1 #!/usr/bin/env python
\r
3 """Commands and settings panel for Hooke.
\r
11 class Tree (wx.TreeCtrl):
\r
12 def __init__(self, commands, selected, *args, **kwargs):
\r
13 super(Tree, self).__init__(*args, **kwargs)
\r
14 imglist = wx.ImageList(width=16, height=16, mask=True, initialCount=2)
\r
15 imglist.Add(wx.ArtProvider.GetBitmap(
\r
16 wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))
\r
17 imglist.Add(wx.ArtProvider.GetBitmap(
\r
18 wx.ART_EXECUTABLE_FILE, wx.ART_OTHER, wx.Size(16, 16)))
\r
19 self.AssignImageList(imglist)
\r
25 self.AddRoot(text='Commands and Settings', image=self.image['root'])
\r
27 self._setup_commands(commands, selected)
\r
29 def _setup_commands(self, commands, selected):
\r
30 self._commands = commands
\r
32 tree_root = self.GetRootItem()
\r
35 plugins = sorted(set([c.plugin for c in commands]),
\r
36 key=lambda p:p.name)
\r
37 for plugin in plugins:
\r
38 plugin_roots[plugin.name] = self.AppendItem(
\r
41 image=self.image['plugin'],
\r
42 data=wx.TreeItemData(plugin))
\r
44 for command in sorted(commands, key=lambda c:c.name):
\r
45 item = self.AppendItem(
\r
46 parent=plugin_roots[command.plugin.name],
\r
48 image=self.image['command'])
\r
49 if command.name == selected:
\r
51 for key,value in plugin_roots.items():
\r
53 #make sure the selected command/plugin is visible in the tree
\r
54 if selected is not None:
\r
55 self.SelectItem(selected, True)
\r
56 self.EnsureVisible(selected)
\r
59 class Commands (wx.Panel):
\r
60 def __init__(self, commands, selected, *args, **kwargs):
\r
61 super(Commands, self).__init__(*args, **kwargs)
\r
68 size=wx.Size(160, 250),
\r
69 style=wx.TR_DEFAULT_STYLE|wx.NO_BORDER|wx.TR_HIDE_ROOT),
\r
70 'execute': wx.Button(self, label='Execute'),
\r
72 sizer = wx.BoxSizer(wx.VERTICAL)
\r
73 sizer.Add(self._c['execute'], 0, wx.EXPAND)
\r
74 sizer.Add(self._c['tree'], 1, wx.EXPAND)
\r
75 self.SetSizer(sizer)
\r