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:
Ferdi Franceschini
2014-07-02 08:50:17 +10:00
parent 89edcef811
commit 87bf34c7b1
2 changed files with 136 additions and 166 deletions

View File

@@ -1,239 +1,212 @@
[12tmagnet]
[12tmagnet_oxford]
desc = "12 Tesla Oxford Magnet"
driver = "12tmagnet"
group = implementation
id = 11
ip = 10.157.205.3
name = magnetic
port = 55001
type = B
driver = "oxford_labview"
imptype = magnetic_field
ip = 10.157.205.3
port = 55001
[12tmagnet_sample_insert]
desc = "som will be redefined as the magnet sample insert rotation. Sample stage will be renamed to somss"
group = implementation
offifon = normal_sample_stage,eularian_cradle,small_omega
radio = samstage
imptype = motion_axis
[Default]
cascade = sample_stage:normal_sample_stage
enabled = True
group = Configuration
[12tmagnet_setup]
cascade = B1:12tmagnet,sample_stage:12tmagnet_sample_insert,T1:mercury_scpi
enabled = True
group = Configuration
onifoff = normal_sample_stage
cascade = B1:12tmagnet_oxford,sample_stage:12tmagnet_sample_insert,T1:mercury_scpi
enabled = False
[B1]
enabled = False
implementation = 12tmagnet_oxford
name = magnet1
optype = magnetic_field
[CF1]
cascade = T1:CF1_ls340,sample_stage:normal_sample_stage
enabled = False
group = Configuration
[T1]
name = tc1
enabled = True
group = Configuration Components
implementation = mercury_scpi
type = temperature
[T2]
name = tc2
enabled = False
group = Configuration Components
implementation = ls336_02
type = temperature
[T3]
name = tc3
enabled = False
group = Configuration Components
implementation = ls336_04
type = temperature
[B1]
name = magnet1
enabled = True
group = Configuration Components
implementation = 12tmagnet
type = magnetic_field
[sample_stage]
name = sample_stage
enabled = Always
group = Configuration Components
implementation = 12tmagnet_sample_insert
type = motion_axis
[CF1_ls340]
desc = "cf1: Bottom loading cryofurnace"
driver = "lakeshore_340"
group = implementation
id = 12
imptype = temperature
ip = 10.157.205.43
name = cf1
port = 4001
terminator = \r\n
tol1 = 1.0
tol2 = 1.0
type = T
imptype = temperature
[Default]
cascade = sample_stage:normal_sample_stage
enabled = True
[I1]
datype = I
enabled = False
implementation = protek_01
name = curr1
optype = multimeter
[I2]
datype = I
enabled = False
implementation = protek_02
name = curr2
optype = multimeter
[T1]
enabled = False
implementation = mercury_scpi
name = tc1
optype = temperature
[T2]
enabled = False
implementation = ls336_02
name = tc2
optype = temperature
[T3]
enabled = False
implementation = ls336_04
name = tc3
optype = temperature
[V1]
datype = V
enabled = False
implementation = protek_01
name = volts1
optype = multimeter
[V2]
datype = V
enabled = False
implementation = protek_02
name = volts2
optype = multimeter
[eularian_cradle]
desc = "Load the Eulerian cradle configuration"
group = implementation
offifon = normal_sample_stage,small_omega,12tmagnet_sample_insert
radio = samstage
imptype = motion_axis
[ls336_01]
desc = "tc1: Lakeshore 336 temperature controller"
driver = "lakeshore_336"
group = implementation
id = 1
imptype = temperature
ip = 10.157.205.28
name = tc1
port = 7777
terminator = \r\n
tol1 = 1.0
tol2 = 1.0
type = T
imptype = temperature
[ls336_02]
desc = "tc2: Lakeshore 336 temperature controller"
driver = "lakeshore_336"
group = implementation
id = 2
imptype = temperature
ip = 10.157.205.29
name = tc2
port = 7777
terminator = \r\n
tol1 = 1.0
tol2 = 1.0
type = T
imptype = temperature
[ls336_04]
desc = "tc3: Lakeshore 336 temperature controller"
driver = "lakeshore_336"
group = implementation
id = 3
imptype = temperature
ip = 10.157.205.30
name = tc3
port = 7777
terminator = \r\n
tol1 = 1.0
tol2 = 1.0
type = T
imptype = temperature
[ls336_05]
desc = "tc4: Lakeshore 336 temperature controller"
driver = "lakeshore_336"
group = implementation
id = 4
imptype = temperature
ip = 137.157.201.21
name = tc4
port = 7777
terminator = \r\n
tol1 = 1.0
tol2 = 1.0
type = T
imptype = temperature
[ls336_06]
desc = "tc5: Lakeshore 336 temperature controller"
driver = "lakeshore_336"
group = implementation
id = 5
imptype = temperature
ip = 137.157.201.21
name = tc5
port = 7777
terminator = \r\n
tol1 = 1.0
tol2 = 1.0
type = T
imptype = temperature
[ls336_12]
desc = "tc6: Lakeshore 336 temperature controller"
driver = "lakeshore_336"
group = implementation
id = 6
imptype = temperature
ip = 10.157.205.31
name = tc6
port = 7777
terminator = \r\n
tol1 = 1.0
tol2 = 1.0
type = T
imptype = temperature
[ls340_01]
desc = "tc7: Lakeshore 340 temperature controller"
group = implementation
driver = "lakeshore_340"
id = 7
imptype = temperature
ip = 137.157.201.86
name = tc7
port = 4001
terminator = \r\n
tol1 = 1.0
tol2 = 1.0
type = T
imptype = temperature
[ls340_02]
desc = "tc8: Lakeshore 340 temperature controller"
group = implementation
driver = "lakeshore_340"
id = 8
imptype = temperature
ip = 137.157.201.86
name = tc8
port = 4002
terminator = \r\n
tol1 = 1.0
tol2 = 1.0
type = T
imptype = temperature
[mercury_scpi]
desc = "tc9: Oxford Mercury temperature controller in Mercury mode"
driver = "mercury_scpi"
group = implementation
id = 9
imptype = temperature
ip = 10.157.205.5
name = tc9
port = 7020
terminator = \r
tol = 2.0
type = T
imptype = temperature
[normal_sample_stage]
desc = "This is the default sample stage configuration with xy translation and phi and chi tilt stages"
group = implementation
offifon = eularian_cradle,small_omega,12tmagnet_sample_insert
radio = samstage
imptype = motion_axis
[protek_01]
desc = "Protek Multimeter"
driver = "protek"
imptype = multimeter
ip = 10.157.205.36
port = 4001
[protek_02]
desc = "Protek Multimeter"
driver = "protek"
imptype = multimeter
ip = 10.157.205.37
port = 4001
[sample_stage]
enabled = Always
implementation = normal_sample_stage
name = sample_stage
optype = motion_axis
[small_omega]
desc = "Load the small omega configuration"
group = implementation
offifon = normal_sample_stage,eularian_cradle,12tmagnet_sample_insert
radio = samstage
imptype = motion_axis
[west4100]
desc = "tc10: Blue furnace temperature controller"
desc = "Blue furnace temperature controller"
driver = "west4100"
group = implementation
id = 10
ip = 10.157.205.19
name = tc10
type = T
imptype = temperature
ip = 10.157.205.19

View File

@@ -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