~awn-testing/awn/awn-core-testing

« back to all changes in this revision

Viewing changes to awn-manager/awnTheme.py

* Merge with the desktop-agnostic branch (Let's malept update the whiteboard ;))
* Debian dir update
 - configure flag : --with-desktop=gnome --with-gconf 
 - add vala 0.1.6~svn as build-depends (need futur upload in PPA)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import shutil
20
20
import tarfile
21
21
import os
22
 
import gconf
23
 
import gconf
24
 
import gnomedesktop
25
22
import gtk
26
23
import gobject
27
24
 
 
25
import awn
 
26
import awnDefs as defs
 
27
 
 
28
CONFIG_TYPE_MAP = {
 
29
    bool: 'bool',
 
30
    float: 'float',
 
31
    int: 'int',
 
32
    str: 'string'
 
33
    }
 
34
 
 
35
def get_typefunc(ptype, prefix):
 
36
    return '%s_%s' % (CONFIG_TYPE_MAP[ptype], prefix)
 
37
 
 
38
class Pref:
 
39
    pref_list = {}
 
40
    def __init__(self, name, ptype):
 
41
        self.name = name
 
42
        self.ptype = ptype
 
43
        Pref.pref_list[self.name] = self
 
44
 
 
45
    @staticmethod
 
46
    def lookup(name):
 
47
        if name in Pref.pref_list:
 
48
            return Pref.pref_list[name]
 
49
        else:
 
50
            return None
 
51
 
28
52
class AwnThemeManager:
29
53
 
30
 
    def list(self, model):
 
54
    def __init__(self, glade):
 
55
        self.wTree = 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)
 
65
 
 
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"
 
72
        self.THEME_PREFS = {
 
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)]
 
87
            }
 
88
        self.theme_list = {}
 
89
        self.currItr = None
 
90
        self.model = None
 
91
        self.window = self.wTree.get_widget("main_window")
 
92
        self.make_model()
 
93
 
 
94
    def list_themes(self, model):
31
95
        self.model = model
32
96
        curr_name = ''
33
97
        curr_version = ''
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()
37
 
            if(len(lines) == 2):
 
101
            if len(lines) == 2:
38
102
                curr_name = lines[0].rstrip('\n')
39
103
                curr_version = lines[1].rstrip('\n')
40
104
                curr.close()
41
105
 
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)
44
108
 
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)
48
112
 
49
113
            if os.path.exists(theme_path):
50
114
                cfg = self.read(theme_path)
51
 
                if(cfg):
52
 
                    if(os.path.exists(thumb_path)):
 
115
                if cfg:
 
116
                    if os.path.exists(thumb_path):
53
117
                        self.pixbuf = gtk.gdk.pixbuf_new_from_file (thumb_path)
54
118
                    else:
55
119
                        self.pixbuf = None
56
120
 
57
 
                    if(curr_name == cfg['details']['name'] and curr_version == cfg['details']['version']):
58
 
                        setRadio = True
59
 
                    else:
60
 
                        setRadio = False
 
121
                    setRadio = curr_name == cfg['details']['name'] and curr_version == cfg['details']['version']
61
122
 
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'])))
 
124
                    
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] = {
 
127
                        'row': row,
 
128
                        'name': cfg['details']['name'],
 
129
                        'version': cfg['details']['version'],
 
130
                        'dir': d
 
131
                        }
65
132
                    if setRadio:
66
133
                        self.currItr = row
67
134
                    else:
68
135
                        self.currItr = ''
69
136
 
70
137
 
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']
77
144
 
78
145
            curr = open(self.AWN_CURRENT, 'w')
79
146
            curr.write(name+"\n")
80
147
            curr.write(version+"\n")
81
148
            curr.close()
82
149
 
83
 
            gconf_insert = self.read(os.path.join(os.path.join(self.AWN_THEME_DIR, dir), self.AWN_CONFIG))
84
 
 
85
 
            self.gconf_client = gconf.client_get_default ()
86
 
 
87
 
            for group in gconf_insert:
 
150
            theme_config = self.read(os.path.join(defs.HOME_THEME_DIR, directory, self.AWN_CONFIG))
 
151
 
 
152
            for group, entries in theme_config.iteritems():
88
153
                if group != 'details':
89
154
                    if group == "root":
90
 
                        key_path = self.AWN_GCONF
91
 
                    else:
92
 
                        key_path = os.path.join(self.AWN_GCONF, group)
93
 
                    style = gconf_insert[group]
94
 
                    for key in style:
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)
 
158
                        if pref is not None:
 
159
                            getattr(self.config, get_typefunc(pref.ptype, 'set'))(group, key, value)
106
160
 
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"))
109
163
 
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)
114
168
 
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)
121
175
 
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")
127
181
                invalid.run()
128
182
                invalid.destroy()
129
183
        dialog.destroy()
130
184
 
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):
 
190
        for f in filelist:
 
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
 
199
            else:
 
200
                [tar.extract(f, defs.HOME_THEME_DIR) for f in tar.getnames()]
146
201
            tar.close()
147
202
            self.add_row(path[0])
148
203
            message = "Theme Successfully Added"
149
204
            message2 = ""
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)
155
210
            success.run()
156
211
            success.destroy()
187
242
        hbox.pack_start(entries["version"], expand=False, fill=False)
188
243
 
189
244
        custom_icons_found = False
190
 
        icon_path = os.path.join(self.AWN_CONFIG_DIR, self.AWN_CUSTOM_ICONS)
191
 
        if os.path.exists(icon_path):
192
 
            if len(os.listdir(icon_path)) > 0:
 
245
        if os.path.exists(defs.HOME_CUSTOM_ICONS_DIR):
 
246
            if len(os.listdir(defs.HOME_CUSTOM_ICONS_DIR)) > 0:
193
247
                hbox = gtk.HBox(homogeneous=False, spacing=5)
194
248
                detailsWindow.vbox.pack_start(hbox)
195
249
                entries["save_icons"] = gtk.CheckButton("Save Custom Icons")
200
254
 
201
255
        response = detailsWindow.run()
202
256
        if response == 48:
203
 
            gconfKeys = {}
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()
212
 
 
213
 
            foldername = entries["name"].get_text().replace(" ", "_")
214
 
            if(foldername == ''): foldername = "awn_theme"
215
 
 
216
 
            os.makedirs(self.BUILD_DIR+"/"+foldername)
217
 
 
218
 
            self.write(self.BUILD_DIR+'/'+foldername+"/"+self.AWN_CONFIG, gconfKeys)
219
 
 
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(),
 
260
                'name': theme_name,
 
261
                'date': entries['date'].get_text(),
 
262
                'version': entries['version'].get_text()
 
263
                }
 
264
 
 
265
            if theme_name == '':
 
266
                foldername = 'awn_theme'
 
267
            else:
 
268
                foldername = theme_name.replace(" ", "_")
 
269
 
 
270
            os.makedirs(os.path.join(self.BUILD_DIR, foldername))
 
271
 
 
272
            self.write(os.path.join(self.BUILD_DIR, foldername, self.AWN_CONFIG))
 
273
 
 
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"))
224
278
 
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")
228
282
 
229
283
            if custom_icons_found:
230
284
                if entries["save_icons"].get_active():
236
290
            tar.close()
237
291
 
238
292
            desktop = os.path.expanduser("~/Desktop")
239
 
            shutil.move(self.BUILD_DIR+'/'+foldername+".tgz", desktop)
 
293
            shutil.move(os.path.join(self.BUILD_DIR, foldername + ".tgz"), desktop)
240
294
 
241
295
            self.clean_tmp(self.BUILD_DIR)
242
296
 
246
300
 
247
301
    def save_custom_icons(self, foldername):
248
302
        build_icon_path = os.path.join(self.BUILD_DIR, foldername, self.AWN_CUSTOM_ICONS)
249
 
        icon_path = os.path.join(self.AWN_CONFIG_DIR, self.AWN_CUSTOM_ICONS)
250
 
        shutil.copytree(icon_path, build_icon_path)
 
303
        shutil.copytree(defs.HOME_CUSTOM_ICONS_DIR, build_icon_path)
251
304
 
252
305
    def delete(self, widget, data=None):
253
 
        if(self.currItr != None):
 
306
        if self.currItr is not None:
254
307
            index = self.model.get_path(self.currItr)[0]
255
308
            name = self.theme_list[index]['name']
256
309
            version = self.theme_list[index]['version']
257
 
            dir = self.theme_list[index]['dir']
258
 
 
259
 
            self.clean_tmp(os.path.join(self.AWN_THEME_DIR, dir))
260
 
 
261
 
            #os.remove(self.AWN_THEME_DIR+'/'+dir+"/"+self.AWN_THUMB)
262
 
            #os.remove(self.AWN_THEME_DIR+'/'+dir+"/"+self.AWN_CONFIG)
263
 
            #os.rmdir(self.AWN_THEME_DIR+'/'+dir)
264
 
 
265
 
            if(os.path.exists(self.AWN_CURRENT)):
 
310
            directory = self.theme_list[index]['dir']
 
311
 
 
312
            self.clean_tmp(os.path.join(defs.HOME_THEME_DIR, directory))
 
313
 
 
314
            #os.remove(os.path.join(defs.HOME_THEME_DIR, dir, self.AWN_THUMB))
 
315
            #os.remove(os.path.join(defs.HOME_THEME_DIR, dir, self.AWN_CONFIG))
 
316
            #os.rmdir(os.path.join(defs.HOME_THEME_DIR, dir))
 
317
 
 
318
            if os.path.exists(self.AWN_CURRENT):
266
319
                curr = open(self.AWN_CURRENT, "rb")
267
320
                lines = curr.readlines()
268
 
                if(len(lines) == 2):
 
321
                if len(lines) == 2:
269
322
                    curr_name = lines[0].rstrip('\n')
270
323
                    curr_version = lines[1].rstrip('\n')
271
324
                    curr.close()
277
330
            del self.theme_list[index]
278
331
            self.model.remove(self.currItr)
279
332
 
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)
283
336
 
284
337
        if os.path.exists(theme_path):
285
338
            cfg = self.read(theme_path)
286
339
 
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)
289
342
            else:
290
343
                self.pixbuf = None
291
344
 
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}
295
 
 
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))
307
 
            else:
308
 
                key = ''
309
 
            return key
310
 
 
311
 
    def write(self, path, gconfKeys):
 
347
            self.theme_list[path] = {
 
348
                'row': row,
 
349
                'name': cfg['details']['name'],
 
350
                'version': cfg['details']['version'],
 
351
                'dir':directory
 
352
                }
 
353
 
 
354
    def write(self, path):
312
355
        cfg = ConfigParser()
313
 
        for item in gconfKeys:
314
 
            if item == "":
315
 
                cfg.add_section("root")
316
 
            else:
317
 
                cfg.add_section(item)
318
 
            for key in gconfKeys[item]:
319
 
                if item == "details":
320
 
                    value = gconfKeys[item][key]
321
 
                else:
322
 
                    value = self.gconf_get_key(os.path.join(os.path.join(self.AWN_GCONF, item), key))
323
 
                if item == "":
324
 
                    itm = "root"
325
 
                else:
326
 
                    itm = item
327
 
                cfg.set(itm, key, value)
 
356
        for group, contents in self.THEME_PREFS.iteritems():
 
357
            if group == '':
 
358
                group = 'root'
 
359
                cfg_group = awn.CONFIG_DEFAULT_GROUP
 
360
            else:
 
361
                cfg_group = group
 
362
            cfg.add_section(group)
 
363
            if type(contents) is dict:
 
364
                [cfg.set(group, key, value) for key, value in contents.iteritems()]
 
365
            else:
 
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'))
 
371
        cfg.close()
329
372
 
330
373
    def read(self, path):
331
374
        cp = ConfigParser()
350
393
        os.rmdir(dirPath)
351
394
 
352
395
    def list_dirs(self, path):
353
 
        dirs = []
354
 
        for dir in os.listdir(path):
355
 
            dirs.append(dir)
356
 
        return dirs
 
396
        return list(os.listdir(path))
357
397
 
358
398
    def get_img(self):
359
399
        img_height = 75
360
400
        cmd = 'xwininfo -int -name  "awn_elements"'
361
401
        x = gtk.gdk.screen_width()/2
362
402
        y = gtk.gdk.screen_height()-img_height
363
 
        for file in os.popen(cmd).readlines():
364
 
            if file.find("Absolute upper-left X:  ") > 0:
365
 
                x = int(file.split("  ")[2])-20
366
 
            elif file.find("Absolute upper-left Y:  ") > 0:
367
 
                y = int(file.split("  ")[2])+int(img_height/2)
 
403
        for line in os.popen(cmd).readlines():
 
404
            if line.find("Absolute upper-left X:  ") > 0:
 
405
                x = int(line.split("  ")[2])-20
 
406
            elif line.find("Absolute upper-left Y:  ") > 0:
 
407
                y = int(line.split("  ")[2])+int(img_height/2)
368
408
        w = gtk.gdk.get_default_root_window()
369
409
        sz = w.get_size()
370
410
        pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,150,75)
374
414
    def on_toggle(self, widget, event, data=None):
375
415
        widget.foreach(self.update_radio, event)
376
416
 
377
 
    def update_radio(self, model, path, iter, data):
378
 
        if(path[0] == int(data)):
379
 
            model.set_value(iter, 0, 1)
380
 
            self.currItr = iter
 
417
    def update_radio(self, model, path, iterator, data):
 
418
        if path[0] == int(data):
 
419
            model.set_value(iterator, 0, 1)
 
420
            self.currItr = iterator
381
421
        else:
382
 
            model.set_value(iter, 0, 0)
 
422
            model.set_value(iterator, 0, 0)
383
423
 
384
424
    def drag_data_received_data(self, treeview, context, x, y, selection, info, etime):
385
425
        data = selection.data
388
428
        if tarfile.is_tarfile(data):
389
429
            self.extract_file(data)
390
430
 
391
 
    def str_to_bool(self, str):
392
 
        if(str.lower() == "true"):
393
 
            return True
394
 
        else:
395
 
            return False
 
431
    def str_to_bool(self, string):
 
432
        return string.lower() == "true"
396
433
 
397
434
    def make_model(self):
398
435
        self.theme_model = gtk.TreeStore (gobject.TYPE_BOOLEAN, gtk.gdk.Pixbuf, str)
415
452
        self.theme_treeview.insert_column_with_attributes (-1, 'Preview', gtk.CellRendererPixbuf (), pixbuf=COL_PREVIEW)
416
453
        self.theme_treeview.insert_column_with_attributes (-1, 'Author', gtk.CellRendererText (), text=COL_AUTHOR)
417
454
 
418
 
        self.list(self.theme_model)
419
 
 
420
 
    def __init__(self, glade, config_dir):
421
 
        self.AWN_CONFIG_DIR = config_dir
422
 
        self.wTree = glade
423
 
        self.theme_treeview = self.wTree.get_widget('theme_treeview')
424
 
        self.theme_add = self.wTree.get_widget('theme_add')
425
 
        self.theme_add.connect("clicked", self.add)
426
 
        self.theme_remove = self.wTree.get_widget('theme_remove')
427
 
        self.theme_remove.connect("clicked", self.delete)
428
 
        self.theme_save = self.wTree.get_widget('theme_save')
429
 
        self.theme_save.connect("clicked", self.save)
430
 
        self.theme_apply = self.wTree.get_widget('theme_apply')
431
 
        self.theme_apply.connect("clicked", self.apply)
432
 
 
433
 
        self.AWN = 'avant-window-navigator'
434
 
        self.AWN_GCONF = '/apps/'+self.AWN
435
 
        self.AWN_THEME_DIR = os.path.join(self.AWN_CONFIG_DIR, "themes/")
436
 
        self.AWN_CONFIG = 'theme.awn'
437
 
        self.AWN_THUMB = 'thumb.png'
438
 
        self.AWN_CUSTOM_ICONS = 'custom-icons'
439
 
        self.AWN_CURRENT = os.path.join(self.AWN_THEME_DIR, 'current.awn')
440
 
        self.GCONF = gconf.client_get_default()
441
 
        self.BUILD_DIR = "/tmp/awn_theme_build"
442
 
        self.theme_list = {}
443
 
        self.currItr = None
444
 
        self.model = None
445
 
        self.window = self.wTree.get_widget("main_window")
446
 
        self.make_model()
 
455
        self.list_themes(self.theme_model)