26
import awnDefs as defs
35
def get_typefunc(ptype, prefix):
36
return '%s_%s' % (CONFIG_TYPE_MAP[ptype], prefix)
40
def __init__(self, name, ptype):
43
Pref.pref_list[self.name] = self
47
if name in Pref.pref_list:
48
return Pref.pref_list[name]
28
52
class AwnThemeManager:
30
def list(self, model):
54
def __init__(self, glade):
56
self.theme_treeview = self.wTree.get_widget('theme_treeview')
57
self.theme_add = self.wTree.get_widget('theme_add')
58
self.theme_add.connect("clicked", self.add)
59
self.theme_remove = self.wTree.get_widget('theme_remove')
60
self.theme_remove.connect("clicked", self.delete)
61
self.theme_save = self.wTree.get_widget('theme_save')
62
self.theme_save.connect("clicked", self.save)
63
self.theme_apply = self.wTree.get_widget('theme_apply')
64
self.theme_apply.connect("clicked", self.apply_theme)
66
self.AWN_CONFIG = 'theme.awn'
67
self.AWN_THUMB = 'thumb.png'
68
self.AWN_CUSTOM_ICONS = 'custom-icons'
69
self.AWN_CURRENT = os.path.join(defs.HOME_THEME_DIR, 'current.awn')
70
self.CONFIG = awn.Config()
71
self.BUILD_DIR = "/tmp/awn_theme_build"
73
'': [Pref('autohide', bool)],
74
'app': [Pref('active_png', str), Pref('alpha_effect', bool),
75
Pref('arrow_color', str),Pref('hover_bounce_effect', bool),
76
Pref('tasks_have_arrows', bool)],
77
'bar': [Pref('bar_angle', int), Pref('bar_height', int),
78
Pref('border_color', str), Pref('corner_radius', float),
79
Pref('glass_histep_1', str), Pref('glass_histep_2', str),
80
Pref('glass_step_1', str), Pref('glass_step_2', str),
81
Pref('hilight_color', str), Pref('icon_offset', float),
82
Pref('pattern_alpha', float), Pref('pattern_uri', str),
83
Pref('render_pattern', bool), Pref('rounded_corners', bool),
84
Pref('sep_color', str), Pref('show_separator', bool)],
85
'title': [Pref('background', str), Pref('font_face', str),
86
Pref('shadow_color', str), Pref('text_color', str)]
91
self.window = self.wTree.get_widget("main_window")
94
def list_themes(self, model):
34
if(os.path.exists(self.AWN_CURRENT)):
98
if os.path.exists(self.AWN_CURRENT):
35
99
curr = open(self.AWN_CURRENT, "rb")
36
100
lines = curr.readlines()
38
102
curr_name = lines[0].rstrip('\n')
39
103
curr_version = lines[1].rstrip('\n')
42
if(not os.path.exists(self.AWN_THEME_DIR) and not os.path.isdir(self.AWN_THEME_DIR)):
43
os.makedirs(self.AWN_THEME_DIR)
106
if not os.path.exists(defs.HOME_THEME_DIR) and not os.path.isdir(defs.HOME_THEME_DIR):
107
os.makedirs(defs.HOME_THEME_DIR)
45
for dir in self.list_dirs(self.AWN_THEME_DIR):
46
theme_path = os.path.join(os.path.join(self.AWN_THEME_DIR, dir), self.AWN_CONFIG)
47
thumb_path = os.path.join(os.path.join(self.AWN_THEME_DIR, dir), self.AWN_THUMB)
109
for d in self.list_dirs(defs.HOME_THEME_DIR):
110
theme_path = os.path.join(defs.HOME_THEME_DIR, d, self.AWN_CONFIG)
111
thumb_path = os.path.join(defs.HOME_THEME_DIR, d, self.AWN_THUMB)
49
113
if os.path.exists(theme_path):
50
114
cfg = self.read(theme_path)
52
if(os.path.exists(thumb_path)):
116
if os.path.exists(thumb_path):
53
117
self.pixbuf = gtk.gdk.pixbuf_new_from_file (thumb_path)
55
119
self.pixbuf = None
57
if(curr_name == cfg['details']['name'] and curr_version == cfg['details']['version']):
121
setRadio = curr_name == cfg['details']['name'] and curr_version == cfg['details']['version']
62
row = model.append (None, (setRadio, self.pixbuf, "Theme: "+cfg['details']['name']+"\nVersion: "+cfg['details']['version']+"\nAuthor: "+cfg['details']['author']+"\nDate: "+cfg['details']['date']))
123
row = model.append (None, (setRadio, self.pixbuf, "Theme: %s\nVersion: %s\nAuthor: %s\nDate: %s" % (cfg['details']['name'], cfg['details']['version'], cfg['details']['author'], cfg['details']['date'])))
63
125
path = model.get_path(row)[0]
64
self.theme_list[path] = {'row':row, 'name':cfg['details']['name'], 'version':cfg['details']['version'], 'dir':dir}
126
self.theme_list[path] = {
128
'name': cfg['details']['name'],
129
'version': cfg['details']['version'],
66
133
self.currItr = row
71
def apply(self, widget, data=None):
72
if(self.currItr != None):
138
def apply_theme(self, widget, data=None):
139
if self.currItr is not None:
73
140
index = self.model.get_path(self.currItr)[0]
74
141
name = self.theme_list[index]['name']
75
142
version = self.theme_list[index]['version']
76
dir = self.theme_list[index]['dir']
143
directory = self.theme_list[index]['dir']
78
145
curr = open(self.AWN_CURRENT, 'w')
79
146
curr.write(name+"\n")
80
147
curr.write(version+"\n")
83
gconf_insert = self.read(os.path.join(os.path.join(self.AWN_THEME_DIR, dir), self.AWN_CONFIG))
85
self.gconf_client = gconf.client_get_default ()
87
for group in gconf_insert:
150
theme_config = self.read(os.path.join(defs.HOME_THEME_DIR, directory, self.AWN_CONFIG))
152
for group, entries in theme_config.iteritems():
88
153
if group != 'details':
89
154
if group == "root":
90
key_path = self.AWN_GCONF
92
key_path = os.path.join(self.AWN_GCONF, group)
93
style = gconf_insert[group]
95
full_key_path = os.path.join(key_path, key)
96
if(self.gconf_client.get(full_key_path) != None):
97
type = self.gconf_client.get(full_key_path).type
98
if type == gconf.VALUE_STRING:
99
self.gconf_client.set_string(full_key_path, style[key])
100
elif type == gconf.VALUE_INT:
101
self.gconf_client.set_int(full_key_path, int(style[key]))
102
elif type == gconf.VALUE_FLOAT:
103
self.gconf_client.set_float(full_key_path, float(style[key]))
104
elif type == gconf.VALUE_BOOL:
105
self.gconf_client.set_bool(full_key_path, self.str_to_bool(style[key]))
155
group = awn.CONFIG_DEFAULT_GROUP
156
for key, value in entries:
157
pref = Pref.lookup(key)
159
getattr(self.config, get_typefunc(pref.ptype, 'set'))(group, key, value)
107
if self.gconf_client.get_bool(self.AWN_GCONF+"/bar/render_pattern"):
108
self.gconf_client.set_string(self.AWN_GCONF+"/bar/pattern_uri", os.path.join(self.AWN_THEME_DIR, dir, "pattern.png"))
161
if self.CONFIG.get_bool(defs.BAR, defs.RENDER_PATTERN):
162
self.CONFIG.set_string(defs.BAR, defs.PATTERN_URI, os.path.join(defs.HOME_THEME_DIR, directory, "pattern.png"))
110
164
def add(self, widget, data=None):
111
165
dialog = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN,
112
166
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
113
167
dialog.set_default_response(gtk.RESPONSE_OK)
115
filter = gtk.FileFilter()
116
filter.set_name("Compressed Files")
117
filter.add_pattern("*.tar.gz")
118
filter.add_pattern("*.tgz")
119
filter.add_pattern("*.bz2")
120
dialog.add_filter(filter)
169
ffilter = gtk.FileFilter()
170
ffilter.set_name("Compressed Files")
171
ffilter.add_pattern("*.tar.gz")
172
ffilter.add_pattern("*.tgz")
173
ffilter.add_pattern("*.bz2")
174
dialog.add_filter(ffilter)
122
176
response = dialog.run()
123
177
if response == gtk.RESPONSE_OK:
124
file = dialog.get_filename()
125
if not self.extract_file(file):
178
fname = dialog.get_filename()
179
if not self.extract_file(fname):
126
180
invalid = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK, message_format="Invalid Theme Format")
128
182
invalid.destroy()
131
def extract_file(self, file):
132
tar = tarfile.open(file, "r:gz")
185
def extract_file(self, fname):
186
tar = tarfile.open(fname, "r:gz")
133
187
filelist = tar.getmembers()
134
188
theme_found = False
135
189
thumb_found = False
136
for file in filelist:
137
path = os.path.split(file.name)
138
if(path[1] == self.AWN_CONFIG):
191
path = os.path.split(f.name)
192
if path[1] == self.AWN_CONFIG:
139
193
theme_found = True
140
if(path[1] == self.AWN_THUMB):
194
if path[1] == self.AWN_THUMB:
141
195
thumb_found = True
142
if(theme_found and thumb_found):
143
for file in tar.getnames():
144
tar.extract(file, self.AWN_THEME_DIR)
145
#tar.extractall(self.AWN_THEME_DIR) #new in python 2.5
196
if theme_found and thumb_found:
197
if hasattr(tar, 'extractall'):
198
tar.extractall(defs.HOME_THEME_DIR) #new in python 2.5
200
[tar.extract(f, defs.HOME_THEME_DIR) for f in tar.getnames()]
147
202
self.add_row(path[0])
148
203
message = "Theme Successfully Added"
150
205
success = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK, message_format=message)
151
icon_path = os.path.join(self.AWN_THEME_DIR, path[0], self.AWN_CUSTOM_ICONS)
206
icon_path = os.path.join(defs.HOME_THEME_DIR, path[0], self.AWN_CUSTOM_ICONS)
152
207
if os.path.exists(icon_path):
153
message2 = "Custom icons included can be found at:\n "+str(os.path.join(self.AWN_THEME_DIR, path[0], self.AWN_CUSTOM_ICONS))
208
message2 = "Custom icons included can be found at:\n " + os.path.join(defs.HOME_THEME_DIR, path[0], self.AWN_CUSTOM_ICONS)
154
209
success.format_secondary_text(message2)
156
211
success.destroy()
201
255
response = detailsWindow.run()
202
256
if response == 48:
204
gconfKeys[""] = ["appactive_png", "apparrow_color", "apptasks_have_arrows", "auto_hide"]
205
gconfKeys["app"] = ["active_png", "alpha_effect", "arrow_color", "fade_effect", "hover_bounce_effect", "tasks_have_arrows"]
206
gconfKeys["bar"] = ["bar_angle", "bar_height", "border_color", "corner_radius", "glass_histep_1", "glass_histep_2", "glass_step_1",
207
"glass_step_2", "hilight_color", "icon_offset", "pattern_alpha", "pattern_uri", "render_pattern",
208
"rounded_corners", "sep_color", "show_separator"]
209
gconfKeys["title"] = ["background", "bold", "font_face", "font_size", "italic", "shadow_color", "text_color"]
210
gconfKeys["details"] = {"author":entries["author"].get_text(),"name":entries["name"].get_text(),"date":entries["date"].get_text(),"version":entries["version"].get_text()}
211
gconf_client = gconf.client_get_default()
213
foldername = entries["name"].get_text().replace(" ", "_")
214
if(foldername == ''): foldername = "awn_theme"
216
os.makedirs(self.BUILD_DIR+"/"+foldername)
218
self.write(self.BUILD_DIR+'/'+foldername+"/"+self.AWN_CONFIG, gconfKeys)
220
if bool(self.GCONF.get_bool(self.AWN_GCONF+"/bar/render_pattern")):
221
pattern_path = str(self.GCONF.get_string(self.AWN_GCONF+"/bar/pattern_uri"))
257
theme_name = entries['name'].get_text()
258
self.THEME_PREFS['details'] = {
259
'author': entries['author'].get_text(),
261
'date': entries['date'].get_text(),
262
'version': entries['version'].get_text()
266
foldername = 'awn_theme'
268
foldername = theme_name.replace(" ", "_")
270
os.makedirs(os.path.join(self.BUILD_DIR, foldername))
272
self.write(os.path.join(self.BUILD_DIR, foldername, self.AWN_CONFIG))
274
if bool(self.CONFIG.get_bool(defs.BAR, defs.RENDER_PATTERN)):
275
pattern_path = str(self.CONFIG.get_string(defs.BAR, defs.PATTERN_URI))
222
276
if os.path.isfile(pattern_path):
223
shutil.copy(pattern_path,self.BUILD_DIR+'/'+foldername+"/pattern.png")
277
shutil.copy(pattern_path, os.path.join(self.BUILD_DIR, foldername, "pattern.png"))
225
279
img = self.get_img()
226
280
if (img != None):
227
img.save(self.BUILD_DIR+'/'+foldername+"/"+self.AWN_THUMB,"png")
281
img.save(os.path.join(self.BUILD_DIR, foldername, self.AWN_THUMB),"png")
229
283
if custom_icons_found:
230
284
if entries["save_icons"].get_active():
277
330
del self.theme_list[index]
278
331
self.model.remove(self.currItr)
280
def add_row(self, dir):
281
theme_path = os.path.join(os.path.join(self.AWN_THEME_DIR, dir), self.AWN_CONFIG)
282
thumb_path = os.path.join(os.path.join(self.AWN_THEME_DIR, dir), self.AWN_THUMB)
333
def add_row(self, directory):
334
theme_path = os.path.join(defs.HOME_THEME_DIR, directory, self.AWN_CONFIG)
335
thumb_path = os.path.join(defs.HOME_THEME_DIR, directory, self.AWN_THUMB)
284
337
if os.path.exists(theme_path):
285
338
cfg = self.read(theme_path)
287
if(os.path.exists(thumb_path)):
340
if os.path.exists(thumb_path):
288
341
self.pixbuf = gtk.gdk.pixbuf_new_from_file(thumb_path)
290
343
self.pixbuf = None
292
row = self.model.append (None, (False, self.pixbuf, "Theme: "+cfg['details']['name']+"\nVersion: "+cfg['details']['version']+"\nAuthor: "+cfg['details']['author']+"\nDate: "+cfg['details']['date']))
345
row = self.model.append (None, (False, self.pixbuf, "Theme: %s\nVersion: %s\nAuthor: %s\nDate: " % (cfg['details']['name'], cfg['details']['version'], cfg['details']['author'], cfg['details']['date'])))
293
346
path = self.model.get_path(row)[0]
294
self.theme_list[path] = {'row':row, 'name':cfg['details']['name'], 'version':cfg['details']['version'], 'dir':dir}
296
def gconf_get_key(self,full_key):
297
if(self.GCONF.get(full_key) != None):
298
type = self.GCONF.get(full_key).type
299
if type == gconf.VALUE_STRING:
300
key = str(self.GCONF.get_string(full_key))
301
elif type == gconf.VALUE_INT:
302
key = str(self.GCONF.get_int(full_key))
303
elif type == gconf.VALUE_FLOAT:
304
key = str(self.GCONF.get_float(full_key))
305
elif type == gconf.VALUE_BOOL:
306
key = str(self.GCONF.get_bool(full_key))
311
def write(self, path, gconfKeys):
347
self.theme_list[path] = {
349
'name': cfg['details']['name'],
350
'version': cfg['details']['version'],
354
def write(self, path):
312
355
cfg = ConfigParser()
313
for item in gconfKeys:
315
cfg.add_section("root")
317
cfg.add_section(item)
318
for key in gconfKeys[item]:
319
if item == "details":
320
value = gconfKeys[item][key]
322
value = self.gconf_get_key(os.path.join(os.path.join(self.AWN_GCONF, item), key))
327
cfg.set(itm, key, value)
356
for group, contents in self.THEME_PREFS.iteritems():
359
cfg_group = awn.CONFIG_DEFAULT_GROUP
362
cfg.add_section(group)
363
if type(contents) is dict:
364
[cfg.set(group, key, value) for key, value in contents.iteritems()]
366
for pref in contents:
367
# uses the proper retrieval function based on the declared type
368
value = getattr(self.CONFIG, get_typefunc(pref.ptype, 'get'))(cfg_group, pref.name)
369
cfg.set(itm, pref.name, value)
328
370
cfg.write(open(path, 'w'))
330
373
def read(self, path):
331
374
cp = ConfigParser()