Renamed type to optype in sics_config.ini so devices
like multimeters can set a data type parameter eg datype config_edit.py uses optype instead of type Also the listwalker is now being generated dynamically so that in the future unavailable drivers can be moved from the list of radiobuttons.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# vim: tabstop=8 softtabstop=2 shiftwidth=2 nocin si et ft=python
|
||||
|
||||
# View Screen has 3 parts
|
||||
# (SICS Configuration), (Configuration Components), (Component Implementation)
|
||||
# (Instrument Configuration), (Configuration Options), (Option Implementation)
|
||||
# Uses MVC implemented as InstConfigData<M>, InstConfigView<V>, ConfigEdit<C>
|
||||
#
|
||||
# InstConfigData <>--- ConfigParser.SafeConfig
|
||||
@@ -20,23 +20,6 @@
|
||||
# PresentationData
|
||||
# |--set_cfdata()
|
||||
|
||||
# TODO
|
||||
# cfgini = ConfigParser.SafeConfig()
|
||||
# cfgdata = InstConfigData()
|
||||
# DONE presentation = PresentationData()
|
||||
# cfgedit = ConfigEdit()
|
||||
# DONE cf_viewer = InstConfigView()
|
||||
|
||||
# config = ConfigParser.SafeConfig()
|
||||
# cfgdata.set_cfparse(config)
|
||||
# presentation.set_cfdata(cfgdata)
|
||||
# cfgedit.set_cfdata(cfgdata)
|
||||
# cfgedit.set_presdata(presentation)
|
||||
# cf_viewer.set_cfedit(cfgedit)
|
||||
# cf_viewer.set_presdata(presentation)
|
||||
#
|
||||
# cf_viewer calls self.cfgedit.set_xyz_data() methods on state change
|
||||
# cf_viewer
|
||||
|
||||
import os
|
||||
import argparse
|
||||
@@ -53,11 +36,11 @@ class InstConfigData:
|
||||
configuration_dict = defaultdict(dict)
|
||||
|
||||
# opt_dict: dict of configuration options as defined below,
|
||||
# {optname:{'enabled': T/F/Always, 'imptype':type, 'selected_imp':dflt}}
|
||||
# {optname:{'enabled': T/F/Always, 'imptype':optype, 'selected_imp':dflt}}
|
||||
opt_dict = defaultdict(dict)
|
||||
|
||||
# imp_dict: dict of implementations indexed by type,
|
||||
# {type: [impname] }
|
||||
# imp_dict: dict of implementations indexed by optype,
|
||||
# {optype: [impname] }
|
||||
imp_dict = defaultdict(list)
|
||||
|
||||
def __init__(self):
|
||||
@@ -74,6 +57,7 @@ class InstConfigData:
|
||||
stateval = True
|
||||
else:
|
||||
stateval = False
|
||||
|
||||
self.configuration_dict[s]['enabled'] = stateval
|
||||
self.configuration_dict[s]['cascade_list'] = cascade_list
|
||||
|
||||
@@ -81,7 +65,7 @@ class InstConfigData:
|
||||
for s in self.file_parser.sections():
|
||||
if self.file_parser.has_option(s, 'implementation'):
|
||||
selected_imp = self.file_parser.get(s, 'implementation')
|
||||
imptype = self.file_parser.get(s, 'type')
|
||||
imptype = self.file_parser.get(s, 'optype')
|
||||
enabled = self.file_parser.get(s, 'enabled').lower()
|
||||
if enabled == 'always':
|
||||
stateval = True
|
||||
@@ -120,7 +104,6 @@ class InstConfigData:
|
||||
self.config_filename + "." + str(idx + 1))
|
||||
if os.path.exists(self.config_filename):
|
||||
os.rename(self.config_filename, self.config_filename + ".1")
|
||||
return
|
||||
|
||||
def write_config_file(self):
|
||||
for item,dict in self.opt_dict.iteritems():
|
||||
@@ -130,7 +113,7 @@ class InstConfigData:
|
||||
enabled = dict['enabled'].__str__()
|
||||
self.file_parser.set(item, 'enabled', enabled)
|
||||
self.file_parser.set(item, 'implementation', dict['selected_imp'])
|
||||
self.file_parser.set(item, 'type', dict['imptype'])
|
||||
self.file_parser.set(item, 'optype', dict['imptype'])
|
||||
for item,dict in self.configuration_dict.iteritems():
|
||||
enabled = dict['enabled'].__str__()
|
||||
self.file_parser.set(item, 'enabled', enabled)
|
||||
@@ -248,28 +231,23 @@ class InstConfigManager:
|
||||
urwid.register_signal(InstConfigManager, ['focus_change'])
|
||||
for opt,dict in cfdat.opt_dict.iteritems():
|
||||
self.options.append((opt, dict['imptype']))
|
||||
imp_items = []
|
||||
for imp in cfdat.imp_dict[dict['imptype']]:
|
||||
if imp == dict['selected_imp']:
|
||||
imp_items.append((imp, True))
|
||||
else:
|
||||
imp_items.append((imp, False))
|
||||
# imp_items = []
|
||||
# for imp in cfdat.imp_dict[dict['imptype']]:
|
||||
# if imp == dict['selected_imp']:
|
||||
# imp_items.append((imp, True))
|
||||
# else:
|
||||
# imp_items.append((imp, False))
|
||||
|
||||
imp_items.sort()
|
||||
self.imp_lw_dict[opt] = RadioButtonListWalker(imp_items, on_state_change=self.imp_statechange, user_data=opt)
|
||||
# imp_items.sort()
|
||||
# self.imp_lw_dict[opt] = RadioButtonListWalker(imp_items, on_state_change=self.imp_statechange, user_data=opt)
|
||||
|
||||
self.options.sort()
|
||||
# ffr Make a sacrificail listwalker imp_lw because copy.copy()
|
||||
# doesn't work for urwid on the SL6 VMs
|
||||
# imp_items.sort()
|
||||
firstopt = self.options[0][0]
|
||||
for opt,dict in cfdat.opt_dict.iteritems():
|
||||
self.options.append((opt, dict['imptype']))
|
||||
imp_items = []
|
||||
|
||||
imp_items.sort()
|
||||
imp_lw = RadioButtonListWalker(imp_items, on_state_change=self.imp_statechange, user_data=firstopt)
|
||||
self.imp_lw = self.__gen_imp_listwalker(firstopt)
|
||||
# self.imp_lw = RadioButtonListWalker([], on_state_change=self.imp_statechange, user_data=firstopt)
|
||||
self.option_lw = OptionListWalker(cfdat.opt_dict, self.opt_statechange)
|
||||
self.imp_lb = ImpListBox(imp_lw)
|
||||
self.imp_lb = ImpListBox(self.imp_lw)
|
||||
urwid.connect_signal(self.option_lw, 'focus_change', self.update_imp_lb)
|
||||
|
||||
item_states = [(i,d['enabled']) for i,d in cf_dat.configuration_dict.iteritems()]
|
||||
@@ -277,8 +255,23 @@ class InstConfigManager:
|
||||
self.cfg_lw = RadioButtonListWalker(item_states, on_state_change = self.cf_statechange)
|
||||
self.config_lb = OptionListBox(self.cfg_lw)
|
||||
self.opt_lb = OptionListBox(self.option_lw)
|
||||
self.opt_lb.set_focus(0)
|
||||
return
|
||||
|
||||
def __gen_imp_listwalker(self, opt):
|
||||
imp_items = []
|
||||
dict = self.cfdat.opt_dict[opt]
|
||||
for imp in self.cfdat.imp_dict[dict['imptype']]:
|
||||
if imp == dict['selected_imp']:
|
||||
imp_items.append((imp, True))
|
||||
else:
|
||||
imp_items.append((imp, False))
|
||||
|
||||
imp_items.sort()
|
||||
|
||||
return RadioButtonListWalker(imp_items, on_state_change=self.imp_statechange, user_data=opt)
|
||||
|
||||
|
||||
def cf_statechange(self, button, new_state, udat=None):
|
||||
self.cfdat.cf_statechange(button, new_state, udat)
|
||||
b = button.get_label()
|
||||
@@ -289,7 +282,10 @@ class InstConfigManager:
|
||||
self.option_lw.button_dict[opt].set_state(False)
|
||||
for opt,imp in cascade:
|
||||
self.option_lw.button_dict[opt].set_state(True)
|
||||
self.imp_lw_dict[opt].button_dict[imp].set_state(True)
|
||||
imp_lw = self.__gen_imp_listwalker(opt)
|
||||
imp_lw.button_dict[imp].set_state(True)
|
||||
currpos = self.opt_lb.get_focus()[1]
|
||||
self.opt_lb.set_focus(currpos)
|
||||
|
||||
dbg.msg(self.cf_msg_index, 'InstConfigManager:cf_statechange({0},{1},{2}), cascade = {3}'.format(b, new_state, udat, cascade))
|
||||
self.cf_msg_index = (self.cf_msg_index - 7) % 2 + 8
|
||||
@@ -305,10 +301,11 @@ class InstConfigManager:
|
||||
|
||||
def update_imp_lb(self, pos):
|
||||
optname = self.options[pos][0]
|
||||
type = self.options[pos][1]
|
||||
mstr = 'InstConfigManager:update_imp_lb({0}) -> select {1}'.format(pos, type)
|
||||
optype = self.options[pos][1]
|
||||
mstr = 'InstConfigManager:update_imp_lb({0}) -> select {1}'.format(pos, optype)
|
||||
dbg.msg(1, mstr)
|
||||
self.imp_lb.use_listwalker(self.imp_lw_dict[optname])
|
||||
self.imp_lw = self.__gen_imp_listwalker(optname)
|
||||
self.imp_lb.use_listwalker(self.imp_lw)
|
||||
return
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user