From 13a43acd9fa0c9a10f7f8d3a10312f69fdf7164e Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 2 Aug 2010 09:14:57 -0400 Subject: [PATCH] Add help tooltips to commands in gui.panel.commands --- hooke/ui/gui/__init__.py | 2 +- hooke/ui/gui/panel/commands.py | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/hooke/ui/gui/__init__.py b/hooke/ui/gui/__init__.py index 61ed74d..9a685e6 100644 --- a/hooke/ui/gui/__init__.py +++ b/hooke/ui/gui/__init__.py @@ -98,7 +98,7 @@ class HookeFrame (wx.Frame): self.execute_command( command=self._command_by_name('load playlist'), - args={'input':'test/data/test'}, + args={'input':'test/data/vclamp_picoforce/playlist'}, ) return # TODO: cleanup self.playlists = self._c['playlist'].Playlists diff --git a/hooke/ui/gui/panel/commands.py b/hooke/ui/gui/panel/commands.py index d7e60a7..0afd765 100644 --- a/hooke/ui/gui/panel/commands.py +++ b/hooke/ui/gui/panel/commands.py @@ -43,9 +43,11 @@ class Tree (wx.TreeCtrl): } self.Bind(wx.EVT_TREE_SEL_CHANGED, self._on_selection_changed) self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self._on_execute) + self.Bind(wx.EVT_MOTION, self._on_motion) self._callbacks = callbacks self._setup_commands(commands, selected) + self._last_tooltip = None def _setup_commands(self, commands, selected): self._plugins = {} # {name: hooke.plugin.Plugin()} @@ -108,7 +110,7 @@ class Tree (wx.TreeCtrl): for c_id in self._name_for_id.keys(): if c_id == _id: return c_id - return _id + raise KeyError(_id) def _on_selection_changed(self, event): active_id = event.GetItem() @@ -122,6 +124,27 @@ class Tree (wx.TreeCtrl): def _on_execute(self, event): self.execute() + def _on_motion(self, event): + """Enable tooltips. + """ + hit_id,hit_flags = self.HitTest(event.GetPosition()) + print hit_id + try: + hit_id = self._canonical_id(hit_id) + except KeyError: + hit_id = None + if hit_id == None: + msg = '' + else: + name = self._name_for_id[hit_id] + if self._is_command(name): + msg = self._commands[name].help() + else: + msg = '' # self._plugins[name].help() TODO: Plugin.help method + if msg != self._last_tooltip: + self._last_tooltip = msg + event.GetEventObject().SetToolTipString(msg) + def select_plugin(self, plugin): in_callback(self, plugin) -- 2.26.2