Remove debug output and cleanup a bit.
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
# View Screen has 3 parts
|
# View Screen has 3 parts
|
||||||
# (Instrument Configuration), (Configuration Options), (Option Implementation)
|
# (Instrument Configuration), (Configuration Options), (Option Implementation)
|
||||||
# Uses MVC as InstConfigData<M>, InstConfigView<V>, InstConfigManager<C>
|
# Uses MVC as InstConfigData<M>, InstConfigView<V>, InstConfigManager<C>
|
||||||
#
|
|
||||||
# InstConfigData <>--- ConfigParser.SafeConfig
|
# InstConfigData <>--- ConfigParser.SafeConfig
|
||||||
# |--set_cfparse()
|
# |--set_cfparse()
|
||||||
|
|
||||||
@ -14,13 +14,12 @@
|
|||||||
# |--set_cfdata(), set_presdata()
|
# |--set_cfdata(), set_presdata()
|
||||||
# |--set_xyz_data() call self.cfgdata.set_xyz() methods
|
# |--set_xyz_data() call self.cfgdata.set_xyz() methods
|
||||||
#
|
#
|
||||||
# urwid.Frame
|
|
||||||
|
# urwid.Pile
|
||||||
# ^
|
# ^
|
||||||
|
# |
|
||||||
# InstConfigView <>--- InstConfigManager, PresentationData
|
# InstConfigView <>--- InstConfigManager, PresentationData
|
||||||
# |--set_cfedit(), set_presdata()
|
# |--set_cfedit(), set_presdata()
|
||||||
#
|
|
||||||
# PresentationData
|
|
||||||
# |--set_cfdata()
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -131,8 +130,6 @@ class OptionListWalker(CheckBoxListWalker):
|
|||||||
def set_focus(self, pos):
|
def set_focus(self, pos):
|
||||||
"""Emit 'focus_change' signal with position of button.
|
"""Emit 'focus_change' signal with position of button.
|
||||||
"""
|
"""
|
||||||
DBG.msg(0,
|
|
||||||
'OptionListWalker:set_focus({0})->emit focus_change'.format(pos))
|
|
||||||
urwid.emit_signal(self, 'focus_change', pos)
|
urwid.emit_signal(self, 'focus_change', pos)
|
||||||
return super(OptionListWalker, self).set_focus(pos)
|
return super(OptionListWalker, self).set_focus(pos)
|
||||||
|
|
||||||
@ -370,18 +367,12 @@ class InstConfigData(object):
|
|||||||
"""Change the given instrument configuration state."""
|
"""Change the given instrument configuration state."""
|
||||||
self.configuration_dict[cfg_id]['enabled'] = new_state
|
self.configuration_dict[cfg_id]['enabled'] = new_state
|
||||||
|
|
||||||
def opt_statechange(self, opt, new_state, udat=None):
|
def opt_statechange(self, opt, new_state):
|
||||||
"""Change the given option state."""
|
"""Change the given option state."""
|
||||||
DBG.msg(3,
|
|
||||||
'InstConfigData:opt_statechange({0},{1},{2})'.format(opt,
|
|
||||||
new_state, udat))
|
|
||||||
self.opt_dict[opt]['enabled'] = new_state
|
self.opt_dict[opt]['enabled'] = new_state
|
||||||
|
|
||||||
def imp_statechange(self, selected_imp, new_state, opt):
|
def imp_statechange(self, selected_imp, new_state, opt):
|
||||||
"""Change the given implementation state."""
|
"""Change the given implementation state."""
|
||||||
DBG.msg(self.msg_index,
|
|
||||||
'InstConfigData:imp_statechange({0},{1},{2})'.format(selected_imp,
|
|
||||||
new_state, opt))
|
|
||||||
self.msg_index = (self.msg_index - 3) % 2 + 4
|
self.msg_index = (self.msg_index - 3) % 2 + 4
|
||||||
if new_state == True:
|
if new_state == True:
|
||||||
self.opt_dict[opt]['selected_imp'] = selected_imp
|
self.opt_dict[opt]['selected_imp'] = selected_imp
|
||||||
@ -392,18 +383,17 @@ class InstConfigView(urwid.Pile):
|
|||||||
"""Extend urwid.Pile to provide an instrument configuration viewer.
|
"""Extend urwid.Pile to provide an instrument configuration viewer.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config_lb, opt_lb, imp_lb, dbmsg):
|
def __init__(self, cfg_lb, opt_lb, imp_lb):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
config_lb: Instrument configuration listbox
|
cfg_lb: Instrument configuration listbox
|
||||||
opt_lb: Configuration options listbox
|
opt_lb: Configuration options listbox
|
||||||
imp_lb: Available implementations listbox
|
imp_lb: Available implementations listbox
|
||||||
"""
|
"""
|
||||||
option_listboxes = [
|
option_listboxes = [
|
||||||
config_lb,
|
cfg_lb,
|
||||||
opt_lb,
|
opt_lb,
|
||||||
imp_lb,
|
imp_lb]
|
||||||
dbmsg]
|
|
||||||
|
|
||||||
super(InstConfigView, self).__init__(option_listboxes)
|
super(InstConfigView, self).__init__(option_listboxes)
|
||||||
return
|
return
|
||||||
@ -419,7 +409,6 @@ class InstConfigManager(object):
|
|||||||
"""Provides controller which keeps data and viewer in sync.
|
"""Provides controller which keeps data and viewer in sync.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cf_msg_index = 8
|
|
||||||
def __init__(self, cf_dat):
|
def __init__(self, cf_dat):
|
||||||
self.cf_dat = cf_dat
|
self.cf_dat = cf_dat
|
||||||
urwid.register_signal(InstConfigManager, ['focus_change'])
|
urwid.register_signal(InstConfigManager, ['focus_change'])
|
||||||
@ -440,7 +429,7 @@ class InstConfigManager(object):
|
|||||||
item_states.sort()
|
item_states.sort()
|
||||||
self.cfg_lw = RadioButtonListWalker(item_states, on_state_change =
|
self.cfg_lw = RadioButtonListWalker(item_states, on_state_change =
|
||||||
self.cf_statechange)
|
self.cf_statechange)
|
||||||
self.config_lb = OptionListBox(self.cfg_lw)
|
self.cfg_lb = OptionListBox(self.cfg_lw)
|
||||||
self.opt_lb = OptionListBox(self.opt_lw)
|
self.opt_lb = OptionListBox(self.opt_lw)
|
||||||
self.opt_lb.set_focus(0)
|
self.opt_lb.set_focus(0)
|
||||||
return
|
return
|
||||||
@ -509,10 +498,6 @@ class InstConfigManager(object):
|
|||||||
if self.cf_dat.opt_dict[opt]['permanent'] == True:
|
if self.cf_dat.opt_dict[opt]['permanent'] == True:
|
||||||
self.opt_lw.button_dict[opt].set_state(True)
|
self.opt_lw.button_dict[opt].set_state(True)
|
||||||
|
|
||||||
DBG.msg(self.cf_msg_index,
|
|
||||||
'InstConfigManager:cf_statechange({0},{1}):cascade={2}'.format(
|
|
||||||
cfg_id, new_state, cascade))
|
|
||||||
self.cf_msg_index = (self.cf_msg_index - 7) % 2 + 8
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def opt_statechange(self, button, new_state, udat=None):
|
def opt_statechange(self, button, new_state, udat=None):
|
||||||
@ -535,7 +520,7 @@ class InstConfigManager(object):
|
|||||||
opt_button.set_label('{0}:{1}'.format(opt, imp))
|
opt_button.set_label('{0}:{1}'.format(opt, imp))
|
||||||
self.cf_dat.set_imp(opt, imp)
|
self.cf_dat.set_imp(opt, imp)
|
||||||
|
|
||||||
self.cf_dat.opt_statechange(opt, new_state, udat)
|
self.cf_dat.opt_statechange(opt, new_state)
|
||||||
|
|
||||||
def imp_statechange(self, button, new_state, opt):
|
def imp_statechange(self, button, new_state, opt):
|
||||||
"""Update label on the configuration option when it's implementation is
|
"""Update label on the configuration option when it's implementation is
|
||||||
@ -554,9 +539,6 @@ class InstConfigManager(object):
|
|||||||
"""Update implementation list when an option gets focus."""
|
"""Update implementation list when an option gets focus."""
|
||||||
optname = self.opt_optype_list[pos][0]
|
optname = self.opt_optype_list[pos][0]
|
||||||
optype = self.opt_optype_list[pos][1]
|
optype = self.opt_optype_list[pos][1]
|
||||||
mstr = 'InstConfigManager:update_imp_lb({0})->select{1}'.format(pos,
|
|
||||||
optype)
|
|
||||||
DBG.msg(1, mstr)
|
|
||||||
self.imp_lw = self.__gen_imp_listwalker(optname)
|
self.imp_lw = self.__gen_imp_listwalker(optname)
|
||||||
self.imp_lb.use_listwalker(self.imp_lw)
|
self.imp_lb.use_listwalker(self.imp_lw)
|
||||||
return
|
return
|
||||||
@ -574,48 +556,24 @@ def gen_input_handler(cf_man, cf_dat, cf_viewer):
|
|||||||
cf_dat.backup_files()
|
cf_dat.backup_files()
|
||||||
cf_dat.write_config_file()
|
cf_dat.write_config_file()
|
||||||
elif key in ['right', 'tab']:
|
elif key in ['right', 'tab']:
|
||||||
if cf_viewer.get_focus() == cf_man.config_lb:
|
if cf_viewer.get_focus() == cf_man.cfg_lb:
|
||||||
cf_viewer.set_focus(cf_man.opt_lb)
|
cf_viewer.set_focus(cf_man.opt_lb)
|
||||||
elif cf_viewer.get_focus() == cf_man.opt_lb:
|
elif cf_viewer.get_focus() == cf_man.opt_lb:
|
||||||
cf_viewer.set_focus(cf_man.imp_lb)
|
cf_viewer.set_focus(cf_man.imp_lb)
|
||||||
else:
|
else:
|
||||||
cf_viewer.set_focus(cf_man.config_lb)
|
cf_viewer.set_focus(cf_man.cfg_lb)
|
||||||
elif key in ['left', 'shift tab']:
|
elif key in ['left', 'shift tab']:
|
||||||
if cf_viewer.get_focus() == cf_man.config_lb:
|
if cf_viewer.get_focus() == cf_man.cfg_lb:
|
||||||
cf_viewer.set_focus(cf_man.imp_lb)
|
cf_viewer.set_focus(cf_man.imp_lb)
|
||||||
elif cf_viewer.get_focus() == cf_man.opt_lb:
|
elif cf_viewer.get_focus() == cf_man.opt_lb:
|
||||||
cf_viewer.set_focus(cf_man.config_lb)
|
cf_viewer.set_focus(cf_man.cfg_lb)
|
||||||
else:
|
else:
|
||||||
cf_viewer.set_focus(cf_man.opt_lb)
|
cf_viewer.set_focus(cf_man.opt_lb)
|
||||||
|
|
||||||
return keyinput
|
return keyinput
|
||||||
|
|
||||||
|
|
||||||
class DEBUG:
|
|
||||||
"""DEBUG class"""
|
|
||||||
msgTextDict = {}
|
|
||||||
msglist = []
|
|
||||||
msg_ids = [ 'm0', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9' ]
|
|
||||||
def __init__(self, enabled=False):
|
|
||||||
self.enabled = enabled
|
|
||||||
if enabled:
|
|
||||||
for msg_id in self.msg_ids:
|
|
||||||
msg_text = urwid.Text(u'Space for message {0}'.format(msg_id))
|
|
||||||
self.msgTextDict[msg_id] = msg_text
|
|
||||||
self.msglist.append(urwid.AttrMap(msg_text, 'body', 'focus'))
|
|
||||||
|
|
||||||
mlw = urwid.SimpleListWalker(self.msglist)
|
|
||||||
self.mlb = urwid.ListBox(mlw)
|
|
||||||
|
|
||||||
def msg(self, index, msg):
|
|
||||||
"""Debug message."""
|
|
||||||
if self.enabled:
|
|
||||||
mid = self.msg_ids[index]
|
|
||||||
self.msgTextDict[mid].set_text(msg)
|
|
||||||
|
|
||||||
DBG = DEBUG(enabled=True)
|
|
||||||
def main(config_ini):
|
def main(config_ini):
|
||||||
global cf_dat, cf_man, cf_viewer
|
|
||||||
"""Create configuration editor."""
|
"""Create configuration editor."""
|
||||||
|
|
||||||
# Make configuration data
|
# Make configuration data
|
||||||
@ -626,8 +584,7 @@ def main(config_ini):
|
|||||||
cf_man = InstConfigManager(cf_dat)
|
cf_man = InstConfigManager(cf_dat)
|
||||||
|
|
||||||
# Make configuration viewer
|
# Make configuration viewer
|
||||||
cf_viewer = InstConfigView(cf_man.config_lb, cf_man.opt_lb, cf_man.imp_lb,
|
cf_viewer = InstConfigView(cf_man.cfg_lb, cf_man.opt_lb, cf_man.imp_lb)
|
||||||
DBG.mlb)
|
|
||||||
|
|
||||||
keyinput = gen_input_handler(cf_man, cf_dat, cf_viewer)
|
keyinput = gen_input_handler(cf_man, cf_dat, cf_viewer)
|
||||||
urwid.MainLoop(cf_viewer, PALETTE, unhandled_input=keyinput).run()
|
urwid.MainLoop(cf_viewer, PALETTE, unhandled_input=keyinput).run()
|
||||||
|
Reference in New Issue
Block a user