-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme.py
88 lines (69 loc) · 2.43 KB
/
theme.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
import os
import rox
from rox import OptionsBox, g
import string
from rox.basedir import xdg_data_dirs
def build_theme_button(box, node, label):
b = g.Button()
b.set_label(label)
box.may_add_tip(b, node)
def open_theme_folder(self):
from rox import filer
filer.open_dir(os.path.join(os.path.expanduser("~"), '.icons'))
#def get():
# return 'false'
#def set():
#box.handlers[option] = (get, set)
b.connect('clicked', open_theme_folder)
return [b]
def add_icon_themes(themes, dir):
if not os.path.isdir(dir):
return
for theme in os.listdir(dir):
if theme.startswith('.'): continue
leaf = os.path.join(dir, theme)
if os.path.isdir(os.path.join(leaf, 'cursors')) or \
theme == "core_theme" and os.path.exists(os.path.join(leaf, 'index.theme')):
themes[theme] = True
def build_icon_theme(box, node, label, option):
hbox = g.HBox(False, 4)
hbox.pack_start(g.Label(_(label)), False, True, 0)
button = g.OptionMenu()
hbox.pack_start(button, True, True, 0)
menu = g.Menu()
button.set_menu(menu)
themes = {}
add_icon_themes(themes, os.path.expanduser('~/.icons'))
add_icon_themes(themes, '/usr/share/icons')
add_icon_themes(themes, '/usr/share/pixmaps')
add_icon_themes(themes, '/usr/X11R6/lib/X11/icons')
add_icon_themes(themes, '/usr/X11/lib/X11/icons')
names = themes.keys()
names.sort()
for name in names:
if name == "core_theme":
del names[names.index(name)]
names.insert(0, _("Core Theme"))
names.insert(0, _("No Theme"))
for name in names:
item = g.MenuItem(name)
menu.append(item)
item.show_all()
def update_theme():
i = -1
for kid in menu.get_children():
i += 1
item = kid.child
# The label actually moves from the menu!!
if not item:
item = button.child
label = item.get_text()
if label == option.value or label == _("No Theme"):
button.set_history(i)
def read_theme():
return button.child.get_text()
box.handlers[option] = (read_theme, update_theme)
button.connect('changed', lambda w: box.check_widget(option))
return [hbox]
OptionsBox.widget_registry['icon-theme'] = build_icon_theme
OptionsBox.widget_registry['folder-button'] = build_theme_button