Push GUI config setting changes to the engine process' Hooke.
authorW. Trevor King <wking@drexel.edu>
Fri, 20 Aug 2010 07:45:00 +0000 (03:45 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 20 Aug 2010 07:45:00 +0000 (03:45 -0400)
doc/gui.txt
hooke/ui/__init__.py
hooke/ui/gui/__init__.py
hooke/ui/gui/dialog/save_file.py

index 4ae9488f81e2b0f2de3f6665e229885c2a2a3c25..28e9cb835b6a6413a4304c1aa0bbaa0b93a9bebf 100644 (file)
@@ -152,8 +152,6 @@ Hooke's GUI will remember the size and position of the main window
 panels any which way you like and save this arrangement as a
 perspective.
 
-.. todo:: Actually write new properties to the config file on GUI exit.
-
 .. image:: img/gui_perspective.jpg
 
 Hooke will always start with the last used perspective and you can
index 02e91513238b299d65790799a96bff330b9d4104..cfdac7293bbc07ceb28cafa9cadd6597c081b7e6 100644 (file)
@@ -24,6 +24,7 @@ import logging
 
 from .. import version
 from ..config import Setting
+from ..engine import CommandMessage
 from ..util.pluggable import IsSubclass, construct_odict
 
 try:
@@ -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
index 034003b7d5278539d417b1dcddf19c06f7a3de20..73620101ee4fc526f51d779b428d75deda5a1959 100644 (file)
@@ -269,11 +269,10 @@ class HookeFrame (wx.Frame):
     def _on_close(self, *args):
         self.log.info('closing GUI framework')
         # apply changes
-        self.gui.config['main height'] = str(self.GetSize().GetHeight())
-        self.gui.config['main left'] = str(self.GetPosition()[0])
-        self.gui.config['main top'] = str(self.GetPosition()[1])
-        self.gui.config['main width'] = str(self.GetSize().GetWidth())
-        # push changes back to Hooke.config?
+        self._set_config('main height', self.GetSize().GetHeight())
+        self._set_config('main left', self.GetPosition()[0])
+        self._set_config('main top', self.GetPosition()[1])
+        self._set_config('main width', self.GetSize().GetWidth())
         self._c['manager'].UnInit()
         del self._c['manager']
         self.Destroy()
@@ -306,7 +305,7 @@ class HookeFrame (wx.Frame):
         if args == None:
             args = {}
         if ('property editor' in self._c
-            and self.gui.config['selected command'] == command):
+            and self.gui.config['selected command'] == command.name):
             for name,value in self._c['property editor'].get_values().items():
                 arg = self._c['property editor']._argument_from_label.get(
                     name, None)
@@ -339,6 +338,9 @@ class HookeFrame (wx.Frame):
                         args[arg.name] = arg.default
         cm = CommandMessage(command.name, args)
         self.gui._submit_command(cm, self.inqueue)
+        return self._handle_response(command_message=cm)
+
+    def _handle_response(self, command_message):
         results = []
         while True:
             msg = self.outqueue.get()
@@ -357,9 +359,11 @@ class HookeFrame (wx.Frame):
                 h.run(self, msg)  # TODO: pause for response?
                 continue
         pp = getattr(
-            self, '_postprocess_%s' % command.name.replace(' ', '_'),
-            self._postprocess_text)
-        pp(command=command, args=args, results=results)
+           self, '_postprocess_%s' % command_message.command.replace(' ', '_'),
+           self._postprocess_text)
+        pp(command=command_message.command,
+           args=command_message.arguments,
+           results=results)
         return results
 
     def _handle_request(self, msg):
@@ -385,6 +389,10 @@ class HookeFrame (wx.Frame):
                 continue
         self.inqueue.put(response)
 
+    def _set_config(self, option, value, section=None):
+        self.gui._set_config(section=section, option=option, value=value,
+                             ui_to_command_queue=self.inqueue,
+                             response_handler=self._handle_response)
 
 
     # Command-specific postprocessing
@@ -751,7 +759,7 @@ class HookeFrame (wx.Frame):
                 self._c['property editor']._argument_from_label[label] = (
                     argument)
 
-        self.gui.config['selected command'] = command  # TODO: push to engine
+        self._set_config('selected command', command.name)
 
 
 
@@ -882,7 +890,7 @@ class HookeFrame (wx.Frame):
 
         selected_perspective = self.gui.config['active perspective']
         if not self._perspectives.has_key(selected_perspective):
-            self.gui.config['active perspective'] = 'Default'  # TODO: push to engine's Hooke
+            self._set_config('active perspective', 'Default')
 
         self._restore_perspective(selected_perspective, force=True)
         self._update_perspective_menu()
@@ -927,7 +935,7 @@ class HookeFrame (wx.Frame):
     def _restore_perspective(self, name, force=False):
         if name != self.gui.config['active perspective'] or force == True:
             self.log.debug('restore perspective %s' % name)
-            self.gui.config['active perspective'] = name  # TODO: push to engine's Hooke
+            self._set_config('active perspective', name)
             self._c['manager'].LoadPerspective(self._perspectives[name])
             self._c['manager'].Update()
             for pane in self._c['manager'].GetAllPanes():
index 0d72db0ae109fe7845343a93701a3048dfa4be9e..cdf95dadd6305982e3e8d62e929fa5593f8cf271 100644 (file)
@@ -48,7 +48,7 @@ def select_save_file(directory, name, extension=None, *args, **kwargs):
         dialog.SetValue(name)
         if dialog.ShowModal() != wx.ID_OK:
             return  # abort
-        name = dialog.GetValue()    
+        name = dialog.GetValue()
         if not name_exists(name):
             return name
         dialogConfirm = wx.MessageDialog(