Add help tooltips to commands in gui.panel.commands
authorW. Trevor King <wking@drexel.edu>
Mon, 2 Aug 2010 13:14:57 +0000 (09:14 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 2 Aug 2010 13:14:57 +0000 (09:14 -0400)
hooke/ui/gui/__init__.py
hooke/ui/gui/panel/commands.py

index 61ed74d2203069713fe86590e11a3516dcc40806..9a685e663e5468d113e209f0f90d3da2288ee512 100644 (file)
@@ -98,7 +98,7 @@ class HookeFrame (wx.Frame):
 \r
         self.execute_command(\r
                 command=self._command_by_name('load playlist'),\r
-                args={'input':'test/data/test'},\r
+                args={'input':'test/data/vclamp_picoforce/playlist'},\r
                 )\r
         return # TODO: cleanup\r
         self.playlists = self._c['playlist'].Playlists\r
index d7e60a78d5d45b2f2eef4df55a924784ce68dcfe..0afd765b22eb82f282af98038799baadadc1f850 100644 (file)
@@ -43,9 +43,11 @@ class Tree (wx.TreeCtrl):
             }\r
         self.Bind(wx.EVT_TREE_SEL_CHANGED, self._on_selection_changed)\r
         self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self._on_execute)\r
+        self.Bind(wx.EVT_MOTION, self._on_motion)\r
 \r
         self._callbacks = callbacks\r
         self._setup_commands(commands, selected)\r
+        self._last_tooltip = None\r
 \r
     def _setup_commands(self, commands, selected):\r
         self._plugins = {}    # {name: hooke.plugin.Plugin()}\r
@@ -108,7 +110,7 @@ class Tree (wx.TreeCtrl):
         for c_id in self._name_for_id.keys():\r
             if c_id == _id:\r
                 return c_id\r
-        return _id\r
+        raise KeyError(_id)\r
 \r
     def _on_selection_changed(self, event):\r
         active_id = event.GetItem()\r
@@ -122,6 +124,27 @@ class Tree (wx.TreeCtrl):
     def _on_execute(self, event):\r
         self.execute()\r
 \r
+    def _on_motion(self, event):\r
+        """Enable tooltips.\r
+        """\r
+        hit_id,hit_flags = self.HitTest(event.GetPosition())\r
+        print hit_id\r
+        try:\r
+            hit_id = self._canonical_id(hit_id)\r
+        except KeyError:\r
+            hit_id = None\r
+        if hit_id == None:\r
+            msg = ''\r
+        else:\r
+            name = self._name_for_id[hit_id]\r
+            if self._is_command(name):\r
+                msg = self._commands[name].help()\r
+            else:\r
+                msg = ''  # self._plugins[name].help() TODO: Plugin.help method\r
+        if msg != self._last_tooltip:\r
+            self._last_tooltip = msg\r
+            event.GetEventObject().SetToolTipString(msg)\r
+\r
     def select_plugin(self, plugin):\r
         in_callback(self, plugin)\r
 \r