-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppRun
executable file
·162 lines (135 loc) · 5.28 KB
/
AppRun
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
#!/usr/bin/env python
import findrox; findrox.version(1, 9, 6)
import os
import subprocess
import sys
import gtk
import rox
from rox.settings import Setting, Settings
from rox.OptionsBox import OptionsBox as OBBase
__builtins__._ = rox.i18n.translation(os.path.join(rox.app_dir, 'Messages'))
class OptionsBox(OBBase):
def __init__(self, options_group, options_xml, translation = None):
self.wdict = {}
OBBase.__init__(self, options_group, options_xml, translation)
self.all_timeouts = map(self.__get_spin_button_by_name,
('BlankTime', 'DPMSStandby', 'DPMSSuspend', 'DPMSOff'))
self.__connect_signals()
def __build_and_store(self, node, label, option, builder):
widgets = builder(self, node, label, option)
name = rox.OptionsBox.str_attr(node, 'name')
if name:
if name.startswith('ROX/'):
name = name[4:]
self.wdict[name] = widgets
return widgets
def build_toggle(self, node, label, option):
return self.__build_and_store(node, label, option,
OBBase.build_toggle)
def build_radio_group(self, node, label, option):
return self.__build_and_store(node, label, option,
OBBase.build_radio_group)
def build_numentry(self, node, label, option):
return self.__build_and_store(node, label, option,
OBBase.build_numentry)
def __connect_signals(self):
self.__connect_toggled('ManageScreensaver', self.__radio_toggled)
self.__connect_toggled('DPMSEnable', self.__dpms_toggled)
self.__connect_timeout_changed('BlankTime')
self.__connect_timeout_changed('DPMSStandby')
self.__connect_timeout_changed('DPMSSuspend')
self.__connect_timeout_changed('DPMSOff')
def __connect_toggled(self, name, fn):
self.wdict[name][0].connect("toggled", fn)
def __connect_timeout_changed(self, name):
w = self.__get_spin_button_by_name(name)
if w:
w.connect("changed", self.__timeout_changed)
def __get_spin_button_by_name(self, name):
for w in self.wdict[name][0].get_children():
if isinstance(w, gtk.SpinButton):
return w
else:
print >> sys.stderr, \
'No spin button found for option "ROX/%s"' % name
return None
def __radio_toggled(self, w):
radios = self.wdict['ManageScreensaver']
for n in range(3):
if radios[n].get_active():
sensitive = n == 1
gnome = n == 2
break
else:
sensitive = False
gnome = False
for n in ['BlankTime', 'DPMSEnable']:
self.__set_sensitive(n, sensitive)
if sensitive:
sensitive = self.wdict['DPMSEnable'][0].get_active()
self.__set_dpms_sensitive(sensitive)
self.gss_prefs_button.set_sensitive(gnome)
def __dpms_toggled(self, w):
sensitive = self.wdict['DPMSEnable'][0].get_active()
self.__set_dpms_sensitive(sensitive)
def __set_dpms_sensitive(self, sensitive):
for n in ['DPMSStandby', 'DPMSSuspend', 'DPMSOff']:
self.__set_sensitive(n, sensitive)
def __set_sensitive(self, name, sensitive):
for w in self.wdict[name]:
w.set_sensitive(sensitive)
def __timeout_changed(self, w):
timeout = w.get_value_as_int()
if not timeout:
return
if w == self.all_timeouts[0]:
before = []
after = self.all_timeouts[1:]
elif w == self.all_timeouts[1]:
before = self.all_timeouts[:1]
after = self.all_timeouts[2:]
elif w == self.all_timeouts[2]:
before = self.all_timeouts[:2]
after = self.all_timeouts[3:]
elif w == self.all_timeouts[3]:
before = self.all_timeouts[:3]
after = []
else:
print >>sys.stderr, "Value of unknown widget changed"
return
for w in before:
if w.get_value_as_int() > timeout:
w.set_value(timeout)
for w in after:
t = w.get_value_as_int()
if t and t < timeout:
w.set_value(timeout)
def open(self):
self.__dpms_toggled(None)
self.__radio_toggled(None)
for n in ['BlankTime', 'DPMSStandby', 'DPMSSuspend', 'DPMSOff']:
self.__timeout_changed(self.__get_spin_button_by_name(n))
OBBase.open(self)
def launch_from_button(w, command):
subprocess.Popen([command])
def build_cmd_button(box, node, label):
button = gtk.Button(label)
box.may_add_tip(button, node)
button.connect('clicked', launch_from_button,
rox.OptionsBox.str_attr(node, 'value'))
box.gss_prefs_button = button
return [button]
rox.OptionsBox.widget_registry['cmd_button'] = build_cmd_button
settings = Settings()
class SSS(Setting):
def __init__(self, name, default):
Setting.__init__(self, name, default, settings)
SSS('ROX/ManageScreensaver', 0)
SSS('ROX/BlankTime', 10)
SSS('ROX/DPMSEnable', 1)
SSS('ROX/DPMSStandby', 15)
SSS('ROX/DPMSSuspend', 20)
SSS('ROX/DPMSOff', 30)
box = OptionsBox(settings, os.path.join(rox.app_dir, 'Options.xml'))
box.open()
rox.mainloop()