Updated gui.panel.note and simplified hooke.plugin.note.
authorW. Trevor King <wking@drexel.edu>
Mon, 2 Aug 2010 14:56:10 +0000 (10:56 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 2 Aug 2010 14:56:10 +0000 (10:56 -0400)
Previous hooke.plugin.note had assumed curve.info['note'] was a list
of strings.  The current implementation is simpler (and class
agnostic) with get/set commands.

NotePanel now works as a UI to the current curve's .info['note'], but
it has exposed some issues with .info in Playlist.flatten().

Also removed some outdated binding cruft from gui/__init__.py (now
handled by the panels themselves) and an outdated _callback setting
from panel.commands (it's set in the base Panel.__init__()).

hooke/plugin/note.py
hooke/ui/gui/__init__.py
hooke/ui/gui/panel/__init__.py
hooke/ui/gui/panel/commands.py
hooke/ui/gui/panel/note.py

index fa20592a90ac0f2e517d4b51926a881a67debfb9..3847dff523e61d8add24d00e85cf5061d0eaf3e0 100644 (file)
 """
 
 from ..command import Command, Argument, Failure
-from ..playlist import FilePlaylist
 from ..plugin import Builtin
-from ..plugin.playlist import current_playlist_callback
+from ..plugin.curve import current_curve_callback
 
 
 class NotePlugin (Builtin):
     def __init__(self):
         super(NotePlugin, self).__init__(name='note')
         self._commands = [
-            AddNoteCommand(self), ClearNoteCommand(self), GetNoteCommand(self)]
+            SetNoteCommand(self), GetNoteCommand(self)]
 
 
-class AddNoteCommand (Command):
+class SetNoteCommand (Command):
     """Add a note to one of several Hooke objects.
     """
     def __init__(self, plugin):
-        super(AddNoteCommand, self).__init__(
-            name='add note',
+        super(SetNoteCommand, self).__init__(
+            name='set note',
             arguments=[
                 Argument(
                     name='target', type='object',
-                    callback=current_playlist_callback,
+                    callback=current_curve_callback,
                     help="""
-Target object for the note.  Defaults to the current playlist.
+Target object for the note.  Defaults to the current curve.
 """.strip()),
                 Argument(
                     name='note', type='string', optional=False,
@@ -56,49 +55,8 @@ The note text.
             help=self.__doc__, plugin=plugin)
 
     def _run(self, hooke, inqueue, outqueue, params):
-        params['target'].info['note'].append(params['note'])
+        params['target'].info['note'] = params['note']
 
-class ClearNoteCommand (Command):
-    """Remove a note or notes from one of several Hooke objects.
-    """
-    def __init__(self, plugin):
-        super(ClearNoteCommand, self).__init__(
-            name='clear note',
-            arguments=[
-                Argument(
-                    name='target', type='object',
-                    callback=current_playlist_callback,
-                    help="""
-Target object for the note.  Defaults to the current playlist.
-""".strip()),
-                Argument(name='count', type='int', default=-1,
-                         help="""
-Number of notes to remove.  Defaults to all notes.
-""".strip()),
-                Argument(name='force', type='bool', default=False,
-                         help="""
-Run without prompting the user.  Use if you save often or don't make
-typing mistakes ;).
-""".strip()),
-                ],
-            help=self.__doc__, plugin=plugin)
-
-    def _run(self, hooke, inqueue, outqueue, params):
-        num_notes = len(params['target'].info['note'])
-        if params['count'] == -1:
-            num_notes_removed = num_notes
-        else:
-            num_notes_removed = min(num_notes, params['count'])
-        if params['force'] == False and num_notes_removed > 0:
-            msg = 'Remove %d notes?' % num_notes_removed
-            default = False
-            outqueue.put(BooleanRequest(msg, default))
-            result = inqueue.get()
-            assert result.type == 'boolean'
-            if result.value == False:
-                return
-        params['target'].info['note'] = \
-            params['target'].info['note'][:-num_notes_removed]
 
 class GetNoteCommand (Command):
     """Retrieve notes from one of several Hooke objects.
@@ -109,9 +67,9 @@ class GetNoteCommand (Command):
             arguments=[
                 Argument(
                     name='target', type='object',
-                    callback=current_playlist_callback,
+                    callback=current_curve_callback,
                     help="""
-Target object for the note.  Defaults to the current playlist.
+Target object for the note.  Defaults to the current curve.
 """.strip()),
                 ],
             help=self.__doc__, plugin=plugin)
index 470b6ec452051a3d8da6fed7f9ee3eb7145a722e..e9a394552a07e03c602da4ab334251a76a1eab6c 100644 (file)
@@ -133,10 +133,14 @@ class HookeFrame (wx.Frame):
                     # WANTS_CHARS so the panel doesn't eat the Return key.\r
 #                    size=(160, 200),\r
                     ), 'left'),\r
-#            ('note', panel.note.Note(\r
-#                    parent=self\r
-#                    style=wx.WANTS_CHARS|wx.NO_BORDER,\r
-#                    size=(160, 200)), 'left'),\r
+            (panel.PANELS['note'](\r
+                    callbacks = {\r
+                        '_on_update':self._on_update_note,\r
+                        },\r
+                    parent=self,\r
+                    style=wx.WANTS_CHARS|wx.NO_BORDER,\r
+#                    size=(160, 200),\r
+                    ), 'left'),\r
 #            ('notebook', Notebook(\r
 #                    parent=self,\r
 #                    pos=wx.Point(client_size.x, client_size.y),\r
@@ -230,20 +234,9 @@ class HookeFrame (wx.Frame):
         self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self._on_notebook_page_close)\r
 \r
         return # TODO: cleanup\r
-        for value in self._c['menu bar']._c['view']._c.values():\r
-            self.Bind(wx.EVT_MENU_RANGE, self._on_view, value)\r
-\r
-        self.Bind(wx.EVT_MENU, self._on_save_perspective,\r
-                  self._c['menu bar']._c['perspective']._c['save'])\r
-        self.Bind(wx.EVT_MENU, self._on_delete_perspective,\r
-                  self._c['menu bar']._c['perspective']._c['delete'])\r
-\r
         treeCtrl = self._c['folders'].GetTreeCtrl()\r
         treeCtrl.Bind(wx.EVT_LEFT_DCLICK, self._on_dir_ctrl_left_double_click)\r
         \r
-        # TODO: playlist callbacks\r
-        return # TODO: cleanup\r
-        evtmgr.eventManager.Register(self.OnUpdateNote, wx.EVT_BUTTON, self.panelNote.UpdateButton)\r
         #property editor\r
         self.panelProperties.pg.Bind(wxpg.EVT_PG_CHANGED, self.OnPropGridChanged)\r
         #results panel\r
@@ -403,6 +396,9 @@ class HookeFrame (wx.Frame):
             playlist = results[0]\r
         else:\r
             raise NotImplementedError()\r
+        if 'note' in self._c:\r
+            print sorted(curve.info.keys())\r
+            self._c['note'].set_text(curve.info['note'])\r
         if 'playlist' in self._c:\r
             self._c['playlist']._c['tree'].set_selected_curve(\r
                 playlist, curve)\r
@@ -592,19 +588,6 @@ class HookeFrame (wx.Frame):
     def _on_size(self, event):\r
         event.Skip()\r
 \r
-    def OnUpdateNote(self, event):\r
-        '''\r
-        Saves the note to the active file.\r
-        '''\r
-        active_file = self.GetActiveFile()\r
-        active_file.note = self.panelNote.Editor.GetValue()\r
-\r
-    def UpdateNote(self):\r
-        #update the note for the active file\r
-        active_file = self.GetActiveFile()\r
-        if active_file is not None:\r
-            self.panelNote.Editor.SetValue(active_file.note)\r
-\r
     def UpdatePlaylistsTreeSelection(self):\r
         playlist = self.GetActivePlaylist()\r
         if playlist is not None:\r
@@ -682,6 +665,18 @@ class HookeFrame (wx.Frame):
 \r
 \r
 \r
+    # Note panel interface\r
+\r
+    def _on_update_note(self, _class, method, text):\r
+        """Sets the note for the active curve.\r
+        """\r
+        # TODO: note list interface in NotePanel.\r
+        self.execute_command(\r
+            command=self._command_by_name('set note'),\r
+            args={'note':text})\r
+\r
+\r
+\r
     # Playlist panel interface\r
 \r
     def _on_user_delete_playlist(self, _class, method, playlist):\r
index 11e5187a640db801f9dc89308320d71a311d1591..cbb4aee87dd3d49140ca6f3d110e9241d0f69389 100644 (file)
@@ -8,7 +8,7 @@ from ....util.pluggable import IsSubclass, construct_odict
 \r
 PANEL_MODULES = [\r
     'commands',\r
-#    'note',\r
+    'note',\r
 #    'notebook',\r
     'output',\r
     'playlist',\r
index 5ea8ba5d6d47d82245429695139e2dd0176a2d37..f46f098bd21713c841759ec15c6de7f7b2e163b2 100644 (file)
@@ -186,7 +186,6 @@ class CommandsPanel (Panel, wx.Panel):
         sizer.Fit(self)\r
 \r
         self.Bind(wx.EVT_BUTTON, self._on_execute_button)\r
-        self._callbacks = callbacks\r
 \r
     def _on_execute_button(self, event):\r
         self._c['tree'].execute()\r
index 7dc68480484e79bc8cc8dd9ffc447685b85d1edd..30de470cb0546466d6c000461a8b0763b7ea7409 100644 (file)
@@ -5,20 +5,34 @@
 \r
 import wx\r
 \r
+from ....util.callback import callback, in_callback\r
 from . import Panel\r
 \r
 \r
 class NotePanel (Panel, wx.Panel):\r
     def __init__(self, callbacks=None, **kwargs):\r
-        super(Note, self).__init__(name='note', callbacks=callbacks, **kwargs)\r
-\r
-        self.Editor = wx.TextCtrl(self, style=wx.TE_MULTILINE)\r
-\r
-        self.UpdateButton = wx.Button(self, -1, 'Update note')\r
-\r
+        super(NotePanel, self).__init__(\r
+            name='note', callbacks=callbacks, **kwargs)\r
+\r
+        self._c = {\r
+            'editor': wx.TextCtrl(\r
+                parent=self,\r
+                style=wx.TE_MULTILINE),\r
+            'update': wx.Button(\r
+                parent=self,\r
+                label='Update note'),\r
+            }\r
         sizer = wx.BoxSizer(wx.VERTICAL)\r
-        sizer.Add(self.Editor, 1, wx.EXPAND)\r
-        sizer.Add(self.UpdateButton, 0, wx.EXPAND)\r
-\r
+        sizer.Add(self._c['editor'], 1, wx.EXPAND)\r
+        sizer.Add(self._c['update'], 0, wx.EXPAND)\r
         self.SetSizer(sizer)\r
         self.SetAutoLayout(True)\r
+\r
+        self.Bind(wx.EVT_BUTTON, self._on_update)\r
+\r
+    def set_text(self, text):\r
+        self._c['editor'].SetValue(text)\r
+\r
+    def _on_update(self, event):\r
+        text = self._c['editor'].GetValue()\r
+        in_callback(self, text)\r