X-Git-Url: http://git.tremily.us/?p=hooke.git;a=blobdiff_plain;f=hooke%2Fui%2F__init__.py;h=31fcae6fd9c859778b37c05819ef147235a22e91;hp=ad09e0236135c6b8fa0b91e0ede1f74e0c407dbc;hb=56725ab3fbcd43c517ea7ebbed17f951ae736db8;hpb=565f9d7b69d2e4a9ea447d7a50f8f835c3e08642 diff --git a/hooke/ui/__init__.py b/hooke/ui/__init__.py index ad09e02..31fcae6 100644 --- a/hooke/ui/__init__.py +++ b/hooke/ui/__init__.py @@ -20,12 +20,21 @@ """ import ConfigParser as configparser +import logging from .. import version -from ..license import short_license from ..config import Setting +from ..engine import CommandMessage from ..util.pluggable import IsSubclass, construct_odict +try: + from ..license import short_license +except ImportError, e: + logging.warn('could not load short_license from hooke.license') + from .. import __license__ + def short_license(extra_info, **kwargs): + return __license__ + USER_INTERFACE_MODULES = [ 'commandline', @@ -39,25 +48,6 @@ USER_INTERFACE_SETTING_SECTION = 'user interfaces' """ -class QueueMessage (object): - def __str__(self): - return self.__class__.__name__ - -class CloseEngine (QueueMessage): - pass - -class CommandMessage (QueueMessage): - """A message storing a command to run, `command` should be a - :class:`hooke.command.Command` instance, and `arguments` should be - a :class:`dict` with `argname` keys and `value` values to be - passed to the command. - """ - def __init__(self, command, arguments=None): - self.command = command - if arguments == None: - arguments = {} - self.arguments = arguments - class UserInterface (object): """A user interface to drive the :class:`hooke.engine.CommandEngine`. """ @@ -93,6 +83,33 @@ class UserInterface (object): # Assorted useful tidbits for subclasses + def _submit_command(self, command_message, ui_to_command_queue, + explicit_user_call=True): + log = logging.getLogger('hooke') + if explicit_user_call == True: + executor = 'user' + else: + executor = 'UI' + command_message.explicit_user_call = explicit_user_call + log.debug('executing (for the %s) %s' % (executor, command_message)) + ui_to_command_queue.put(command_message) + + def _set_config(self, option, value, ui_to_command_queue, response_handler, + section=None): + if section == None: + section = self.setting_section + if section in [self.setting_section, 'conditions']: + if self.config[option] == value: + return # No change, so no need to push the new value. + self.config[option] = value + cm = CommandMessage( + command='set config', + arguments={'section': section, 'option': option, 'value': value}) + self._submit_command(command_message=cm, + ui_to_command_queue=ui_to_command_queue, + explicit_user_call=False) + response_handler(command_message=cm) + def _splash_text(self, extra_info, **kwargs): return (""" Hooke version %s @@ -103,7 +120,7 @@ Hooke version %s def _playlist_status(self, playlist): if len(playlist) > 0: - return '%s (%s/%s)' % (playlist.name, playlist._index + 1, + return '%s (%s/%s)' % (playlist.name, playlist.index() + 1, len(playlist)) return 'The playlist %s does not contain any valid force curve data.' \ % self.name