Add change callback, and write code

This commit is contained in:
Douglas Clowes
2013-08-16 15:37:31 +10:00
parent 75cc6a1ff6
commit 4ecebd5e1f

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env python
# vim: tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
import sys
import urwid
import ConfigParser
@@ -11,11 +12,29 @@ def main():
u"UP / DOWN / PAGE UP / PAGE DOWN scroll. F8 exits.")
text_button_list = [u"Yes", u"No", u"Perhaps", u"Certainly", u"Partially",
u"Tuesdays Only", u"Help"]
text_cb_list = [u"Wax", u"Wash", u"Buff", u"Clear Coat", u"Dry",
u"Racing Stripe"]
def checkbox_change(check_box, new_state, user_data):
config.set(user_data, 'enabled', str(new_state))
line = u"Checkbox: name=%s, new_state=%s, user_data=%s" % (
check_box.get_label(), str(new_state), str(user_data))
frame.footer = urwid.AttrWrap(urwid.Text(
line), 'header')
text_cb_list = list(config.sections())
cb_list =[urwid.AttrWrap(urwid.CheckBox(txt),'buttn','buttnf')
for txt in text_cb_list]
cb_list = []
for txt in 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 = urwid.AttrWrap(
urwid.CheckBox(txt,
state=state,
on_state_change=checkbox_change,
user_data=txt),
'buttn','buttnf')
cb_list.append(cb)
text_rb_list = [u"Morning", u"Afternoon", u"Evening", u"Weekend"]
@@ -35,7 +54,7 @@ def main():
blank,
urwid.Padding(urwid.GridFlow(
cb_list,
10, 3, 1, 'left') ,
20, 3, 1, 'left') ,
left=4, right=3, min_width=10),
blank,
# urwid.Padding(urwid.GridFlow(
@@ -64,6 +83,9 @@ def main():
]
def unhandled(key):
if key in ['w', 'W', 'f10']:
with open("junk.ini", "wb") as configfile:
config.write(configfile)
if key in ['q', 'Q', 'f8']:
raise urwid.ExitMainLoop()