Add some help and feedback when saving a file.
This commit is contained in:
@ -32,7 +32,7 @@ from collections import defaultdict
|
||||
PALETTE = [
|
||||
('body', 'dark cyan', '', 'standout'),
|
||||
('focus', 'dark red', '', 'standout'),
|
||||
('head', 'light red', 'black'),
|
||||
('head', 'yellow', 'black'),
|
||||
]
|
||||
|
||||
|
||||
@ -281,8 +281,8 @@ class InstConfigData(object):
|
||||
else:
|
||||
self.opt_dict[sect]['enabled'] = True
|
||||
self.set_imp(sect, selected_imp)
|
||||
dbmsg = 'Add imp2opt_dict[{0}] = {1}'
|
||||
print dbmsg.format(selected_imp, sect)
|
||||
# dbmsg = 'Add imp2opt_dict[{0}] = {1}'
|
||||
# print dbmsg.format(selected_imp, sect)
|
||||
else:
|
||||
self.opt_dict[sect]['enabled'] = False
|
||||
self.opt_dict[sect]['selected_imp'] = 'none'
|
||||
@ -305,7 +305,7 @@ class InstConfigData(object):
|
||||
|
||||
if sect not in self.imp2opt_dict:
|
||||
self.imp2opt_dict[sect] = 'none'
|
||||
print 'Add imp2opt_dict[{0}] = none'.format(sect)
|
||||
# print 'Add imp2opt_dict[{0}] = none'.format(sect)
|
||||
|
||||
def consistency_check(self):
|
||||
"""Check that there is a one to one mapping between options and
|
||||
@ -439,7 +439,7 @@ class InstConfigData(object):
|
||||
self.opt_dict[opt]['selected_imp'] = selected_imp
|
||||
|
||||
|
||||
class InstConfigView(urwid.Pile):
|
||||
class InstConfigView(urwid.Frame):
|
||||
|
||||
"""Extend urwid.Pile to provide an instrument configuration viewer.
|
||||
"""
|
||||
@ -456,9 +456,30 @@ class InstConfigView(urwid.Pile):
|
||||
opt_lb,
|
||||
imp_lb]
|
||||
|
||||
super(InstConfigView, self).__init__(option_listboxes)
|
||||
|
||||
self. main_loop = None
|
||||
self.cfg_pile = urwid.Pile(option_listboxes)
|
||||
self.help_str = 'Alt-Q (Quit), W (Write file)'
|
||||
self.header_text = urwid.Text(u'')
|
||||
self._msg_hdr('')
|
||||
self.mapped_header = urwid.AttrMap(self.header_text, 'head')
|
||||
|
||||
super(InstConfigView, self).__init__(header = self.mapped_header, body = self.cfg_pile)
|
||||
return
|
||||
|
||||
def _msg_hdr(self, msg):
|
||||
hdr = self.help_str + msg
|
||||
self.header_text.set_text(hdr)
|
||||
|
||||
def _msg_cb(self, ml, msg):
|
||||
self._msg_hdr(msg)
|
||||
|
||||
def _timed_msg(self, t_sec, msg):
|
||||
self._msg_hdr(msg)
|
||||
self.main_loop.set_alarm_in(t_sec, self._msg_cb, '')
|
||||
|
||||
def set_main(self, m):
|
||||
self.main_loop = m
|
||||
|
||||
# Contains OptionListWalker dict indexed by option
|
||||
# Contains ImpListBox
|
||||
@ -635,21 +656,22 @@ def gen_input_handler(cf_man, cf_dat, cf_viewer):
|
||||
raise urwid.ExitMainLoop()
|
||||
elif key == 'w':
|
||||
cf_dat.backup_files()
|
||||
cf_viewer._timed_msg(1, ': Saving file')
|
||||
cf_dat.write_config_file()
|
||||
elif key in ['right', 'tab']:
|
||||
if cf_viewer.get_focus() == cf_man.cfg_lb:
|
||||
cf_viewer.set_focus(cf_man.opt_lb)
|
||||
elif cf_viewer.get_focus() == cf_man.opt_lb:
|
||||
cf_viewer.set_focus(cf_man.imp_lb)
|
||||
if cf_viewer.cfg_pile.get_focus() == cf_man.cfg_lb:
|
||||
cf_viewer.cfg_pile.set_focus(cf_man.opt_lb)
|
||||
elif cf_viewer.cfg_pile.get_focus() == cf_man.opt_lb:
|
||||
cf_viewer.cfg_pile.set_focus(cf_man.imp_lb)
|
||||
else:
|
||||
cf_viewer.set_focus(cf_man.cfg_lb)
|
||||
cf_viewer.cfg_pile.set_focus(cf_man.cfg_lb)
|
||||
elif key in ['left', 'shift tab']:
|
||||
if cf_viewer.get_focus() == cf_man.cfg_lb:
|
||||
cf_viewer.set_focus(cf_man.imp_lb)
|
||||
elif cf_viewer.get_focus() == cf_man.opt_lb:
|
||||
cf_viewer.set_focus(cf_man.cfg_lb)
|
||||
if cf_viewer.cfg_pile.get_focus() == cf_man.cfg_lb:
|
||||
cf_viewer.cfg_pile.set_focus(cf_man.imp_lb)
|
||||
elif cf_viewer.cfg_pile.get_focus() == cf_man.opt_lb:
|
||||
cf_viewer.cfg_pile.set_focus(cf_man.cfg_lb)
|
||||
else:
|
||||
cf_viewer.set_focus(cf_man.opt_lb)
|
||||
cf_viewer.cfg_pile.set_focus(cf_man.opt_lb)
|
||||
|
||||
return keyinput
|
||||
|
||||
@ -669,7 +691,9 @@ def main(config_ini):
|
||||
cf_viewer = InstConfigView(cf_man.cfg_lb, cf_man.opt_lb, cf_man.imp_lb)
|
||||
|
||||
keyinput = gen_input_handler(cf_man, cf_dat, cf_viewer)
|
||||
urwid.MainLoop(cf_viewer, PALETTE, unhandled_input=keyinput).run()
|
||||
main_loop = urwid.MainLoop(cf_viewer, PALETTE, unhandled_input=keyinput)
|
||||
cf_viewer.set_main(main_loop)
|
||||
main_loop.run()
|
||||
return
|
||||
|
||||
if '__main__' == __name__:
|
||||
|
Reference in New Issue
Block a user