import ConfigParser as configparser
from .. import version
-from ..compat.odict import odict
from ..config import Setting
-from ..util.pluggable import IsSubclass
+from ..util.pluggable import IsSubclass, construct_odict
USER_INTERFACE_MODULES = [
'commandline',
- #'gui',
+ 'gui',
]
"""List of user interface modules. TODO: autodiscovery
"""
a :class:`dict` with `argname` keys and `value` values to be
passed to the command.
"""
- def __init__(self, command, arguments):
+ def __init__(self, command, arguments=None):
self.command = command
+ if arguments == None:
+ arguments = {}
self.arguments = arguments
class UserInterface (object):
"""Update the user interface for new config settings.
Should be called with the new `config` upon recipt of
- `ReloadUserInterfaceConfig` from the `CommandEngine`.
+ `ReloadUserInterfaceConfig` from the `CommandEngine` or when
+ loading the initial configuration.
"""
try:
self.config = dict(config.items(self.setting_section))
except configparser.NoSectionError:
self.config = {}
- def run(self, hooke, ui_to_command_queue, command_to_ui_queue):
+ def run(self, commands, ui_to_command_queue, command_to_ui_queue):
return
# Assorted useful tidbits for subclasses
return 'The playlist %s does not contain any valid force curve data.' \
% self.name
-def construct_odict(this_modname, submodnames, class_selector):
- """Search the submodules `submodnames` of a module `this_modname`
- for class objects for which `class_selector(class)` returns
- `True`. These classes are instantiated and stored in the returned
- :class:`hooke.compat.odict.odict` in the order in which they were
- discovered.
- """
- instances = odict()
- for submodname in submodnames:
- count = len([s for s in submodnames if s == submodname])
- assert count > 0, 'No %s entries: %s' % (submodname, submodnames)
- assert count == 1, 'Multiple (%d) %s entries: %s' \
- % (count, submodname, submodnames)
- this_mod = __import__(this_modname, fromlist=[submodname])
- submod = getattr(this_mod, submodname)
- for objname in dir(submod):
- obj = getattr(submod, objname)
- if class_selector(obj):
- instance = obj()
- instances[instance.name] = instance
- return instances
USER_INTERFACES = construct_odict(
this_modname=__name__,
assert len(uis) == 1, 'Can only select one UI, not %d: %s' % (len(uis),uis)
name = uis[0]
ui = USER_INTERFACES[name]
- try:
- ui.config = dict(config.items(ui.setting_section))
- except configparser.NoSectionError:
- pass
+ ui.reload_config(config)
return ui