From ab9c8c1e394de4f816440129d5b483d04845f783 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 20 Aug 2010 03:45:00 -0400 Subject: [PATCH] Push GUI config setting changes to the engine process' Hooke. --- doc/gui.txt | 2 -- hooke/ui/__init__.py | 16 ++++++++++++++++ hooke/ui/gui/__init__.py | 32 ++++++++++++++++++++------------ hooke/ui/gui/dialog/save_file.py | 2 +- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/doc/gui.txt b/doc/gui.txt index 4ae9488..28e9cb8 100644 --- a/doc/gui.txt +++ b/doc/gui.txt @@ -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 diff --git a/hooke/ui/__init__.py b/hooke/ui/__init__.py index 02e9151..cfdac72 100644 --- a/hooke/ui/__init__.py +++ b/hooke/ui/__init__.py @@ -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 diff --git a/hooke/ui/gui/__init__.py b/hooke/ui/gui/__init__.py index 034003b..7362010 100644 --- a/hooke/ui/gui/__init__.py +++ b/hooke/ui/gui/__init__.py @@ -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(): diff --git a/hooke/ui/gui/dialog/save_file.py b/hooke/ui/gui/dialog/save_file.py index 0d72db0..cdf95da 100644 --- a/hooke/ui/gui/dialog/save_file.py +++ b/hooke/ui/gui/dialog/save_file.py @@ -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( -- 2.26.2