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 |
# Load values from conf. store into gtk widgets
def load_config(self, config, prefix="config_"):
for key,val in config.items():
w = self.main.get_widget(prefix + key)
if w:
# input field
if type(w) is gtk.Entry:
w.set_text(str(val))
# checkmark
elif type(w) is gtk.CheckButton:
w.set_active(bool(val))
# dropdown
elif type(w) is ComboBoxText:
w.set_default(val)
# list
elif type(w) is gtk.ListStore:
w.clear()
for k,v in val.items():
w.append([k, v, True, self.app_bin_check(v)])
w.append(["", "", True, gtk.STOCK_NEW])
#log.CONF("config load", prefix+key, val, type(w))
# Store gtk widget valus back into conf. dict
def save_config(self, config, prefix="config_", save=0):
for key,val in config.items():
w = self.main.get_widget(prefix + key)
if w:
# text
if type(w) is gtk.Entry:
config[key] = w.get_text()
# pre-defined text
elif type(w) is ComboBoxText:
config[key] = w.get_active_text()
# boolean
elif type(w) is gtk.CheckButton:
config[key] = w.get_active()
# dict
elif type(w) is gtk.ListStore:
config[key] = {}
for row in w:
if row[0] and row[1]:
config[key][row[0]] = row[1]
log.CONF("config save", prefix+key, val)
|
|
|
|
>
>
>
|
|
|
|
>
>
>
|
| 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 |
# Load values from conf. store into gtk widgets
def load_config(self, config, prefix="config_"):
for key,val in config.items():
w = self.main.get_widget(prefix + key)
if w:
# input field
if isinstance(w, gtk.Entry):
w.set_text(str(val))
# checkmark
elif isinstance(w, gtk.CheckButton):
w.set_active(bool(val))
# dropdown
elif isinstance(w, ComboBoxText):
w.set_default(val)
# number
elif isinstance(w, gtk.SpinButton):
w.set_value(int(val))
# list
elif isinstance(w, gtk.ListStore):
w.clear()
for k,v in val.items():
w.append([k, v, True, self.app_bin_check(v)])
w.append(["", "", True, gtk.STOCK_NEW])
#log.CONF("config load", prefix+key, val, type(w))
# Store gtk widget valus back into conf. dict
def save_config(self, config, prefix="config_", save=0):
for key,val in config.items():
w = self.main.get_widget(prefix + key)
if w:
# text
if isinstance(w, gtk.Entry):
config[key] = w.get_text()
# pre-defined text
elif isinstance(w, ComboBoxText):
config[key] = w.get_active_text()
# boolean
elif isinstance(w, gtk.CheckButton):
config[key] = w.get_active()
# int
elif isinstance(w, gtk.SpinButton):
config[key] = int(w.get_value(val))
# dict
elif isinstance(w, gtk.ListStore):
config[key] = {}
for row in w:
if row[0] and row[1]:
config[key][row[0]] = row[1]
log.CONF("config save", prefix+key, val)
|
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 | cb.set_tooltip_text(self._tooltip(meta))
add_( "config_plugins_"+name, cb, color=meta.get("color"), image=meta.get("png"), align=0)
# Default values are already in conf[] dict
# (now done in conf.add_plugin_defaults)
for opt in meta["config"]:
color = opt.get("color", None)
# hidden
if opt.get("hidden"):
continue
# display checkbox
elif opt["type"] in ("bool", "boolean"):
cb = gtk.CheckButton(opt["description"])
add_( "config_"+opt["name"], cb, color=color )
# drop down list
elif opt["type"] in ("select", "choose", "options"):
cb = ComboBoxText(ComboBoxText.parse_options(opt["select"])) # custom uikit widget
add_( "config_"+opt["name"], cb, opt["description"], color )
# text entry
else:
add_( "config_"+opt["name"], gtk.Entry(), opt["description"], color )
# Spacer between plugins
add_( None, gtk.HSeparator() )
# Reformat `doc` linebreaks for gtk.tooltip
def _tooltip(self, meta):
doc = meta.get("doc", "").strip() |
>
>
|
|
>
>
>
>
|
>
>
|
| 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 | cb.set_tooltip_text(self._tooltip(meta))
add_( "config_plugins_"+name, cb, color=meta.get("color"), image=meta.get("png"), align=0)
# Default values are already in conf[] dict
# (now done in conf.add_plugin_defaults)
for opt in meta["config"]:
color = opt.get("color", None)
type = opt.get("type", "str")
description = opt.get("description", "./.")
# hidden
if opt.get("hidden"):
continue
# display checkbox
elif opt["type"] in ("bool", "boolean"):
cb = gtk.CheckButton(opt["description"])
description = None
# drop down list
elif opt["type"] in ("select", "choose", "options"):
cb = ComboBoxText(ComboBoxText.parse_options(opt["select"])) # custom uikit widget
# numeric
elif opt["type"] in ("int", "integer", "numeric"):
adj = gtk.Adjustment(0, 0, 5000, 1, 10, 0)
cb = gtk.SpinButton(adj, 1.0, 0)
# text field
else:
cb = gtk.Entry()
add_( "config_"+opt["name"], cb, description, color )
# Spacer between plugins
add_( None, gtk.HSeparator() )
# Reformat `doc` linebreaks for gtk.tooltip
def _tooltip(self, meta):
doc = meta.get("doc", "").strip() |