Clean up and adjust names of commands requiring curve updates in the GUI.
[hooke.git] / hooke / ui / gui / __init__.py
index 048764e97f6a1c204c24a0948fe6b7ee3bc0aa9f..a49fe27e498b4abc37a78a225cdd7f6d7cd8a30e 100644 (file)
@@ -1,7 +1,4 @@
-# Copyright (C) 2008-2010 Fabrizio Benedetti
-#                         Massimo Sandal <devicerandom@gmail.com>
-#                         Rolf Schmidt <rschmidt@alcor.concordia.ca>
-#                         W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2011 W. Trevor King <wking@drexel.edu>
 #
 # This file is part of Hooke.
 #
@@ -71,7 +68,9 @@ class HookeFrame (wx.Frame):
         self._perspectives = {}  # {name: perspective_str}
         self._c = {}
 
-        self.SetIcon(wx.Icon(self.gui.config['icon image'], wx.BITMAP_TYPE_ICO))
+        self.SetIcon(wx.Icon(
+                os.path.expanduser(self.gui.config['icon image']),
+                wx.BITMAP_TYPE_ICO))
 
         # setup frame manager
         self._c['manager'] = aui.AuiManager()
@@ -165,7 +164,7 @@ class HookeFrame (wx.Frame):
                     commands=self.commands,
                     selected=self.gui.config['selected command'],
                     callbacks={
-                        'execute': self.execute_command,
+                        'execute': self.explicit_execute_command,
                         'select_plugin': self.select_plugin,
                         'select_command': self.select_command,
 #                        'selection_changed': self.panelProperties.select(self, method, command),  #SelectedTreeItem = selected_item,
@@ -196,7 +195,6 @@ class HookeFrame (wx.Frame):
                     size=wx.Size(150, 90),
                     style=wx.TE_READONLY|wx.NO_BORDER|wx.TE_MULTILINE),
              'bottom'),
-#            ('results', panel.results.Results(self), 'bottom'),
             ]:
             self._add_panel(p, style)
         self.execute_command(  # setup already loaded playlists
@@ -244,7 +242,6 @@ class HookeFrame (wx.Frame):
         self.Bind(wx.EVT_SIZE, self._on_size)
         self.Bind(wx.EVT_CLOSE, self._on_close)
         self.Bind(aui.EVT_AUI_PANE_CLOSE, self._on_pane_close)
-        self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self._on_notebook_page_close)
 
         return # TODO: cleanup
         treeCtrl = self._c['folders'].GetTreeCtrl()
@@ -301,8 +298,14 @@ class HookeFrame (wx.Frame):
             raise Exception('Multiple commands named "%s"' % name)
         return cs[0]
 
+    def explicit_execute_command(self, _class=None, method=None,
+                                 command=None, args=None):
+        return self.execute_command(
+            _class=_class, method=method, command=command, args=args,
+            explicit_user_call=True)
+
     def execute_command(self, _class=None, method=None,
-                        command=None, args=None):
+                        command=None, args=None, explicit_user_call=False):
         if args == None:
             args = {}
         if ('property editor' in self._c
@@ -338,7 +341,11 @@ class HookeFrame (wx.Frame):
                     if len(args[arg.name]) == 0:
                         args[arg.name] = arg.default
         cm = CommandMessage(command.name, args)
-        self.gui._submit_command(cm, self.inqueue)
+        self.gui._submit_command(
+            cm, self.inqueue, explicit_user_call=explicit_user_call)
+        # TODO: skip responses for commands that were captured by the
+        # command stack.  We'd need to poll on each request, remember
+        # capture state, or add a flag to the response...
         return self._handle_response(command_message=cm)
 
     def _handle_response(self, command_message):
@@ -512,22 +519,12 @@ class HookeFrame (wx.Frame):
                 self.execute_command(
                     command=self._command_by_name('get playlist'))
 
-    def _postprocess_zero_block_surface_contact_point(
-        self, command, args={}, results=[]):
+    def _update_curve(self, command, args={}, results=[]):
         """Update the curve, since the available columns may have changed.
         """
         if isinstance(results[-1], Success):
             self.execute_command(
                 command=self._command_by_name('get curve'))
-    def _postprocess_add_block_force_array(
-        self, command, args={}, results=[]):
-        """Update the curve, since the available columns may have changed.
-        """
-        if isinstance(results[-1], Success):
-            self.execute_command(
-                command=self._command_by_name('get curve'))
-
 
 
     # Command panel interface
@@ -567,6 +564,9 @@ class HookeFrame (wx.Frame):
 
         self._set_config('selected command', command.name)
 
+    def select_plugin(self, _class=None, method=None, plugin=None):
+        pass
+
 
 
     # Folders panel interface
@@ -696,7 +696,7 @@ class HookeFrame (wx.Frame):
         self._perspectives = {
             'Default': self._c['manager'].SavePerspective(),
             }
-        path = self.gui.config['perspective path']
+        path = os.path.expanduser(self.gui.config['perspective path'])
         if os.path.isdir(path):
             files = sorted(os.listdir(path))
             for fname in files:
@@ -773,7 +773,7 @@ class HookeFrame (wx.Frame):
         if name == 'Default':
             name = 'New perspective'
         name = select_save_file(
-            directory=self.gui.config['perspective path'],
+            directory=os.path.expanduser(self.gui.config['perspective path']),
             name=name,
             extension=self.gui.config['perspective extension'],
             parent=self,
@@ -782,7 +782,8 @@ class HookeFrame (wx.Frame):
         if name == None:
             return
         self._save_perspective(
-            perspective, self.gui.config['perspective path'], name=name,
+            perspective,
+            os.path.expanduser(self.gui.config['perspective path']), name=name,
             extension=self.gui.config['perspective extension'])
 
     def _on_delete_perspective(self, *args, **kwargs):
@@ -803,13 +804,22 @@ class HookeFrame (wx.Frame):
         names = [options[i] for i in dialog.selected]
         dialog.Destroy()
         self._delete_perspectives(
-            self.gui.config['perspective path'], names=names,
-            extension=self.gui.config['perspective extension'])
+            os.path.expanduser(self.gui.config['perspective path']),
+            names=names, extension=self.gui.config['perspective extension'])
 
     def _on_select_perspective(self, _class, method, name):
         self._restore_perspective(name)
 
 
+# setup per-command versions of HookeFrame._update_curve
+for _command in ['convert_distance_to_force',
+                 'polymer_fit_peaks',
+                 'remove_cantilever_from_extension',
+                 'zero_surface_contact_point',
+                 ]:
+    setattr(HookeFrame, '_postprocess_%s' % _command, HookeFrame._update_curve)
+del _command
+
 
 class HookeApp (wx.App):
     """A :class:`wx.App` wrapper around :class:`HookeFrame`.
@@ -856,7 +866,7 @@ class HookeApp (wx.App):
 
     def _setup_splash_screen(self):
         if self.gui.config['show splash screen'] == True:
-            path = self.gui.config['splash screen image']
+            path = os.path.expanduser(self.gui.config['splash screen image'])
             if os.path.isfile(path):
                 duration = self.gui.config['splash screen duration']
                 wx.SplashScreen(