~ubuntu-branches/ubuntu/saucy/unity-tweak-tool/saucy-proposed

« back to all changes in this revision

Viewing changes to UnityTweakTool/section/sphagetti/theme.py

  • Committer: Package Import Robot
  • Author(s): Barneedhar Vigneshwar, J Phani Mahesh, Barneedhar Vigneshwar
  • Date: 2013-09-16 19:34:38 UTC
  • Revision ID: package-import@ubuntu.com-20130916193438-dw14bzxkohvxub2y
Tags: 0.0.5
[ J Phani Mahesh ]
* New upstream release (LP: #1226059)
  - New application icon 
  - Show error dialog when schemas are missing instead of crashing
  - Trigger new build of pot files
* UnityTweakTool/section/unity.py
  - Fix Show recently used and more suggestions in dash search (LP: #1166294)
  - Fix Launcher reveal sensitivity scale update issues (LP: #1168863)
* UnityTweakTool/elements/colorchooser.py
  - Fix TypeError in get_rgba() (LP: #1165627)
  - Fix segmentation fault on selecting custom launcher (LP: #1190398)
* UnityTweakTool/elements/option.py
  - Fix "Restore defaults" button (LP: #1186634)
* UnityTweakTool/__init__.py  
  - Fix unity-tweak-tool crashed with dbus.exceptions.DBusException in
  call_blocking() (LP: #1168738)
  - Fix FileNotFoundError (LP: #1225463)
  - Fix dbus.exceptions.DBusException (LP: #1170571)
* data/unity.ui
  - Remove Panel transparency switch (LP: #1168836)
  - Remove Launcher transparency switch (LP: #1168834)

[ Barneedhar Vigneshwar ]
* UnityTweakTool/section/unity.py
  - Fix 'Can't set background blur to static' (LP: #1167343)
  - Fix non-working Launcher only on primary desktop (LP: #1173977)
* UnityTweakTool/section/sphagetti/compiz.py
  - Fix TypeError in color_to_hash() (LP: #1166884)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python3
2
 
# -*- coding: utf-8 -*-
3
 
#
4
 
# Team:
5
 
#   J Phani Mahesh <phanimahesh@gmail.com>
6
 
#   Barneedhar (jokerdino) <barneedhar@ubuntu.com>
7
 
#   Amith KK <amithkumaran@gmail.com>
8
 
#   Georgi Karavasilev <motorslav@gmail.com>
9
 
#   Sam Tran <samvtran@gmail.com>
10
 
#   Sam Hewitt <hewittsamuel@gmail.com>
11
 
#   Angel Araya <al.arayaq@gmail.com>
12
 
#
13
 
# Description:
14
 
#   A One-stop configuration tool for Unity.
15
 
#
16
 
# Legal Stuff:
17
 
#
18
 
# This file is a part of Unity Tweak Tool
19
 
#
20
 
# Unity Tweak Tool is free software; you can redistribute it and/or modify it under
21
 
# the terms of the GNU General Public License as published by the Free Software
22
 
# Foundation; version 3.
23
 
#
24
 
# Unity Tweak Tool is distributed in the hope that it will be useful, but WITHOUT
25
 
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
26
 
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
27
 
# details.
28
 
#
29
 
# You should have received a copy of the GNU General Public License along with
30
 
# this program; if not, see <https://www.gnu.org/licenses/gpl-3.0.txt>
31
 
 
32
 
import os, os.path
33
 
 
34
 
from gi.repository import Gtk, Gio
35
 
 
36
 
from UnityTweakTool.config.ui import ui
37
 
from . import unitytweakconfig
38
 
from . import gsettings
39
 
 
40
 
class Themesettings ():
41
 
    def __init__(self, builder):
42
 
        self.ui=ui(builder)
43
 
        self.gtkthemestore=Gtk.ListStore(str,str)
44
 
        self.windowthemestore=self.gtkthemestore
45
 
        self.ui['tree_gtk_theme'].set_model(self.gtkthemestore)
46
 
        self.ui['tree_window_theme'].set_model(self.windowthemestore)
47
 
 
48
 
        # Get all themes
49
 
        systhdir='/usr/share/themes'
50
 
        systemthemes=[(theme.capitalize(),os.path.join(systhdir,theme)) for theme in os.listdir(systhdir) if os.path.isdir(os.path.join(systhdir,theme))]
51
 
        try:
52
 
            uthdir=os.path.expanduser('~/.themes')
53
 
            userthemes=[(theme.capitalize(),os.path.join(uthdir,theme)) for theme in os.listdir(uthdir) if os.path.isdir(os.path.join(uthdir,theme))]
54
 
        except OSError as e:
55
 
            userthemes=[]
56
 
        allthemes=systemthemes+userthemes
57
 
        allthemes.sort()
58
 
        required=['gtk-2.0','gtk-3.0','metacity-1']
59
 
        self.gtkthemes={}
60
 
        self.windowthemes={}
61
 
        for theme in allthemes:
62
 
            if all([os.path.isdir(os.path.join(theme[1],req)) for req in required]):
63
 
                iter=self.gtkthemestore.append(theme)
64
 
                themename=os.path.split(theme[1])[1]
65
 
                self.gtkthemes[themename]={'iter':iter,'path':theme[1]}
66
 
                self.windowthemes[themename]={'iter':iter,'path':theme[1]}
67
 
 
68
 
        self.iconthemestore=Gtk.ListStore(str,str)
69
 
        self.cursorthemestore=Gtk.ListStore(str,str)
70
 
        self.ui['tree_icon_theme'].set_model(self.iconthemestore)
71
 
        self.ui['tree_cursor_theme'].set_model(self.cursorthemestore)
72
 
 
73
 
        sysithdir='/usr/share/icons'
74
 
        systemiconthemes= [(theme.capitalize(),os.path.join(sysithdir,theme)) for theme in os.listdir(sysithdir) if os.path.isdir(os.path.join(sysithdir,theme))]
75
 
        to_be_hidden=[('Loginicons','/usr/share/icons/LoginIcons'),('Unity-webapps-applications','/usr/share/icons/unity-webapps-applications')]
76
 
        for item in to_be_hidden:
77
 
            try:
78
 
                systemiconthemes.remove(item)
79
 
            except ValueError as e:
80
 
                pass
81
 
        try:
82
 
            uithdir=os.path.expanduser('~/.icons')
83
 
            usericonthemes=[(theme.capitalize(),os.path.join(uithdir,theme)) for theme in os.listdir(uithdir) if os.path.isdir(os.path.join(uithdir,theme))]
84
 
        except OSError as e:
85
 
            usericonthemes=[]
86
 
        allithemes=systemiconthemes+usericonthemes
87
 
        allithemes.sort()
88
 
        self.iconthemes={}
89
 
        self.cursorthemes={}
90
 
        for theme in allithemes:
91
 
            iter=self.iconthemestore.append(theme)
92
 
            themename=os.path.split(theme[1])[1]
93
 
            self.iconthemes[themename]={'iter':iter,'path':theme[1]}
94
 
            if os.path.isdir(os.path.join(theme[1],'cursors')):
95
 
                iter=self.cursorthemestore.append(theme)
96
 
                self.cursorthemes[themename]={'iter':iter,'path':theme[1]}
97
 
 
98
 
        self.matchthemes=True
99
 
 
100
 
#=====================================================================#
101
 
#                                Helpers                              #
102
 
#=====================================================================#
103
 
 
104
 
 
105
 
    def refresh(self):
106
 
 
107
 
        # System theme
108
 
        gtkthemesel=self.ui['tree_gtk_theme'].get_selection()
109
 
        gtktheme=gsettings.gnome('desktop.interface').get_string('gtk-theme')
110
 
 
111
 
        # FIXME: Workaround to fix LP bug: #1098845
112
 
        try:
113
 
            gtkthemesel.select_iter(self.gtkthemes[gtktheme]['iter'])
114
 
 
115
 
        # TODO: This except part should do something more.
116
 
        except KeyError:
117
 
            gtkthemesel.unselect_all()
118
 
 
119
 
        # Window theme
120
 
        windowthemesel=self.ui['tree_window_theme'].get_selection()
121
 
        windowtheme=gsettings.gnome('desktop.wm.preferences').get_string('theme')
122
 
 
123
 
        # FIXME: Workaround to fix LP bug: #1146122
124
 
        try:
125
 
            windowthemesel.select_iter(self.windowthemes[windowtheme]['iter'])
126
 
 
127
 
        # TODO: This except part should do a lot more.
128
 
        except KeyError:
129
 
            windowthemesel.unselect_all()    
130
 
 
131
 
        # Icon theme
132
 
        iconthemesel=self.ui['tree_icon_theme'].get_selection()
133
 
        icontheme=gsettings.gnome('desktop.interface').get_string('icon-theme')
134
 
 
135
 
        # FIXME: Workaround to fix potential bug
136
 
        try:
137
 
            iconthemesel.select_iter(self.iconthemes[icontheme]['iter'])
138
 
 
139
 
        except KeyError:
140
 
            iconthemesel.unselect_all()
141
 
 
142
 
        # Cursor theme
143
 
        cursorthemesel=self.ui['tree_cursor_theme'].get_selection()
144
 
        cursortheme=gsettings.gnome('desktop.interface').get_string('cursor-theme')
145
 
 
146
 
        # FIXME: Workaround to fix LP bug: #1097227
147
 
 
148
 
        try:
149
 
            cursorthemesel.select_iter(self.cursorthemes[cursortheme]['iter'])
150
 
        # TODO: except part should make sure the selection is deselected.
151
 
        except KeyError:
152
 
            cursorthemesel.unselect_all()
153
 
 
154
 
        # Cursor size
155
 
        self.ui['check_cursor_size'].set_active(True if gsettings.interface.get_int('cursor-size') is 48 else False)
156
 
 
157
 
        # ===== Fonts ===== #
158
 
 
159
 
        # Fonts
160
 
        self.ui['font_default'].set_font_name(gsettings.interface.get_string('font-name'))
161
 
        self.ui['font_document'].set_font_name(gsettings.interface.get_string('document-font-name'))
162
 
        self.ui['font_monospace'].set_font_name(gsettings.interface.get_string('monospace-font-name'))
163
 
        self.ui['font_window_title'].set_font_name(gsettings.wm.get_string('titlebar-font'))
164
 
 
165
 
        # Antialiasing
166
 
        if gsettings.antialiasing.get_string('antialiasing') == 'none':
167
 
            self.ui['cbox_antialiasing'].set_active(0)
168
 
        elif gsettings.antialiasing.get_string('antialiasing') == 'grayscale':
169
 
            self.ui['cbox_antialiasing'].set_active(1)
170
 
        elif gsettings.antialiasing.get_string('antialiasing') == 'rgba':
171
 
            self.ui['cbox_antialiasing'].set_active(2)
172
 
 
173
 
        # Hinting
174
 
        if gsettings.antialiasing.get_string('hinting') == 'none':
175
 
            self.ui['cbox_hinting'].set_active(0)
176
 
        elif gsettings.antialiasing.get_string('hinting') == 'slight':
177
 
            self.ui['cbox_hinting'].set_active(1)
178
 
        elif gsettings.antialiasing.get_string('hinting') == 'medium':
179
 
            self.ui['cbox_hinting'].set_active(2)
180
 
        elif gsettings.antialiasing.get_string('hinting') == 'full':
181
 
            self.ui['cbox_hinting'].set_active(3)
182
 
 
183
 
        # Scaling
184
 
        self.ui['spin_textscaling'].set_value(gsettings.interface.get_double('text-scaling-factor'))
185
 
        self.refresh_window_controls()
186
 
        self.refresh_window_controls_combobox()
187
 
        self.refresh_window_menu_check()
188
 
 
189
 
 
190
 
    # ===== Window Controls ===== #
191
 
 
192
 
    # Button layout
193
 
    def refresh_window_controls(self):
194
 
 
195
 
        combobox = ['cbox_custom_layout']
196
 
        dependants = ['radio_left',
197
 
                    'radio_right']
198
 
        if gsettings.wm.get_string('button-layout') == 'close,minimize,maximize:':
199
 
            self.ui['radio_left'].set_active(True)
200
 
            self.ui['radio_default_layout'].set_active(True)
201
 
            self.ui['check_show_menu'].set_active(False)
202
 
        elif gsettings.wm.get_string('button-layout') == ':minimize,maximize,close':
203
 
            self.ui['radio_right'].set_active(True)
204
 
            self.ui['check_show_menu'].set_active(False)
205
 
        else:
206
 
            self.ui['radio_custom_layout'].set_active(True)
207
 
            self.ui.unsensitize(dependants)
208
 
            self.ui.sensitize(combobox)
209
 
        del dependants
210
 
        del combobox
211
 
 
212
 
    # Custom Combobox
213
 
    def refresh_window_controls_combobox(self):
214
 
 
215
 
        if gsettings.wm.get_string('button-layout') == 'close:':
216
 
            self.ui['cbox_custom_layout'].set_active(1)
217
 
        elif gsettings.wm.get_string('button-layout') == 'close,maximize:':
218
 
            self.ui['cbox_custom_layout'].set_active(2)
219
 
        elif gsettings.wm.get_string('button-layout') == 'close,minimize:':
220
 
            self.ui['cbox_custom_layout'].set_active(3)
221
 
        elif gsettings.wm.get_string('button-layout') == 'close:maximize':
222
 
            self.ui['cbox_custom_layout'].set_active(4)
223
 
        else:
224
 
            self.ui['cbox_custom_layout'].set_active(0)
225
 
 
226
 
    # Show menu
227
 
    def refresh_window_menu_check(self):
228
 
        if 'menu' in gsettings.wm.get_string('button-layout'):
229
 
            self.ui['check_show_menu'].set_active(True)
230
 
        else:
231
 
            self.ui['check_show_menu'].set_active(False)
232
 
 
233
 
# TODO : Find a clever way or set each one manually.
234
 
# Do it the dumb way now. BIIIG refactoring needed later.
235
 
 
236
 
 
237
 
#-----BEGIN: Theme settings------
238
 
 
239
 
# These check for nonetype and return since for some bizzare reason Gtk.quit destroys
240
 
# the selection object and then calls these callbacks. This is a temporary fix to LP:1096964
241
 
 
242
 
    # System Theme
243
 
    def on_treeselection_gtk_theme_changed(self,udata=None):
244
 
        gtktreesel = self.ui['tree_gtk_theme'].get_selection()
245
 
        if gtktreesel is None:
246
 
            return
247
 
        gtkthemestore,iter = gtktreesel.get_selected()
248
 
        if self.matchthemes:
249
 
            self.ui['treeselection_window_theme'].select_iter(iter)
250
 
        themepath=gtkthemestore.get_value(iter,1)
251
 
        theme=os.path.split(themepath)[1]
252
 
        gsettings.interface.set_string('gtk-theme',theme)
253
 
 
254
 
    def on_treeselection_window_theme_changed(self,udata=None):
255
 
        windowtreesel = self.ui['tree_window_theme'].get_selection()
256
 
        if windowtreesel is None:
257
 
            return
258
 
        windowthemestore,iter = windowtreesel.get_selected()
259
 
        if self.matchthemes:
260
 
            self.ui['treeselection_gtk_theme'].select_iter(iter)
261
 
        themepath=windowthemestore.get_value(iter,1)
262
 
        theme=os.path.split(themepath)[1]
263
 
        gsettings.wm.set_string('theme',theme)
264
 
 
265
 
    # Icon theme
266
 
    def on_tree_icon_theme_cursor_changed(self,udata=None):
267
 
        icontreesel = self.ui['tree_icon_theme'].get_selection()
268
 
        if icontreesel is None:
269
 
            return
270
 
        iconthemestore,iter = icontreesel.get_selected()
271
 
        themepath=iconthemestore.get_value(iter,1)
272
 
        theme=os.path.split(themepath)[1]
273
 
        gsettings.interface.set_string('icon-theme',theme)
274
 
 
275
 
    def on_check_show_incomplete_toggled(self,udata=None):
276
 
    # TODO
277
 
        print('To do')
278
 
 
279
 
    def on_b_theme_system_reset_clicked(self, widget):
280
 
        gsettings.interface.reset('gtk-theme')
281
 
        gsettings.wm.reset('theme')
282
 
        self.refresh()
283
 
 
284
 
#----- End: Theme settings------
285
 
 
286
 
#----- Begin: Icon settings--------
287
 
 
288
 
    def on_b_theme_icon_reset_clicked(self, widget):
289
 
        gsettings.interface.reset('icon-theme')
290
 
        self.refresh()
291
 
 
292
 
#----- End: Icon settings------
293
 
 
294
 
#----- Begin: Cursor settings--------
295
 
 
296
 
    # Cursor
297
 
    def on_tree_cursor_theme_cursor_changed(self,udata=None):
298
 
        cursortreesel= self.ui['tree_cursor_theme'].get_selection()
299
 
        if cursortreesel is None:
300
 
            return
301
 
        cursorthemestore,iter = cursortreesel.get_selected()
302
 
        themepath=cursorthemestore.get_value(iter,1)
303
 
        theme=os.path.split(themepath)[1]
304
 
        gsettings.interface.set_string('cursor-theme',theme)
305
 
 
306
 
    # Cursor Size
307
 
    def on_check_cursor_size_toggled(self, widget, udata = None):
308
 
        if self.ui['check_cursor_size'].get_active() == True :
309
 
            gsettings.interface.set_int('cursor-size', 48)
310
 
        else:
311
 
            gsettings.interface.set_int('cursor-size', 24)
312
 
 
313
 
    def on_b_theme_cursor_reset_clicked(self, widget):
314
 
        gsettings.interface.reset('cursor-theme')
315
 
        gsettings.interface.reset('cursor-size')
316
 
        self.refresh()
317
 
 
318
 
#----- End: Cursor settings------
319
 
#----- Begin: Window control settings--------
320
 
 
321
 
    def on_radio_default_layout_toggled(self, button, udata = None):
322
 
        combobox = ['cbox_custom_layout',]
323
 
        dependants = ['radio_left',
324
 
                    'radio_right',
325
 
                    'l_alignment']
326
 
 
327
 
        if self.ui['radio_default_layout'].get_active() == True:
328
 
            gsettings.wm.set_string('button-layout', 'close,minimize,maximize:')
329
 
            self.ui.sensitize(dependants)
330
 
            self.ui.unsensitize(combobox)
331
 
            self.refresh_window_menu_check()
332
 
        else:
333
 
            self.ui.unsensitize(dependants)
334
 
            self.ui.sensitize(combobox)
335
 
            self.refresh_window_menu_check()
336
 
 
337
 
    def on_radio_left_toggled(self, button, udata = None):
338
 
 
339
 
        if self.ui['radio_left'].get_active() == True:
340
 
            gsettings.wm.set_string('button-layout', 'close,minimize,maximize:')
341
 
            self.refresh_window_menu_check()
342
 
        else:
343
 
            gsettings.wm.set_string('button-layout', ':minimize,maximize,close')
344
 
            self.refresh_window_menu_check()
345
 
 
346
 
    def on_radio_right_toggled(self, button, udata = None):
347
 
 
348
 
        if self.ui['radio_right'].get_active() == True:
349
 
            gsettings.wm.set_string('button-layout', ':minimize,maximize,close')
350
 
            self.refresh_window_menu_check()
351
 
        else:
352
 
            gsettings.wm.set_string('button-layout', 'close,minimize,maximize:')
353
 
            self.refresh_window_menu_check()
354
 
 
355
 
    def on_radio_custom_layout_toggled(self, button, udata = None):
356
 
        combobox = ['cbox_custom_layout']
357
 
        dependants = ['radio_left',
358
 
                    'radio_right',
359
 
                    'l_alignment']
360
 
 
361
 
        if self.ui['radio_custom_layout'].get_active() == True:
362
 
            self.ui.sensitize(combobox)
363
 
            self.ui.unsensitize(dependants)
364
 
            self.refresh_window_menu_check()
365
 
        else:
366
 
            self.ui.unsensitize(combobox)
367
 
            self.ui.sensitize(dependants)
368
 
            self.refresh_window_menu_check()
369
 
 
370
 
    def on_cbox_custom_layout_changed(self, widget, udata = None):
371
 
 
372
 
        checkbox = ['check_show_menu']
373
 
        if self.ui['cbox_custom_layout'].get_active() == 0:
374
 
            pass
375
 
        elif self.ui['cbox_custom_layout'].get_active() == 1:
376
 
            gsettings.wm.set_string('button-layout', 'close:')
377
 
            self.ui.sensitize(checkbox)
378
 
            self.refresh_window_menu_check()
379
 
        elif self.ui['cbox_custom_layout'].get_active() == 2:
380
 
            gsettings.wm.set_string('button-layout', 'close,maximize:')
381
 
            self.ui.sensitize(checkbox)
382
 
            self.refresh_window_menu_check()
383
 
        elif self.ui['cbox_custom_layout'].get_active() == 3:
384
 
            gsettings.wm.set_string('button-layout', 'close,minimize:')
385
 
            self.ui.sensitize(checkbox)
386
 
            self.refresh_window_menu_check()
387
 
        elif self.ui['cbox_custom_layout'].get_active() == 4:
388
 
            gsettings.wm.set_string('button-layout', 'close:maximize')
389
 
            self.ui.unsensitize(checkbox)
390
 
            self.refresh_window_menu_check()
391
 
        else:
392
 
            gsettings.wm.set_string('button-layout', 'close,minimize,maximize:')
393
 
            self.ui.unsensitize(checkbox)
394
 
            self.refresh_window_menu_check()
395
 
 
396
 
    def on_check_show_menu_toggled(self, button, udata = None):
397
 
 
398
 
        if gsettings.wm.get_string('button-layout').endswith(':'):
399
 
            value = gsettings.wm.get_string('button-layout') + 'menu'
400
 
            gsettings.wm.set_string('button-layout', value)
401
 
            del value
402
 
        elif gsettings.wm.get_string('button-layout').startswith(':'):
403
 
            value = 'menu' + gsettings.wm.get_string('button-layout')
404
 
            gsettings.wm.set_string('button-layout', value)
405
 
            del value
406
 
        else:
407
 
            if 'menu' in gsettings.wm.get_string('button-layout'):
408
 
                value = str(gsettings.wm.get_string('button-layout')).replace('menu', '')
409
 
                gsettings.wm.set_string('button-layout', value)
410
 
            else:
411
 
                return
412
 
 
413
 
    def on_b_theme_window_controls_reset_clicked(self, widget):
414
 
        gsettings.wm.set_string('button-layout', 'close,minimize,maximize:')
415
 
        self.refresh_window_controls()
416
 
        self.refresh_window_controls_combobox()
417
 
        self.refresh_window_menu_check()
418
 
 
419
 
#----- End: Window control settings--------