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