cascade, onifon, onifoff, offifon and offofoff
This commit is contained in:
@@ -25,6 +25,14 @@ def write_config_file(config, config_filename):
|
||||
configfile.write("\n")
|
||||
#config.write(configfile)
|
||||
|
||||
def do_cascade(config, name, cb_list, label, new_state):
|
||||
if label in config.options(name):
|
||||
cascade_list = config.get(name, label).lower().split(",")
|
||||
for cb in cb_list:
|
||||
lbl = cb.get_label().split(":")[0].lower()
|
||||
if lbl in cascade_list:
|
||||
cb.set_state(new_state)
|
||||
|
||||
def main(config_filename):
|
||||
import urwid
|
||||
|
||||
@@ -40,11 +48,15 @@ def main(config_filename):
|
||||
frame.footer = urwid.AttrWrap(urwid.Text(
|
||||
line), 'header')
|
||||
if 'cascade' in config.options(user_data):
|
||||
cascade_list = config.get(user_data, 'cascade').split(",")
|
||||
for cb in cb_list:
|
||||
lbl = cb.get_label().split(":")[0]
|
||||
if lbl in cascade_list:
|
||||
cb.set_state(new_state)
|
||||
do_cascade(config, user_data, cb_list, 'cascade', new_state)
|
||||
if new_state and 'onifon' in config.options(user_data):
|
||||
do_cascade(config, user_data, cb_list, 'onifon', True)
|
||||
if new_state and 'offifon' in config.options(user_data):
|
||||
do_cascade(config, user_data, cb_list, 'offifon', False)
|
||||
if (False == new_state) and 'onifoff' in config.options(user_data):
|
||||
do_cascade(config, user_data, cb_list, 'onifoff', True)
|
||||
if (False == new_state) and 'offifoff' in config.options(user_data):
|
||||
do_cascade(config, user_data, cb_list, 'offifoff', False)
|
||||
|
||||
text_cb_list = list(config.sections())
|
||||
cb_map = {}
|
||||
@@ -56,26 +68,27 @@ def main(config_filename):
|
||||
if group not in cb_map:
|
||||
cb_map[group] = []
|
||||
cb_map[group].append(txt)
|
||||
sorted_text_cb_list = []
|
||||
for key in sorted(cb_map.keys()):
|
||||
for val in sorted(cb_map[key]):
|
||||
sorted_text_cb_list.append(val)
|
||||
cb_list = []
|
||||
for txt in sorted_text_cb_list:
|
||||
state = False
|
||||
if 'enabled' in config.options(txt):
|
||||
if config.get(txt, 'enabled').lower() in ['1', 'yes', 'true']:
|
||||
state = True
|
||||
config.set(txt, 'enabled', str(state))
|
||||
cb_text = ""
|
||||
cb_text += txt
|
||||
if 'desc' in config.options(txt):
|
||||
cb_text += ": (" + config.get(txt, 'desc').strip("\"") + ")"
|
||||
cb = urwid.CheckBox(cb_text,
|
||||
state=state,
|
||||
on_state_change=checkbox_change,
|
||||
user_data=txt)
|
||||
cb_list.append(cb)
|
||||
for key in sorted(cb_map.keys()):
|
||||
#cb_list.append(urwid.AttrWrap(urwid.Text("Group: %s" % key), 'bright'))
|
||||
for txt in sorted(cb_map[key]):
|
||||
state = False
|
||||
if 'enabled' in config.options(txt):
|
||||
if config.get(txt, 'enabled').lower() in ['1', 'yes', 'true']:
|
||||
state = True
|
||||
config.set(txt, 'enabled', str(state))
|
||||
cb_text = ""
|
||||
cb_text += txt + ": ("
|
||||
if 'group' in config.options(txt):
|
||||
cb_text += config.get(txt, 'group').strip("\"") + ": "
|
||||
if 'desc' in config.options(txt):
|
||||
cb_text += config.get(txt, 'desc').strip("\"")
|
||||
cb_text += ")"
|
||||
cb = urwid.AttrWrap(urwid.CheckBox(cb_text,
|
||||
state=state,
|
||||
on_state_change=checkbox_change,
|
||||
user_data=txt), 'buttn', 'buttnf')
|
||||
cb_list.append(cb)
|
||||
|
||||
def fcc(focus):
|
||||
frame.footer = urwid.AttrWrap(urwid.Text(
|
||||
@@ -86,9 +99,9 @@ def main(config_filename):
|
||||
listbox_content = [
|
||||
blank,
|
||||
urwid.Padding(urwid.GridFlow(
|
||||
[urwid.AttrWrap(cb, 'buttn', 'buttnf') for cb in cb_list],
|
||||
60, 1, 0, 'left'),
|
||||
left=4, right=3, min_width=60),
|
||||
cb_list,
|
||||
76, 1, 0, 'left'),
|
||||
left=2, right=2, min_width=76),
|
||||
blank,
|
||||
blank
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user