Add a `Delete` button to the GUI NavBar, and cleanup deletion callbacks.
[hooke.git] / hooke / ui / gui / interface.py
index 3d106e04dd42918969070ddf3648a2634aaa7530..3ea863153415616c4b859bd1f895cc658decf378 100644 (file)
@@ -31,8 +31,10 @@ import platform
 import shutil
 import time
 
+import wx
 import wx.html
-import wx.aui as aui
+#import wx.aui as aui         # C++ implementation
+import wx.lib.agw.aui as aui  # Python implementation
 import wx.lib.evtmgr as evtmgr
 # wxPropertyGrid is included in wxPython >= 2.9.1, see
 #   http://wxpropgrid.sourceforge.net/cgi-bin/index?page=download
@@ -75,8 +77,6 @@ class HookeFrame (wx.Frame):
         # set the gradient and drag styles
         self._c['manager'].GetArtProvider().SetMetric(
             aui.AUI_DOCKART_GRADIENT_TYPE, aui.AUI_GRADIENT_NONE)
-        self._c['manager'].SetFlags(
-            self._c['manager'].GetFlags() ^ aui.AUI_MGR_TRANSPARENT_DRAG)
 
         # Min size for the frame itself isn't completely done.  See
         # the end of FrameManager::Update() for the test code. For
@@ -130,10 +130,8 @@ class HookeFrame (wx.Frame):
 #                    defaultFilter=self.gui.config['folders-filter-index']), 'left'),
             (panel.PANELS['playlist'](
                     callbacks={
-                        'delete_playlist':self._on_user_delete_playlist,
-                        '_delete_playlist':self._on_delete_playlist,
-                        'delete_curve':self._on_user_delete_curve,
-                        '_delete_curve':self._on_delete_curve,
+                        '_delete_playlist':self._delete_playlist,
+                        '_delete_curve':self._delete_curve,
                         '_on_set_selected_playlist':self._on_set_selected_playlist,
                         '_on_set_selected_curve':self._on_set_selected_curve,
                         },
@@ -221,9 +219,9 @@ class HookeFrame (wx.Frame):
             callbacks={
                 'next': self._next_curve,
                 'previous': self._previous_curve,
+                'delete': self._delete_curve,
                 },
-            parent=self,
-            style=wx.TB_FLAT | wx.TB_NODIVIDER)
+            parent=self)
         self._c['manager'].AddPane(
             self._c['navigation bar'],
             aui.AuiPaneInfo().Name('Navigation').Caption('Navigation'
@@ -238,6 +236,7 @@ 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(wx.EVT_CHAR_HOOK, self._on_key)
 
         return # TODO: cleanup
         treeCtrl = self._c['folders'].GetTreeCtrl()
@@ -259,6 +258,7 @@ class HookeFrame (wx.Frame):
 
     def _on_close(self, *args):
         self.log.info('closing GUI framework')
+
         # apply changes
         self._set_config('main height', self.GetSize().GetHeight())
         self._set_config('main left', self.GetPosition()[0])
@@ -271,6 +271,16 @@ class HookeFrame (wx.Frame):
     def _on_erase_background(self, event):
         event.Skip()
 
+    def _on_key(self, event):
+        code = event.GetKeyCode()
+        if code == wx.WXK_RIGHT:
+            self._next_curve()
+        elif code == wx.WXK_LEFT:
+            self._previous_curve()
+        elif code == wx.WXK_DELETE or code == wx.WXK_BACK:
+            self._delete_curve()
+        else:
+            event.Skip()
 
 
     # Panel utility functions
@@ -520,6 +530,11 @@ class HookeFrame (wx.Frame):
                 self.execute_command(
                     command=self._command_by_name('get playlist'))
 
+    def _postprocess_delete_curve(self, command, args={}, results=[]):
+        """No-op.  Only call 'delete curve' via `self._delete_curve()`.
+        """
+        pass
+
     def _update_curve(self, command, args={}, results=[]):
         """Update the curve, since the available columns may have changed.
         """
@@ -594,22 +609,11 @@ class HookeFrame (wx.Frame):
 
     # Playlist panel interface
 
-    def _on_user_delete_playlist(self, _class, method, playlist):
-        pass
-
-    def _on_delete_playlist(self, _class, method, playlist):
-        if hasattr(playlist, 'path') and playlist.path != None:
-            os.remove(playlist.path)
-
-    def _on_user_delete_curve(self, _class, method, playlist, curve):
-        pass
-
-    def _on_delete_curve(self, _class, method, playlist, curve):
-        index = playlist.index(curve)
-        results = self.execute_command(
-            command=self._command_by_name('remove curve from playlist'),
-            args={'index': index})
-        #os.remove(curve.path)
+    def _delete_playlist(self, _class, method, playlist):
+        #if hasattr(playlist, 'path') and playlist.path != None:
+        #    os.remove(playlist.path)
+        # TODO: remove playlist from underlying hooke instance and call ._c['playlist'].delete_playlist()
+        # possibly rename this method to _postprocess_delete_playlist...
         pass
 
     def _on_set_selected_playlist(self, _class, method, playlist):
@@ -675,6 +679,18 @@ class HookeFrame (wx.Frame):
             self.execute_command(
                 command=self._command_by_name('get curve'))
 
+    def _delete_curve(self, *args, **kwargs):
+        cmd_kwargs = {}
+        playlist = kwargs.get('playlist', None)
+        curve = kwargs.get('curve', None)
+        if playlist is not None and curve is not None:
+            cmd_kwargs['index'] = playlist.index(curve)
+        results = self.execute_command(
+            command=self._command_by_name('remove curve from playlist'),
+            args=cmd_kwargs)
+        if isinstance(results[-1], Success):
+            results = self.execute_command(
+                command=self._command_by_name('get playlist'))
 
 
     # Panel display handling