Remove dependency of viewer on data and manager objects.
It just requires listboxes for the layout. Also use new style class definition for InstConfigData and InstConfigManager.
This commit is contained in:
@ -185,7 +185,7 @@ class ImpListBox(ClosedListBox):
|
||||
return
|
||||
|
||||
|
||||
class InstConfigData:
|
||||
class InstConfigData(object):
|
||||
|
||||
"""Handles reading and writing instrument configuration data and provides
|
||||
methods to change the configuration.
|
||||
@ -392,52 +392,29 @@ class InstConfigView(urwid.Pile):
|
||||
"""Extend urwid.Pile to provide an instrument configuration viewer.
|
||||
"""
|
||||
|
||||
def __init__(self, cf_dat, cf_man, dbmsg):
|
||||
def __init__(self, config_lb, opt_lb, imp_lb, dbmsg):
|
||||
"""
|
||||
Args:
|
||||
cf_dat: InstConfigData object.
|
||||
cf_man: InstConfigManager object.
|
||||
config_lb: Instrument configuration listbox
|
||||
opt_lb: Configuration options listbox
|
||||
imp_lb: Available implementations listbox
|
||||
"""
|
||||
self.cf_dat = cf_dat
|
||||
self.cf_man = cf_man
|
||||
option_listboxes = [
|
||||
self.cf_man.config_lb,
|
||||
self.cf_man.opt_lb,
|
||||
self.cf_man.imp_lb,
|
||||
config_lb,
|
||||
opt_lb,
|
||||
imp_lb,
|
||||
dbmsg]
|
||||
|
||||
super(InstConfigView, self).__init__(option_listboxes)
|
||||
return
|
||||
|
||||
def keyinput(self, key):
|
||||
"""Switch between lists, save data and quit on key input."""
|
||||
if key == 'meta q':
|
||||
raise urwid.ExitMainLoop()
|
||||
elif key == 'w':
|
||||
self.cf_dat.backup_files()
|
||||
self.cf_dat.write_config_file()
|
||||
elif key in ['right', 'tab']:
|
||||
if self.get_focus() == self.cf_man.config_lb:
|
||||
self.set_focus(self.cf_man.opt_lb)
|
||||
elif self.get_focus() == self.cf_man.opt_lb:
|
||||
self.set_focus(self.cf_man.imp_lb)
|
||||
else:
|
||||
self.set_focus(self.cf_man.config_lb)
|
||||
elif key in ['left', 'shift tab']:
|
||||
if self.get_focus() == self.cf_man.config_lb:
|
||||
self.set_focus(self.cf_man.imp_lb)
|
||||
elif self.get_focus() == self.cf_man.opt_lb:
|
||||
self.set_focus(self.cf_man.config_lb)
|
||||
else:
|
||||
self.set_focus(self.cf_man.opt_lb)
|
||||
|
||||
|
||||
# Contains OptionListWalker dict indexed by option
|
||||
# Contains ImpListBox
|
||||
# Connects OptionListWalker 'focus_change' signal to update_imp_lb handler
|
||||
# Tracks selected implementation for each option
|
||||
# and sets selection on ImpListBox
|
||||
class InstConfigManager:
|
||||
class InstConfigManager(object):
|
||||
|
||||
"""Provides controller which keeps data and viewer in sync.
|
||||
"""
|
||||
@ -575,6 +552,35 @@ class InstConfigManager:
|
||||
return
|
||||
|
||||
|
||||
def gen_input_handler(cf_man, cf_dat, cf_viewer):
|
||||
"""Generate keyinput handler with references to the controller object, the
|
||||
data object and the viewer object.
|
||||
"""
|
||||
def keyinput(key):
|
||||
"""Switch between lists, save data and quit on key input."""
|
||||
if key == 'meta q':
|
||||
raise urwid.ExitMainLoop()
|
||||
elif key == 'w':
|
||||
cf_dat.backup_files()
|
||||
cf_dat.write_config_file()
|
||||
elif key in ['right', 'tab']:
|
||||
if cf_viewer.get_focus() == cf_man.config_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)
|
||||
else:
|
||||
cf_viewer.set_focus(cf_man.config_lb)
|
||||
elif key in ['left', 'shift tab']:
|
||||
if cf_viewer.get_focus() == cf_man.config_lb:
|
||||
cf_viewer.set_focus(cf_man.imp_lb)
|
||||
elif cf_viewer.get_focus() == cf_man.opt_lb:
|
||||
cf_viewer.set_focus(cf_man.config_lb)
|
||||
else:
|
||||
cf_viewer.set_focus(cf_man.opt_lb)
|
||||
|
||||
return keyinput
|
||||
|
||||
|
||||
class DEBUG:
|
||||
"""DEBUG class"""
|
||||
msgTextDict = {}
|
||||
@ -609,8 +615,11 @@ def main(config_ini):
|
||||
cf_man = InstConfigManager(cf_dat)
|
||||
|
||||
# Make configuration viewer
|
||||
cf_viewer = InstConfigView(cf_dat, cf_man, DBG.mlb)
|
||||
urwid.MainLoop(cf_viewer, PALETTE, unhandled_input=cf_viewer.keyinput).run()
|
||||
cf_viewer = InstConfigView(cf_man.config_lb, cf_man.opt_lb, cf_man.imp_lb,
|
||||
DBG.mlb)
|
||||
|
||||
keyinput = gen_input_handler(cf_man, cf_dat, cf_viewer)
|
||||
urwid.MainLoop(cf_viewer, PALETTE, unhandled_input=keyinput).run()
|
||||
return
|
||||
|
||||
if '__main__' == __name__:
|
||||
|
Reference in New Issue
Block a user