1 #!/usr/bin/env python
\r
3 Commands and settings panel for Hooke
\r
5 Displays commands and settings for Hooke in a tree control
\r
6 (c) Dr. Rolf Schmidt, 2009
\r
9 from configobj import ConfigObj
\r
11 from validate import Validator
\r
14 import libhooke as lh
\r
16 class Commands(wx.Panel):
\r
18 def __init__(self, parent):
\r
19 # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
\r
20 wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))
\r
22 self.CommandsTree = wx.TreeCtrl(self, -1, wx.Point(0, 0), wx.Size(160, 250), wx.TR_DEFAULT_STYLE|wx.NO_BORDER|wx.TR_HIDE_ROOT)
\r
23 imglist = wx.ImageList(16, 16, True, 2)
\r
24 imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))
\r
25 imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_EXECUTABLE_FILE, wx.ART_OTHER, wx.Size(16, 16)))
\r
26 self.CommandsTree.AssignImageList(imglist)
\r
27 self.CommandsTree.AddRoot('Commands and Settings', 0)
\r
29 self.ExecuteButton = wx.Button(self, -1, 'Execute')
\r
31 sizer = wx.BoxSizer(wx.VERTICAL)
\r
32 sizer.Add(self.CommandsTree, 1, wx.EXPAND)
\r
33 sizer.Add(self.ExecuteButton, 0, wx.EXPAND)
\r
35 self.SetSizer(sizer)
\r
38 def Initialize(self, plugins):
\r
39 tree_root = self.CommandsTree.GetRootItem()
\r
40 for plugin in plugins:
\r
41 filename = ''.join([plugin, '.ini'])
\r
42 path = lh.get_file_path(filename, ['plugins'])
\r
43 config = ConfigObj()
\r
44 if os.path.isfile(path):
\r
45 config.filename = path
\r
47 #append the ini file to the plugin
\r
48 plugin_root = self.CommandsTree.AppendItem(tree_root, plugin, 0, data=wx.TreeItemData(config))
\r
50 plugin_root = self.CommandsTree.AppendItem(tree_root, plugin, 0)
\r
52 #add all commands to the tree
\r
53 for command in plugins[plugin]:
\r
54 command_label = command.replace('do_', '')
\r
55 #do not add the ini file to the command (we'll access the ini file of the plugin (ie parent) instead, see above)
\r
56 self.CommandsTree.AppendItem(plugin_root, command_label, 1)
\r
57 self.CommandsTree.Expand(plugin_root)
\r