This repository has been archived by the owner on May 13, 2018. It is now read-only.
forked from freyja-dev/unity-tweak-tool
/
unity.py
462 lines (387 loc) · 20.5 KB
/
unity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Team:
# J Phani Mahesh <phanimahesh@gmail.com>
# Barneedhar (jokerdino) <barneedhar@ubuntu.com>
# Amith KK <amithkumaran@gmail.com>
# Georgi Karavasilev <motorslav@gmail.com>
# Sam Tran <samvtran@gmail.com>
# Sam Hewitt <hewittsamuel@gmail.com>
# Angel Araya <al.arayaq@gmail.com>
#
# Description:
# A One-stop configuration tool for Unity.
#
# Legal Stuff:
#
# This file is a part of Unity Tweak Tool
#
# Unity Tweak Tool is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 3.
#
# Unity Tweak Tool is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <https://www.gnu.org/licenses/gpl-3.0.txt>
import os, os.path
from gi.repository import Gtk, Gdk
from UnityTweakTool.config.ui import ui
from . import unitytweakconfig
from . import gsettings
from .values import values
class Unitysettings ():
def __init__(self, builder):
self.ui = ui(builder)
self.ui['sc_reveal_sensitivity'].add_mark(2.0, Gtk.PositionType.BOTTOM, None)
self.ui['sc_launcher_transparency'].add_mark(.666, Gtk.PositionType.BOTTOM, None)
self.ui['sc_panel_transparency'].add_mark(.67, Gtk.PositionType.BOTTOM, None)
if Gdk.Screen.get_default().get_n_monitors() == 1:
dependants = ['l_launcher_visibility',
'radio_launcher_visibility_all',
'radio_launcher_visibility_primary',
'l_notifications',
'radio_active_monitor',
'radio_all_monitors']
self.ui.unsensitize(dependants)
#=====================================================================#
# Helpers #
#=====================================================================#
def refresh(self):
'''Reads the current config and refreshes the displayed values'''
# Colour
color = gsettings.unityshell.get_string('background-color')
if color.endswith('00'):
self.ui['radio_launcher_color_cham'].set_active(True)
self.ui.unsensitize(['color_launcher_color_cus'])
else:
self.ui['radio_launcher_color_cus'].set_active(True)
self.ui.sensitize(['color_launcher_color_cus'])
valid, gdkcolor = Gdk.Color.parse(color[:-2])
if valid:
self.ui['color_launcher_color_cus'].set_color(gdkcolor)
del color, valid, gdkcolor
# Show Desktop
self.ui['sw_show_desktop'].set_active(True if 'unity://desktop-icon' in gsettings.launcher.get_strv('favorites') else False)
# ====== Dash Helpers ===== #
# Run Command History
dependants = ['b_clear_run_history']
if gsettings.runner.get_strv('history') == '[]':
self.ui.unsensitize(dependants)
self.ui['b_clear_run_history'].set_active(False)
else:
self.ui.sensitize(dependants)
del dependants
# ====== Panel Helpers ====== #
self.ui['sc_panel_transparency'].set_value(gsettings.unityshell.get_double('panel-opacity'))
# Default Player
interested_players = gsettings.sound.get_strv('interested-media-players')
preferred_players = gsettings.sound.get_strv('preferred-media-players')
for player in interested_players:
self.ui['cbox_default_player'].append_text(player.capitalize())
if preferred_players[0] in interested_players:
self.ui['cbox_default_player'].set_active(interested_players.index(preferred_players[0]))
# ====== Unity Switcher helpers ====== #
# Window Switcher accelerators
model = self.ui['list_unity_switcher_windows_accelerators']
alt_tab_forward = gsettings.unityshell.get_string('alt-tab-forward')
iter_alt_tab_forward = model.get_iter_first()
model.set_value(iter_alt_tab_forward, 1, alt_tab_forward)
alt_tab_prev = gsettings.unityshell.get_string('alt-tab-prev')
iter_alt_tab_prev = model.iter_next(iter_alt_tab_forward)
model.set_value(iter_alt_tab_prev, 1, alt_tab_prev)
alt_tab_forward_all = gsettings.unityshell.get_string('alt-tab-forward-all')
iter_alt_tab_forward_all = model.iter_next(iter_alt_tab_prev)
model.set_value(iter_alt_tab_forward_all, 1, alt_tab_forward_all)
alt_tab_prev_all = gsettings.unityshell.get_string('alt-tab-prev-all')
iter_alt_tab_prev_all = model.iter_next(iter_alt_tab_forward_all)
model.set_value(iter_alt_tab_prev_all, 1, alt_tab_prev_all)
alt_tab_right = gsettings.unityshell.get_string('alt-tab-right')
iter_alt_tab_right = model.iter_next(iter_alt_tab_prev_all)
model.set_value(iter_alt_tab_right, 1, alt_tab_right)
alt_tab_left = gsettings.unityshell.get_string('alt-tab-left')
iter_alt_tab_left = model.iter_next(iter_alt_tab_right)
model.set_value(iter_alt_tab_left, 1, alt_tab_left)
alt_tab_detail_start = gsettings.unityshell.get_string('alt-tab-detail-start')
iter_alt_tab_detail_start = model.iter_next(iter_alt_tab_left)
model.set_value(iter_alt_tab_detail_start, 1, alt_tab_detail_start)
alt_tab_detail_stop = gsettings.unityshell.get_string('alt-tab-detail-stop')
iter_alt_tab_detail_stop = model.iter_next(iter_alt_tab_detail_start)
model.set_value(iter_alt_tab_detail_stop, 1, alt_tab_detail_stop)
alt_tab_next_window = gsettings.unityshell.get_string('alt-tab-next-window')
iter_alt_tab_next_window = model.iter_next(iter_alt_tab_detail_stop)
model.set_value(iter_alt_tab_next_window, 1, alt_tab_next_window)
alt_tab_prev_window = gsettings.unityshell.get_string('alt-tab-prev-window')
iter_alt_tab_prev_window = model.iter_next(iter_alt_tab_next_window)
model.set_value(iter_alt_tab_prev_window, 1, alt_tab_prev_window)
del model
# Launcher switcher accelerators
model = self.ui['list_unity_switcher_launcher_accelerators']
launcher_switcher_forward = gsettings.unityshell.get_string('launcher-switcher-forward')
iter_launcher_switcher_forward = model.get_iter_first()
model.set_value(iter_launcher_switcher_forward, 1, launcher_switcher_forward)
launcher_switcher_prev = gsettings.unityshell.get_string('launcher-switcher-prev')
iter_launcher_switcher_prev = model.iter_next(iter_launcher_switcher_forward)
model.set_value(iter_launcher_switcher_prev, 1, launcher_switcher_prev)
del model, launcher_switcher_forward, iter_launcher_switcher_forward, launcher_switcher_prev, iter_launcher_switcher_prev
# ====== Unity Webapps helpers ===== #
# Preauthorized domains
self.ui['check_preauthorized_amazon'].set_active(True if 'amazon.ca' in gsettings.webapps.get_strv('preauthorized-domains') else False)
self.ui['check_preauthorized_ubuntuone'].set_active(True if 'one.ubuntu.com' in gsettings.webapps.get_strv('preauthorized-domains') else False)
# ====== Unity additional helpers ======= #
model = self.ui['list_unity_additional_accelerators']
show_hud = gsettings.unityshell.get_string('show-hud')
iter_show_hud = model.get_iter_first()
model.set_value(iter_show_hud, 1, show_hud)
show_launcher = gsettings.unityshell.get_string('show-launcher')
iter_show_launcher = model.iter_next(iter_show_hud)
model.set_value(iter_show_launcher, 1, show_launcher)
execute_command = gsettings.unityshell.get_string('execute-command')
iter_execute_command = model.iter_next(iter_show_launcher)
model.set_value(iter_execute_command, 1, execute_command)
keyboard_focus = gsettings.unityshell.get_string('keyboard-focus')
iter_keyboard_focus = model.iter_next(iter_execute_command)
model.set_value(iter_keyboard_focus, 1, keyboard_focus)
panel_first_menu = gsettings.unityshell.get_string('panel-first-menu')
iter_panel_first_menu = model.iter_next(iter_keyboard_focus)
model.set_value(iter_panel_first_menu, 1, panel_first_menu)
del model, show_hud, iter_show_hud, show_launcher, iter_show_launcher, execute_command, iter_execute_command, keyboard_focus, iter_keyboard_focus, panel_first_menu, iter_panel_first_menu
# ===== BEGIN: Unity settings =====
# ----- BEGIN: Launcher -----
def on_sc_reveal_sensitivity_value_changed(self, widget, udata = None):
value = self.ui['sc_reveal_sensitivity'].get_value()
gsettings.unityshell.set_double('edge-responsiveness', value)
del value
def on_sc_launcher_transparency_value_changed(self, widget, udata = None):
opacity = self.ui['sc_launcher_transparency'].get_value()
gsettings.unityshell.set_double('launcher-opacity', opacity)
def on_radio_launcher_color_cus_toggled(self, widget, udata = None):
dependants = ['color_launcher_color_cus']
color = self.ui['color_launcher_color_cus'].get_color()
colorhash = gsettings.color_to_hash(color)
if self.ui['radio_launcher_color_cus'].get_active():
self.ui.sensitize(dependants)
gsettings.unityshell.set_string('background-color', colorhash)
else:
self.ui.unsensitize(dependants)
gsettings.unityshell.set_string('background-color', colorhash[:-2]+'00')
def on_sw_show_desktop_active_notify(self, widget, udata = None):
fav = gsettings.launcher.get_strv('favorites')
desktop = 'unity://desktop-icon'
if self.ui['sw_show_desktop'].get_active():
if desktop not in fav:
fav.append(desktop)
gsettings.launcher.set_strv('favorites', fav)
else:
if desktop in fav:
fav.remove(desktop)
gsettings.launcher.set_strv('favorites', fav)
del desktop
def on_b_unity_launcher_reset_clicked(self, widget):
gsettings.unityshell.reset('background-color')
gsettings.unityshell.reset('panel-opacity')
# Launcher items
fav = gsettings.launcher.get_strv('favorites')
desktop = 'unity://desktop-icon'
if desktop in fav:
fav.remove(desktop)
gsettings.launcher.set_strv('favorites', fav)
del desktop
del fav
self.refresh()
# ----- END: Launcher -----
# ----- BEGIN: Dash -----
def on_b_clear_run_history_clicked(self, widget):
gsettings.runner.reset('history')
#----- END: Dash -------
#----- BEGIN: Panel -----
def on_sc_panel_transparency_value_changed(self, widget, udata = None):
panel_transparency = widget.get_value()
gsettings.unityshell.set_double('panel-opacity', panel_transparency)
def on_cbox_default_player_changed(self, widget, udata = None):
combobox_text = self.ui['cbox_default_player'].get_active_text()
gsettings.sound.set_strv('preferred-media-players', [combobox_text.lower()])
def on_b_unity_panel_reset_clicked(self, widget):
gsettings.sound.reset('preferred-media-players')
self.refresh()
#----- END: Panel -----
#----- BEGIN: Switcher -----
# keyboard widgets in unity-windows-switcher
def on_craccel_unity_switcher_windows_accel_edited(self, craccel, path, key, mods, hwcode, model = None):
model = self.ui['list_unity_switcher_windows_accelerators']
accel = Gtk.accelerator_name(key, mods)
titer = model.get_iter(path)
model.set_value(titer, 1, accel)
# Python has no switch statement, right?
if path == '0':
gsettings.unityshell.set_string('alt-tab-forward', accel)
elif path == '1':
gsettings.unityshell.set_string('alt-tab-prev', accel)
elif path == '2':
gsettings.unityshell.set_string('alt-tab-forward-all', accel)
elif path == '3':
gsettings.unityshell.set_string('alt-tab-prev-all', accel)
elif path == '4':
gsettings.unityshell.set_string('alt-tab-right', accel)
elif path == '5':
gsettings.unityshell.set_string('alt-tab-left', accel)
elif path == '6':
gsettings.unityshell.set_string('alt-tab-detail-start', accel)
elif path == '7':
gsettings.unityshell.set_string('alt-tab-detail-stop', accel)
elif path == '8':
gsettings.unityshell.set_string('alt-tab-next-window', accel)
elif path == '9':
gsettings.unityshell.set_string('alt-tab-prev-window', accel)
def on_craccel_unity_switcher_windows_accel_cleared(self, craccel, path, model = None):
model = self.ui['list_unity_switcher_windows_accelerators']
titer = model.get_iter(path)
model.set_value(titer, 1, 'Disabled')
if path == '0':
gsettings.unityshell.set_string('alt-tab-forward', 'Disabled')
elif path == '1':
gsettings.unityshell.set_string('alt-tab-prev', 'Disabled')
elif path == '2':
gsettings.unityshell.set_string('alt-tab-forward-all', 'Disabled')
elif path == '3':
gsettings.unityshell.set_string('alt-tab-prev-all', 'Disabled')
elif path == '4':
gsettings.unityshell.set_string('alt-tab-right', 'Disabled')
elif path == '5':
gsettings.unityshell.set_string('alt-tab-left', 'Disabled')
elif path == '6':
gsettings.unityshell.set_string('alt-tab-detail-start', 'Disabled')
elif path == '7':
gsettings.unityshell.set_string('alt-tab-detail-stop', 'Disabled')
elif path == '8':
gsettings.unityshell.set_string('alt-tab-next-window', 'Disabled')
elif path == '9':
gsettings.unityshell.set_string('alt-tab-prev-window', 'Disabled')
# keyboard widgets in unity-launcher-switcher
def on_craccel_unity_switcher_launcher_accel_edited(self, craccel, path, key, mods, hwcode, model = None):
model = self.ui['list_unity_switcher_launcher_accelerators']
accel = Gtk.accelerator_name(key, mods)
titer = model.get_iter(path)
model.set_value(titer, 1, accel)
# Python has no switch statement, right?
if path == '0':
gsettings.unityshell.set_string('launcher-switcher-forward', accel)
else:
gsettings.unityshell.set_string('launcher-switcher-prev', accel)
def on_craccel_unity_switcher_launcher_accel_cleared(self, craccel, path, model = None):
model = self.ui['list_unity_switcher_launcher_accelerators']
titer = model.get_iter(path)
model.set_value(titer, 1, 'Disabled')
if path == '0':
gsettings.unityshell.set_string('launcher-switcher-forward', 'Disabled')
else:
gsettings.unityshell.set_string('launcher-switcher-prev', 'Disabled')
def on_b_unity_switcher_reset_clicked(self, widget):
gsettings.unityshell.reset('alt-tab-forward')
gsettings.unityshell.reset('alt-tab-prev')
gsettings.unityshell.reset('alt-tab-forward-all')
gsettings.unityshell.reset('alt-tab-prev-all')
gsettings.unityshell.reset('alt-tab-right')
gsettings.unityshell.reset('alt-tab-left')
gsettings.unityshell.reset('alt-tab-detail-start')
gsettings.unityshell.reset('alt-tab-detail-stop')
gsettings.unityshell.reset('alt-tab-next-window')
gsettings.unityshell.reset('alt-tab-prev-window')
gsettings.unityshell.reset('launcher-switcher-forward')
gsettings.unityshell.reset('launcher-switcher-prev')
self.refresh()
#----- END: Switch -----
#----- BEGIN: Webapps -----
# Preauthorized domains - Amazon
def on_check_preauthorized_amazon_toggled(self, widget):
if self.ui['check_preauthorized_amazon'].get_active() == False:
preauthorized = gsettings.webapps.get_strv('preauthorized-domains')
amazonca = 'amazon.ca'
if amazonca in preauthorized:
amazonlist = ['amazon.ca', 'amazon.cn', 'amazon.com', 'amazon.co.uk', 'amazon.de', 'amazon.es', 'amazon.fr', 'amazon.it', 'www.amazon.ca', 'www.amazon.cn', 'www.amazon.com', 'www.amazon.co.uk', 'www.amazon.de', 'www.amazon.es', 'www.amazon.fr', 'www.amazon.it']
for amazon in amazonlist:
preauthorized.remove(amazon)
gsettings.webapps.set_strv('preauthorized-domains', preauthorized)
elif amazonca not in preauthorized:
pass
else:
preauthorized = gsettings.webapps.get_strv('preauthorized-domains')
amazonca = 'amazon.ca'
if amazonca not in preauthorized:
amazonlist = ['amazon.ca', 'amazon.cn', 'amazon.com', 'amazon.co.uk', 'amazon.de', 'amazon.es', 'amazon.fr', 'amazon.it', 'www.amazon.ca', 'www.amazon.cn', 'www.amazon.com', 'www.amazon.co.uk', 'www.amazon.de', 'www.amazon.es', 'www.amazon.fr', 'www.amazon.it']
for amazon in amazonlist:
preauthorized.append(amazon)
gsettings.webapps.set_strv('preauthorized-domains', preauthorized)
elif amazonca in preauthorized:
pass
# Preauthorized domains - Ubuntu One
def on_check_preauthorized_ubuntuone_toggled(self, widget):
if self.ui['check_preauthorized_ubuntuone'].get_active() == False:
preauthorized = gsettings.webapps.get_strv('preauthorized-domains')
ubuntuone = 'one.ubuntu.com'
if ubuntuone in preauthorized:
preauthorized.remove(ubuntuone)
gsettings.webapps.set_strv('preauthorized-domains', preauthorized)
elif ubuntuone not in preauthorized:
pass
else:
preauthorized = gsettings.webapps.get_strv('preauthorized-domains')
ubuntuone = 'one.ubuntu.com'
if ubuntuone not in preauthorized:
preauthorized.append(ubuntuone)
gsettings.webapps.set_strv('preauthorized-domains', preauthorized)
elif ubuntuone in preauthorized:
pass
# Reset button
def on_b_unity_webapps_reset_clicked(self, widget):
gsettings.webapps.reset('preauthorized-domains')
self.refresh()
#----- END: Webapps -----
#----- BEGIN: Additional -----
# keyboard widgets in unity-additional
def on_craccel_unity_additional_accel_edited(self, craccel, path, key, mods, hwcode, model = None):
# Glade has a habit of swapping arguments. beware.
model = self.ui['list_unity_additional_accelerators']
accel = Gtk.accelerator_name(key, mods)
titer = model.get_iter(path)
model.set_value(titer, 1, accel)
# Python has no switch statement, right?
# You are right, jokerdino. Python has no switch statement.
# That is against OOP principles. -jpm
if path == '0':
gsettings.unityshell.set_string('show-hud', accel)
elif path == '1':
gsettings.unityshell.set_string('show-launcher', accel)
elif path == '2':
gsettings.unityshell.set_string('execute-command', accel)
elif path == '3':
gsettings.unityshell.set_string('keyboard-focus', accel)
else:
gsettings.unityshell.set_string('panel-first-menu', accel)
def on_craccel_unity_additional_accel_cleared(self, craccel, path, model = None):
model = self.ui['list_unity_additional_accelerators']
titer = model.get_iter(path)
model.set_value(titer, 1, 'Disabled')
if path == '0':
gsettings.unityshell.set_string('show-hud', 'Disabled')
elif path == '1':
gsettings.unityshell.set_string('show-launcher', 'Disabled')
elif path == '2':
gsettings.unityshell.set_string('execute-command', 'Disabled')
elif path == '3':
gsettings.unityshell.set_string('keyboard-focus', 'Disabled')
else:
gsettings.unityshell.set_string('panel-first-menu', 'Disabled')
def on_b_unity_additional_reset_clicked(self, widget):
gsettings.unityshell.reset('shortcut-overlay')
gsettings.unityshell.reset('show-hud')
gsettings.unityshell.reset('show-launcher')
gsettings.unityshell.reset('execute-command')
gsettings.unityshell.reset('keyboard-focus')
gsettings.unityshell.reset('panel-first-menu')
self.refresh()
#----- END: Additional -----