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'))
186
# ===== Window Controls ===== #
189
def refresh_window_controls(self):
191
dependants = ['radio_left',
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)
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)
208
self.ui['check_show_menu'].set_active(False)
210
# TODO : Find a clever way or set each one manually.
211
# Do it the dumb way now. BIIIG refactoring needed later.
214
#-----BEGIN: Theme settings------
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
220
def on_treeselection_gtk_theme_changed(self,udata=None):
221
gtktreesel = self.ui['tree_gtk_theme'].get_selection()
222
if gtktreesel is None:
224
gtkthemestore,iter = gtktreesel.get_selected()
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)
231
def on_treeselection_window_theme_changed(self,udata=None):
232
windowtreesel = self.ui['tree_window_theme'].get_selection()
233
if windowtreesel is None:
235
windowthemestore,iter = windowtreesel.get_selected()
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)
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:
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)
252
def on_check_show_incomplete_toggled(self,udata=None):
256
def on_b_theme_system_reset_clicked(self, widget):
257
gsettings.interface.reset('gtk-theme')
258
gsettings.wm.reset('theme')
261
#----- End: Theme settings------
263
#----- Begin: Icon settings--------
265
def on_b_theme_icon_reset_clicked(self, widget):
266
gsettings.interface.reset('icon-theme')
269
#----- End: Icon settings------
271
#----- Begin: Cursor settings--------
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:
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)
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)
288
gsettings.interface.set_int('cursor-size', 24)
290
def on_b_theme_cursor_reset_clicked(self, widget):
291
gsettings.interface.reset('cursor-theme')
292
gsettings.interface.reset('cursor-size')
295
#----- End: Cursor settings------
296
#----- Begin: Window control settings--------
298
def on_radio_left_toggled(self, button, udata = None):
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()
307
value = 'close,minimize,maximize:'
308
gsettings.wm.set_string('button-layout', value)
309
self.refresh_window_menu_check()
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()
318
value = ':minimize,maximize,close'
319
gsettings.wm.set_string('button-layout', value)
320
self.refresh_window_menu_check()
323
def on_radio_right_toggled(self, button, udata = None):
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()
333
value = ':minimize,maximize,close'
334
gsettings.wm.set_string('button-layout', value)
335
self.refresh_window_menu_check()
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()
344
value = 'close,minimize,maximize:'
345
gsettings.wm.set_string('button-layout', value)
346
self.refresh_window_menu_check()
349
def on_check_show_menu_toggled(self, button, udata = None):
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)
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)
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)
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()
372
#----- End: Window control settings--------