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

« back to all changes in this revision

Viewing changes to UnityTweakTool/section/spaghetti/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
 
 
186
    # ===== Window Controls ===== #
 
187
 
 
188
    # Button layout
 
189
    def refresh_window_controls(self):
 
190
 
 
191
        dependants = ['radio_left',
 
192
                    'radio_right']
 
193
        if gsettings.wm.get_string('button-layout') == 'close,minimize,maximize:':
 
194
            self.ui['radio_left'].set_active(True)
 
195
            self.ui['check_show_menu'].set_active(False)
 
196
        elif gsettings.wm.get_string('button-layout') == ':minimize,maximize,close':
 
197
            self.ui['radio_right'].set_active(True)
 
198
            self.ui['check_show_menu'].set_active(False)
 
199
        else:
 
200
            return
 
201
        del dependants
 
202
 
 
203
    # Show menu
 
204
    def refresh_window_menu_check(self):
 
205
        if 'menu' in gsettings.wm.get_string('button-layout'):
 
206
            self.ui['check_show_menu'].set_active(True)
 
207
        else:
 
208
            self.ui['check_show_menu'].set_active(False)
 
209
 
 
210
# TODO : Find a clever way or set each one manually.
 
211
# Do it the dumb way now. BIIIG refactoring needed later.
 
212
 
 
213
 
 
214
#-----BEGIN: Theme settings------
 
215
 
 
216
# These check for nonetype and return since for some bizzare reason Gtk.quit destroys
 
217
# the selection object and then calls these callbacks. This is a temporary fix to LP:1096964
 
218
 
 
219
    # System Theme
 
220
    def on_treeselection_gtk_theme_changed(self,udata=None):
 
221
        gtktreesel = self.ui['tree_gtk_theme'].get_selection()
 
222
        if gtktreesel is None:
 
223
            return
 
224
        gtkthemestore,iter = gtktreesel.get_selected()
 
225
        if self.matchthemes:
 
226
            self.ui['treeselection_window_theme'].select_iter(iter)
 
227
        themepath=gtkthemestore.get_value(iter,1)
 
228
        theme=os.path.split(themepath)[1]
 
229
        gsettings.interface.set_string('gtk-theme',theme)
 
230
 
 
231
    def on_treeselection_window_theme_changed(self,udata=None):
 
232
        windowtreesel = self.ui['tree_window_theme'].get_selection()
 
233
        if windowtreesel is None:
 
234
            return
 
235
        windowthemestore,iter = windowtreesel.get_selected()
 
236
        if self.matchthemes:
 
237
            self.ui['treeselection_gtk_theme'].select_iter(iter)
 
238
        themepath=windowthemestore.get_value(iter,1)
 
239
        theme=os.path.split(themepath)[1]
 
240
        gsettings.wm.set_string('theme',theme)
 
241
 
 
242
    # Icon theme
 
243
    def on_tree_icon_theme_cursor_changed(self,udata=None):
 
244
        icontreesel = self.ui['tree_icon_theme'].get_selection()
 
245
        if icontreesel is None:
 
246
            return
 
247
        iconthemestore,iter = icontreesel.get_selected()
 
248
        themepath=iconthemestore.get_value(iter,1)
 
249
        theme=os.path.split(themepath)[1]
 
250
        gsettings.interface.set_string('icon-theme',theme)
 
251
 
 
252
    def on_check_show_incomplete_toggled(self,udata=None):
 
253
    # TODO
 
254
        print('To do')
 
255
 
 
256
    def on_b_theme_system_reset_clicked(self, widget):
 
257
        gsettings.interface.reset('gtk-theme')
 
258
        gsettings.wm.reset('theme')
 
259
        self.refresh()
 
260
 
 
261
#----- End: Theme settings------
 
262
 
 
263
#----- Begin: Icon settings--------
 
264
 
 
265
    def on_b_theme_icon_reset_clicked(self, widget):
 
266
        gsettings.interface.reset('icon-theme')
 
267
        self.refresh()
 
268
 
 
269
#----- End: Icon settings------
 
270
 
 
271
#----- Begin: Cursor settings--------
 
272
 
 
273
    # Cursor
 
274
    def on_tree_cursor_theme_cursor_changed(self,udata=None):
 
275
        cursortreesel= self.ui['tree_cursor_theme'].get_selection()
 
276
        if cursortreesel is None:
 
277
            return
 
278
        cursorthemestore,iter = cursortreesel.get_selected()
 
279
        themepath=cursorthemestore.get_value(iter,1)
 
280
        theme=os.path.split(themepath)[1]
 
281
        gsettings.interface.set_string('cursor-theme',theme)
 
282
 
 
283
    # Cursor Size
 
284
    def on_check_cursor_size_toggled(self, widget, udata = None):
 
285
        if self.ui['check_cursor_size'].get_active() == True :
 
286
            gsettings.interface.set_int('cursor-size', 48)
 
287
        else:
 
288
            gsettings.interface.set_int('cursor-size', 24)
 
289
 
 
290
    def on_b_theme_cursor_reset_clicked(self, widget):
 
291
        gsettings.interface.reset('cursor-theme')
 
292
        gsettings.interface.reset('cursor-size')
 
293
        self.refresh()
 
294
 
 
295
#----- End: Cursor settings------
 
296
#----- Begin: Window control settings--------
 
297
 
 
298
    def on_radio_left_toggled(self, button, udata = None):
 
299
 
 
300
        if self.ui['radio_left'].get_active() == True:
 
301
            if 'menu' in gsettings.wm.get_string('button-layout'):
 
302
                value = 'close,minimize,maximize:' + 'menu'
 
303
                gsettings.wm.set_string('button-layout', value)
 
304
                self.refresh_window_menu_check()
 
305
                del value
 
306
            else:
 
307
                value = 'close,minimize,maximize:'
 
308
                gsettings.wm.set_string('button-layout', value)
 
309
                self.refresh_window_menu_check()
 
310
                del value
 
311
        else:
 
312
            if 'menu' in gsettings.wm.get_string('button-layout'):
 
313
                value = 'menu' + ':minimize,maximize,close'
 
314
                gsettings.wm.set_string('button-layout', value)
 
315
                self.refresh_window_menu_check()
 
316
                del value
 
317
            else:
 
318
                value = ':minimize,maximize,close'
 
319
                gsettings.wm.set_string('button-layout', value)
 
320
                self.refresh_window_menu_check()
 
321
                del value
 
322
 
 
323
    def on_radio_right_toggled(self, button, udata = None):
 
324
 
 
325
        if self.ui['radio_right'].get_active() == True:
 
326
            if 'menu' in gsettings.wm.get_string('button-layout'):
 
327
                value = 'menu' + ':minimize,maximize,close'
 
328
                gsettings.wm.set_string('button-layout', value)
 
329
                self.refresh_window_menu_check()
 
330
                del value
 
331
 
 
332
            else:
 
333
                value = ':minimize,maximize,close'
 
334
                gsettings.wm.set_string('button-layout', value)
 
335
                self.refresh_window_menu_check()
 
336
                del value
 
337
        else:
 
338
            if 'menu' in gsettings.wm.get_string('button-layout'):
 
339
                value = 'close,minimize,maximize:' + 'menu'
 
340
                gsettings.wm.set_string('button-layout', value)
 
341
                self.refresh_window_menu_check()
 
342
                del value
 
343
            else:
 
344
                value = 'close,minimize,maximize:'
 
345
                gsettings.wm.set_string('button-layout', value)
 
346
                self.refresh_window_menu_check()
 
347
                del value
 
348
 
 
349
    def on_check_show_menu_toggled(self, button, udata = None):
 
350
 
 
351
        if gsettings.wm.get_string('button-layout').endswith(':'):
 
352
            value = gsettings.wm.get_string('button-layout') + 'menu'
 
353
            gsettings.wm.set_string('button-layout', value)
 
354
            del value
 
355
        elif gsettings.wm.get_string('button-layout').startswith(':'):
 
356
            value = 'menu' + gsettings.wm.get_string('button-layout')
 
357
            gsettings.wm.set_string('button-layout', value)
 
358
            del value
 
359
        else:
 
360
            if 'menu' in gsettings.wm.get_string('button-layout'):
 
361
                value = str(gsettings.wm.get_string('button-layout')).replace('menu', '')
 
362
                gsettings.wm.set_string('button-layout', value)
 
363
            else:
 
364
                return
 
365
 
 
366
    def on_b_theme_window_controls_reset_clicked(self, widget):
 
367
        self.ui['check_show_menu'].set_active(False)
 
368
        gsettings.wm.set_string('button-layout', 'close,minimize,maximize:')
 
369
        self.refresh_window_menu_check()
 
370
        self.refresh_window_controls()
 
371
 
 
372
#----- End: Window control settings--------