Push GUI config setting changes to the engine process' Hooke.
[hooke.git] / hooke / ui / __init__.py
index 774a1511e10c2c4c3dc2665437b96feeb816c7b3..cfdac7293bbc07ceb28cafa9cadd6597c081b7e6 100644 (file)
 """
 
 import ConfigParser as configparser
+import logging
 
 from .. import version
 from ..config import Setting
+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__
@@ -87,6 +88,21 @@ class UserInterface (object):
         log.debug('executing %s' % 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)
+        response_handler(command_message=cm)
+
     def _splash_text(self, extra_info, **kwargs):
         return ("""
 Hooke version %s