81 lines
2.4 KiB
Python
81 lines
2.4 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.")
|
|
|
|
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())
|
|
print 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)
|
|
print cb_list
|
|
|
|
def fcc(focus):
|
|
frame.footer = urwid.AttrWrap(urwid.Text(
|
|
[u"Focus: " + str(focus)]), 'header')
|
|
|
|
sflw = urwid.SimpleFocusListWalker(cb_list)
|
|
sflw.set_focus_changed_callback(fcc)
|
|
listbox = urwid.ListBox(sflw)
|
|
|
|
header = urwid.AttrWrap(urwid.Text(text_header), 'header')
|
|
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)
|
|
elif key in ['q', 'Q', 'f8']:
|
|
raise urwid.ExitMainLoop()
|
|
else:
|
|
frame.footer = urwid.AttrWrap(urwid.Text(
|
|
[u"Press: " + str(key)]), 'header')
|
|
|
|
urwid.MainLoop(frame, palette, unhandled_input=unhandled).run()
|
|
|
|
def setup():
|
|
main()
|
|
|
|
if '__main__'==__name__:
|
|
setup()
|
|
|