From bbf2b7eb99e94cf82de4c4160c9fdf8702cd1ba4 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 2 Aug 2010 10:56:10 -0400 Subject: [PATCH] Updated gui.panel.note and simplified hooke.plugin.note. 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 | 62 ++++++---------------------------- hooke/ui/gui/__init__.py | 51 +++++++++++++--------------- hooke/ui/gui/panel/__init__.py | 2 +- hooke/ui/gui/panel/commands.py | 1 - hooke/ui/gui/panel/note.py | 32 +++++++++++++----- 5 files changed, 57 insertions(+), 91 deletions(-) diff --git a/hooke/plugin/note.py b/hooke/plugin/note.py index fa20592..3847dff 100644 --- a/hooke/plugin/note.py +++ b/hooke/plugin/note.py @@ -22,30 +22,29 @@ """ 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) diff --git a/hooke/ui/gui/__init__.py b/hooke/ui/gui/__init__.py index 470b6ec..e9a3945 100644 --- a/hooke/ui/gui/__init__.py +++ b/hooke/ui/gui/__init__.py @@ -133,10 +133,14 @@ class HookeFrame (wx.Frame): # WANTS_CHARS so the panel doesn't eat the Return key. # size=(160, 200), ), 'left'), -# ('note', panel.note.Note( -# parent=self -# style=wx.WANTS_CHARS|wx.NO_BORDER, -# size=(160, 200)), 'left'), + (panel.PANELS['note']( + callbacks = { + '_on_update':self._on_update_note, + }, + parent=self, + style=wx.WANTS_CHARS|wx.NO_BORDER, +# size=(160, 200), + ), 'left'), # ('notebook', Notebook( # parent=self, # pos=wx.Point(client_size.x, client_size.y), @@ -230,20 +234,9 @@ class HookeFrame (wx.Frame): self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self._on_notebook_page_close) return # TODO: cleanup - for value in self._c['menu bar']._c['view']._c.values(): - self.Bind(wx.EVT_MENU_RANGE, self._on_view, value) - - self.Bind(wx.EVT_MENU, self._on_save_perspective, - self._c['menu bar']._c['perspective']._c['save']) - self.Bind(wx.EVT_MENU, self._on_delete_perspective, - self._c['menu bar']._c['perspective']._c['delete']) - treeCtrl = self._c['folders'].GetTreeCtrl() treeCtrl.Bind(wx.EVT_LEFT_DCLICK, self._on_dir_ctrl_left_double_click) - # TODO: playlist callbacks - return # TODO: cleanup - evtmgr.eventManager.Register(self.OnUpdateNote, wx.EVT_BUTTON, self.panelNote.UpdateButton) #property editor self.panelProperties.pg.Bind(wxpg.EVT_PG_CHANGED, self.OnPropGridChanged) #results panel @@ -403,6 +396,9 @@ class HookeFrame (wx.Frame): playlist = results[0] else: raise NotImplementedError() + if 'note' in self._c: + print sorted(curve.info.keys()) + self._c['note'].set_text(curve.info['note']) if 'playlist' in self._c: self._c['playlist']._c['tree'].set_selected_curve( playlist, curve) @@ -592,19 +588,6 @@ class HookeFrame (wx.Frame): def _on_size(self, event): event.Skip() - def OnUpdateNote(self, event): - ''' - Saves the note to the active file. - ''' - active_file = self.GetActiveFile() - active_file.note = self.panelNote.Editor.GetValue() - - def UpdateNote(self): - #update the note for the active file - active_file = self.GetActiveFile() - if active_file is not None: - self.panelNote.Editor.SetValue(active_file.note) - def UpdatePlaylistsTreeSelection(self): playlist = self.GetActivePlaylist() if playlist is not None: @@ -682,6 +665,18 @@ class HookeFrame (wx.Frame): + # Note panel interface + + def _on_update_note(self, _class, method, text): + """Sets the note for the active curve. + """ + # TODO: note list interface in NotePanel. + self.execute_command( + command=self._command_by_name('set note'), + args={'note':text}) + + + # Playlist panel interface def _on_user_delete_playlist(self, _class, method, playlist): diff --git a/hooke/ui/gui/panel/__init__.py b/hooke/ui/gui/panel/__init__.py index 11e5187..cbb4aee 100644 --- a/hooke/ui/gui/panel/__init__.py +++ b/hooke/ui/gui/panel/__init__.py @@ -8,7 +8,7 @@ from ....util.pluggable import IsSubclass, construct_odict PANEL_MODULES = [ 'commands', -# 'note', + 'note', # 'notebook', 'output', 'playlist', diff --git a/hooke/ui/gui/panel/commands.py b/hooke/ui/gui/panel/commands.py index 5ea8ba5..f46f098 100644 --- a/hooke/ui/gui/panel/commands.py +++ b/hooke/ui/gui/panel/commands.py @@ -186,7 +186,6 @@ class CommandsPanel (Panel, wx.Panel): sizer.Fit(self) self.Bind(wx.EVT_BUTTON, self._on_execute_button) - self._callbacks = callbacks def _on_execute_button(self, event): self._c['tree'].execute() diff --git a/hooke/ui/gui/panel/note.py b/hooke/ui/gui/panel/note.py index 7dc6848..30de470 100644 --- a/hooke/ui/gui/panel/note.py +++ b/hooke/ui/gui/panel/note.py @@ -5,20 +5,34 @@ import wx +from ....util.callback import callback, in_callback from . import Panel class NotePanel (Panel, wx.Panel): def __init__(self, callbacks=None, **kwargs): - super(Note, self).__init__(name='note', callbacks=callbacks, **kwargs) - - self.Editor = wx.TextCtrl(self, style=wx.TE_MULTILINE) - - self.UpdateButton = wx.Button(self, -1, 'Update note') - + super(NotePanel, self).__init__( + name='note', callbacks=callbacks, **kwargs) + + self._c = { + 'editor': wx.TextCtrl( + parent=self, + style=wx.TE_MULTILINE), + 'update': wx.Button( + parent=self, + label='Update note'), + } sizer = wx.BoxSizer(wx.VERTICAL) - sizer.Add(self.Editor, 1, wx.EXPAND) - sizer.Add(self.UpdateButton, 0, wx.EXPAND) - + sizer.Add(self._c['editor'], 1, wx.EXPAND) + sizer.Add(self._c['update'], 0, wx.EXPAND) self.SetSizer(sizer) self.SetAutoLayout(True) + + self.Bind(wx.EVT_BUTTON, self._on_update) + + def set_text(self, text): + self._c['editor'].SetValue(text) + + def _on_update(self, event): + text = self._c['editor'].GetValue() + in_callback(self, text) -- 2.26.2