From: W. Trevor King Date: Mon, 2 Aug 2010 13:14:57 +0000 (-0400) Subject: Add help tooltips to commands in gui.panel.commands X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ed69165e3537a6aab753f656d971571de93a5af0;p=hooke.git Add help tooltips to commands in gui.panel.commands --- 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)