2
# -*- coding: utf-8 -*-
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>
14
# A One-stop configuration tool for Unity.
18
# This file is a part of Unity Tweak Tool
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.
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
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>
34
from gi.repository import Gtk, Gio
36
from UnityTweakTool.config.ui import ui
37
from . import unitytweakconfig
38
from . import gsettings
40
class Themesettings ():
41
def __init__(self, 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)
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))]
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))]
56
allthemes=systemthemes+userthemes
58
required=['gtk-2.0','gtk-3.0','metacity-1']
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]}
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)
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:
78
systemiconthemes.remove(item)
79
except ValueError as e:
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))]
86
allithemes=systemiconthemes+usericonthemes
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]}
100
#=====================================================================#
102
#=====================================================================#
108
gtkthemesel=self.ui['tree_gtk_theme'].get_selection()
109
gtktheme=gsettings.gnome('desktop.interface').get_string('gtk-theme')
111
# FIXME: Workaround to fix LP bug: #1098845
113
gtkthemesel.select_iter(self.gtkthemes[gtktheme]['iter'])
115
# TODO: This except part should do something more.
117
gtkthemesel.unselect_all()
120
windowthemesel=self.ui['tree_window_theme'].get_selection()
121
windowtheme=gsettings.gnome('desktop.wm.preferences').get_string('theme')
123
# FIXME: Workaround to fix LP bug: #1146122
125
windowthemesel.select_iter(self.windowthemes[windowtheme]['iter'])
127
# TODO: This except part should do a lot more.
129
windowthemesel.unselect_all()
132
iconthemesel=self.ui['tree_icon_theme'].get_selection()
133
icontheme=gsettings.gnome('desktop.interface').get_string('icon-theme')
135
# FIXME: Workaround to fix potential bug
137
iconthemesel.select_iter(self.iconthemes[icontheme]['iter'])
140
iconthemesel.unselect_all()
143
cursorthemesel=self.ui['tree_cursor_theme'].get_selection()
144
cursortheme=gsettings.gnome('desktop.interface').get_string('cursor-theme')
146
# FIXME: Workaround to fix LP bug: #1097227
149
cursorthemesel.select_iter(self.cursorthemes[cursortheme]['iter'])
150
# TODO: except part should make sure the selection is deselected.
152
cursorthemesel.unselect_all()
155
self.ui['check_cursor_size'].set_active(True if gsettings.interface.get_int('cursor-size') is 48 else False)
157
# ===== 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'))
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)
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)
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()
190
# ===== Window Controls ===== #
193
def refresh_window_controls(self):
195
combobox = ['cbox_custom_layout']
196
dependants = ['radio_left',
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)
206
self.ui['radio_custom_layout'].set_active(True)
207
self.ui.unsensitize(dependants)
208
self.ui.sensitize(combobox)
213
def refresh_window_controls_combobox(self):
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)
224
self.ui['cbox_custom_layout'].set_active(0)
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)
231
self.ui['check_show_menu'].set_active(False)
233
# TODO : Find a clever way or set each one manually.
234
# Do it the dumb way now. BIIIG refactoring needed later.
237
#-----BEGIN: Theme settings------
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
243
def on_treeselection_gtk_theme_changed(self,udata=None):
244
gtktreesel = self.ui['tree_gtk_theme'].get_selection()
245
if gtktreesel is None:
247
gtkthemestore,iter = gtktreesel.get_selected()
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)
254
def on_treeselection_window_theme_changed(self,udata=None):
255
windowtreesel = self.ui['tree_window_theme'].get_selection()
256
if windowtreesel is None:
258
windowthemestore,iter = windowtreesel.get_selected()
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)
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:
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)
275
def on_check_show_incomplete_toggled(self,udata=None):
279
def on_b_theme_system_reset_clicked(self, widget):
280
gsettings.interface.reset('gtk-theme')
281
gsettings.wm.reset('theme')
284
#----- End: Theme settings------
286
#----- Begin: Icon settings--------
288
def on_b_theme_icon_reset_clicked(self, widget):
289
gsettings.interface.reset('icon-theme')
292
#----- End: Icon settings------
294
#----- Begin: Cursor settings--------
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:
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)
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)
311
gsettings.interface.set_int('cursor-size', 24)
313
def on_b_theme_cursor_reset_clicked(self, widget):
314
gsettings.interface.reset('cursor-theme')
315
gsettings.interface.reset('cursor-size')
318
#----- End: Cursor settings------
319
#----- Begin: Window control settings--------
321
def on_radio_default_layout_toggled(self, button, udata = None):
322
combobox = ['cbox_custom_layout',]
323
dependants = ['radio_left',
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()
333
self.ui.unsensitize(dependants)
334
self.ui.sensitize(combobox)
335
self.refresh_window_menu_check()
337
def on_radio_left_toggled(self, button, udata = None):
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()
343
gsettings.wm.set_string('button-layout', ':minimize,maximize,close')
344
self.refresh_window_menu_check()
346
def on_radio_right_toggled(self, button, udata = None):
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()
352
gsettings.wm.set_string('button-layout', 'close,minimize,maximize:')
353
self.refresh_window_menu_check()
355
def on_radio_custom_layout_toggled(self, button, udata = None):
356
combobox = ['cbox_custom_layout']
357
dependants = ['radio_left',
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()
366
self.ui.unsensitize(combobox)
367
self.ui.sensitize(dependants)
368
self.refresh_window_menu_check()
370
def on_cbox_custom_layout_changed(self, widget, udata = None):
372
checkbox = ['check_show_menu']
373
if self.ui['cbox_custom_layout'].get_active() == 0:
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()
392
gsettings.wm.set_string('button-layout', 'close,minimize,maximize:')
393
self.ui.unsensitize(checkbox)
394
self.refresh_window_menu_check()
396
def on_check_show_menu_toggled(self, button, udata = None):
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)
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)
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)
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()
419
#----- End: Window control settings--------