100 lines
3.2 KiB
Python
100 lines
3.2 KiB
Python
#!/usr/bin/env python
|
|
# vim: tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
|
|
|
|
import sys
|
|
import urwid
|
|
import ConfigParser
|
|
|
|
def main():
|
|
config = ConfigParser.SafeConfigParser()
|
|
config.read("my_config_parser.ini")
|
|
text_header = (u"SICS Config Editor!\n"
|
|
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"]
|
|
|
|
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 = []
|
|
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"]
|
|
|
|
|
|
def button_press(button):
|
|
frame.footer = urwid.AttrWrap(urwid.Text(
|
|
[u"Pressed: ", button.get_label()]), 'header')
|
|
|
|
radio_button_group = []
|
|
|
|
blank = urwid.Divider()
|
|
listbox_content = [
|
|
# urwid.Padding(urwid.GridFlow(
|
|
# [urwid.AttrWrap(urwid.Button(txt, button_press),
|
|
# 'buttn','buttnf') for txt in text_button_list],
|
|
# 13, 3, 1, 'left'),
|
|
# left=4, right=3, min_width=13),
|
|
blank,
|
|
urwid.Padding(urwid.GridFlow(
|
|
cb_list,
|
|
20, 3, 1, 'left') ,
|
|
left=4, right=3, min_width=10),
|
|
blank,
|
|
# urwid.Padding(urwid.GridFlow(
|
|
# [urwid.AttrWrap(urwid.RadioButton(radio_button_group,
|
|
# txt), 'buttn','buttnf')
|
|
# for txt in text_rb_list],
|
|
# 13, 3, 1, 'left') ,
|
|
# left=4, right=3, min_width=13),
|
|
# blank,
|
|
]
|
|
header = urwid.AttrWrap(urwid.Text(text_header), 'header')
|
|
listbox = urwid.ListBox(urwid.SimpleListWalker(listbox_content))
|
|
frame = urwid.Frame(urwid.AttrWrap(listbox, 'body'), header=header)
|
|
|
|
palette = [
|
|
('body','black','light gray', 'standout'),
|
|
('reverse','light gray','black'),
|
|
('header','white','dark red', 'bold'),
|
|
('important','dark blue','light gray',('standout','underline')),
|
|
('editfc','white', 'dark blue', 'bold'),
|
|
('editbx','light gray', 'dark blue'),
|
|
('editcp','black','light gray', 'standout'),
|
|
('bright','dark gray','light gray', ('bold','standout')),
|
|
('buttn','black','dark cyan'),
|
|
('buttnf','white','dark blue','bold'),
|
|
]
|
|
|
|
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()
|
|
|
|
urwid.MainLoop(frame, palette, unhandled_input=unhandled).run()
|
|
|
|
def setup():
|
|
main()
|
|
|
|
if '__main__'==__name__:
|
|
setup()
|
|
|