A bit of refactoring, a bit of housekeeping. Make Pylint happy. Mmmmm nice.
This commit is contained in:
@ -187,7 +187,7 @@ class InstConfigData(object):
|
|||||||
"""Handles reading and writing instrument configuration data and provides
|
"""Handles reading and writing instrument configuration data and provides
|
||||||
methods to change the configuration.
|
methods to change the configuration.
|
||||||
Attributes:
|
Attributes:
|
||||||
configuration_dict: Instrument configurations by configuration name.
|
config_dict: Instrument configurations by configuration name.
|
||||||
opt_dict: Configuration option descriptions indexed by option name.
|
opt_dict: Configuration option descriptions indexed by option name.
|
||||||
imp_dict: Implementations for indexed by option type.
|
imp_dict: Implementations for indexed by option type.
|
||||||
"""
|
"""
|
||||||
@ -197,9 +197,9 @@ class InstConfigData(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.file_parser = ConfigParser.SafeConfigParser()
|
self.file_parser = ConfigParser.SafeConfigParser()
|
||||||
self.config_filename = 'sics_config.ini'
|
self.config_filename = 'sics_config.ini'
|
||||||
#configuration_dict: dict of instrument configurations as defined below,
|
#config_dict: dict of instrument configurations as defined below,
|
||||||
# {configname: {'enabled':T/F, 'cascade_list':[(option, dflt_imp)]} }
|
# {configname: {'enabled':T/F, 'cascade_list':[(option, dflt_imp)]} }
|
||||||
self.configuration_dict = defaultdict(dict)
|
self.config_dict = defaultdict(dict)
|
||||||
|
|
||||||
#imp_dict: dict of implementations indexed by optype,
|
#imp_dict: dict of implementations indexed by optype,
|
||||||
# {optype: [impname] }
|
# {optype: [impname] }
|
||||||
@ -219,7 +219,7 @@ class InstConfigData(object):
|
|||||||
|
|
||||||
def __get_configurations(self):
|
def __get_configurations(self):
|
||||||
"""Parse instrument configuration definitions from INI file into
|
"""Parse instrument configuration definitions from INI file into
|
||||||
configuration_dict attribute of InstConfigData object
|
config_dict attribute of InstConfigData object
|
||||||
"""
|
"""
|
||||||
for sect in self.file_parser.sections():
|
for sect in self.file_parser.sections():
|
||||||
cascade_list = []
|
cascade_list = []
|
||||||
@ -238,8 +238,8 @@ class InstConfigData(object):
|
|||||||
else:
|
else:
|
||||||
stateval = False
|
stateval = False
|
||||||
|
|
||||||
self.configuration_dict[sect]['enabled'] = stateval
|
self.config_dict[sect]['enabled'] = stateval
|
||||||
self.configuration_dict[sect]['cascade_list'] = cascade_list
|
self.config_dict[sect]['cascade_list'] = cascade_list
|
||||||
|
|
||||||
def __get_options(self):
|
def __get_options(self):
|
||||||
"""Parse configuration options from INI file into opt_dict attribute of
|
"""Parse configuration options from INI file into opt_dict attribute of
|
||||||
@ -269,14 +269,17 @@ class InstConfigData(object):
|
|||||||
self.opt_dict[sect]['permanent'] = permanent
|
self.opt_dict[sect]['permanent'] = permanent
|
||||||
self.opt_dict[sect]['imptype'] = imptype
|
self.opt_dict[sect]['imptype'] = imptype
|
||||||
if stateval == True:
|
if stateval == True:
|
||||||
if selected_imp == 'none' or (selected_imp in self.imp2opt_dict) and self.imp2opt_dict[selected_imp] != 'none':
|
imp_unavailable = (selected_imp in self.imp2opt_dict) and (
|
||||||
|
self.imp2opt_dict[selected_imp] != 'none' )
|
||||||
|
if selected_imp == 'none' or imp_unavailable:
|
||||||
self.opt_dict[sect]['enabled'] = False
|
self.opt_dict[sect]['enabled'] = False
|
||||||
self.opt_dict[sect]['selected_imp'] = 'none'
|
self.opt_dict[sect]['selected_imp'] = 'none'
|
||||||
else:
|
else:
|
||||||
self.opt_dict[sect]['enabled'] = True
|
self.opt_dict[sect]['enabled'] = True
|
||||||
self.opt_dict[sect]['selected_imp'] = selected_imp
|
self.opt_dict[sect]['selected_imp'] = selected_imp
|
||||||
self.imp2opt_dict[selected_imp] = sect
|
self.imp2opt_dict[selected_imp] = sect
|
||||||
print 'Add imp2opt_dict[{0}] = {1}'.format(selected_imp, sect)
|
dbmsg = 'Add imp2opt_dict[{0}] = {1}'
|
||||||
|
print dbmsg.format(selected_imp, sect)
|
||||||
else:
|
else:
|
||||||
self.opt_dict[sect]['enabled'] = False
|
self.opt_dict[sect]['enabled'] = False
|
||||||
self.opt_dict[sect]['selected_imp'] = 'none'
|
self.opt_dict[sect]['selected_imp'] = 'none'
|
||||||
@ -287,10 +290,8 @@ class InstConfigData(object):
|
|||||||
"""
|
"""
|
||||||
for sect in self.file_parser.sections():
|
for sect in self.file_parser.sections():
|
||||||
if self.file_parser.has_option(sect, 'imptype'):
|
if self.file_parser.has_option(sect, 'imptype'):
|
||||||
key = self.file_parser.get(sect, 'imptype')
|
imptype = self.file_parser.get(sect, 'imptype')
|
||||||
self.imp_dict[key].append(sect)
|
self.imp_dict[imptype].append(sect)
|
||||||
if 'none' not in self.imp_dict[key]:
|
|
||||||
self.imp_dict[key].insert(0, 'none')
|
|
||||||
|
|
||||||
if sect not in self.imp2opt_dict:
|
if sect not in self.imp2opt_dict:
|
||||||
self.imp2opt_dict[sect] = 'none'
|
self.imp2opt_dict[sect] = 'none'
|
||||||
@ -307,6 +308,10 @@ class InstConfigData(object):
|
|||||||
for opt, opt_desc in self.opt_dict.iteritems():
|
for opt, opt_desc in self.opt_dict.iteritems():
|
||||||
self.optypelist.append((opt, opt_desc['imptype']))
|
self.optypelist.append((opt, opt_desc['imptype']))
|
||||||
|
|
||||||
|
for imptype in self.imp_dict.keys():
|
||||||
|
if 'none' not in self.imp_dict[imptype]:
|
||||||
|
self.imp_dict[imptype].insert(0, 'none')
|
||||||
|
|
||||||
def backup_files(self):
|
def backup_files(self):
|
||||||
""" Backup configuration files """
|
""" Backup configuration files """
|
||||||
for idx in range(8, 0, -1):
|
for idx in range(8, 0, -1):
|
||||||
@ -330,7 +335,7 @@ class InstConfigData(object):
|
|||||||
opt_desc['selected_imp'])
|
opt_desc['selected_imp'])
|
||||||
self.file_parser.set(opt, 'optype', opt_desc['imptype'])
|
self.file_parser.set(opt, 'optype', opt_desc['imptype'])
|
||||||
|
|
||||||
for config, config_desc in self.configuration_dict.iteritems():
|
for config, config_desc in self.config_dict.iteritems():
|
||||||
enabled = config_desc['enabled'].__str__()
|
enabled = config_desc['enabled'].__str__()
|
||||||
self.file_parser.set(config, 'enabled', enabled)
|
self.file_parser.set(config, 'enabled', enabled)
|
||||||
|
|
||||||
@ -368,7 +373,7 @@ class InstConfigData(object):
|
|||||||
|
|
||||||
def cf_statechange(self, cfg_id, new_state):
|
def cf_statechange(self, cfg_id, new_state):
|
||||||
"""Change the given instrument configuration state."""
|
"""Change the given instrument configuration state."""
|
||||||
self.configuration_dict[cfg_id]['enabled'] = new_state
|
self.config_dict[cfg_id]['enabled'] = new_state
|
||||||
|
|
||||||
def opt_statechange(self, opt, new_state):
|
def opt_statechange(self, opt, new_state):
|
||||||
"""Change the given option state."""
|
"""Change the given option state."""
|
||||||
@ -428,7 +433,7 @@ class InstConfigManager(object):
|
|||||||
self.imp_lb = ImpListBox(self.imp_lw)
|
self.imp_lb = ImpListBox(self.imp_lw)
|
||||||
urwid.connect_signal(self.opt_lw, 'focus_change', self.update_imp_lb)
|
urwid.connect_signal(self.opt_lw, 'focus_change', self.update_imp_lb)
|
||||||
item_states = [(i, d['enabled']) for i, d in
|
item_states = [(i, d['enabled']) for i, d in
|
||||||
cf_dat.configuration_dict.iteritems()]
|
cf_dat.config_dict.iteritems()]
|
||||||
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)
|
||||||
@ -488,7 +493,7 @@ class InstConfigManager(object):
|
|||||||
"""
|
"""
|
||||||
cfg_id = button.get_label()
|
cfg_id = button.get_label()
|
||||||
self.cf_dat.cf_statechange(cfg_id, new_state)
|
self.cf_dat.cf_statechange(cfg_id, new_state)
|
||||||
cascade = self.cf_dat.configuration_dict[cfg_id]['cascade_list']
|
cascade = self.cf_dat.config_dict[cfg_id]['cascade_list']
|
||||||
if new_state == True:
|
if new_state == True:
|
||||||
for opt in self.cf_dat.opt_dict.keys():
|
for opt in self.cf_dat.opt_dict.keys():
|
||||||
self.opt_lw.button_dict[opt].set_state(False)
|
self.opt_lw.button_dict[opt].set_state(False)
|
||||||
@ -503,7 +508,7 @@ class InstConfigManager(object):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def opt_statechange(self, button, new_state, udat=None):
|
def opt_statechange(self, button, new_state):
|
||||||
"""Update option label when it changes state and notify InstConfigData
|
"""Update option label when it changes state and notify InstConfigData
|
||||||
object.
|
object.
|
||||||
"""
|
"""
|
||||||
@ -541,7 +546,6 @@ class InstConfigManager(object):
|
|||||||
def update_imp_lb(self, pos):
|
def update_imp_lb(self, pos):
|
||||||
"""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]
|
|
||||||
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
|
||||||
@ -578,6 +582,7 @@ def gen_input_handler(cf_man, cf_dat, cf_viewer):
|
|||||||
|
|
||||||
def main(config_ini):
|
def main(config_ini):
|
||||||
"""Create configuration editor."""
|
"""Create configuration editor."""
|
||||||
|
# global cf_dat, cf_man, cf_viewer
|
||||||
|
|
||||||
# Make configuration data
|
# Make configuration data
|
||||||
cf_dat = InstConfigData()
|
cf_dat = InstConfigData()
|
||||||
|
Reference in New Issue
Block a user