Ran update-copyright.py
[hooke.git] / hooke / ui / __init__.py
index 1b939144b6f2c1c1f693bca8088891507661e982..ec30d2583cf9c7128fda3ef5f538ad4eb2b96262 100644 (file)
@@ -1,36 +1,35 @@
-# Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2012 W. Trevor King <wking@tremily.us>
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
 #
-# Hooke is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
-# Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
 #
-# You should have received a copy of the GNU Lesser General Public
-# License along with Hooke.  If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
 
 """The `ui` module provides :class:`UserInterface` and various subclasses.
 """
 
 import ConfigParser as configparser
+import logging
 
 from .. import version
 from ..config import Setting
-from ..engine import CloseEngine, CommandMessage
+from ..engine import CommandMessage
 from ..util.pluggable import IsSubclass, construct_odict
 
 try:
     from ..license import short_license
 except ImportError, e:
-    import logging
-    logging.warn('Could not load short_license from hooke.license')
+    logging.warn('could not load short_license from hooke.license')
     from .. import __license__
     def short_license(extra_info, **kwargs):
         return __license__
@@ -83,6 +82,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