2 """The plugin module provides optional submodules that add new Hooke
5 All of the science happens in here.
10 from ..config import Setting
11 from ..util.graph import Node, Graph
18 ('flatfilts-rolf', True),
20 ('generalclamp', True),
21 ('generaltccd', True),
22 ('generalvclamp', True),
25 ('massanalysis', True),
26 ('multidistance', True),
31 ('showconvoluted', True),
32 ('superimpose', True),
36 """List of plugin modules and whether they should be included by
41 """The pluggable collection of Hooke commands.
43 Fulfills the same role for Hooke that a software package does for
46 def dependencies(self):
47 """Return a list of Plugins we require."""
50 """Return a list of Commands provided."""
52 def default_settings(self):
53 """Return a list of hooke.config.Settings() for any
54 configurable module settings."""
58 """(name,instance) :class:`dict` of all possible :class:`Plugin`\s.
62 for plugin_modname,value in PLUGIN_MODULES:
63 this_mod = __import__(__name__, fromlist=[plugin_modname])
64 plugin_mod = getattr(this_mod, plugin_modname)
65 for objname in dir(plugin_mod):
66 obj = getattr(plugin_mod, objname)
67 if type(obj) == Plugin:
68 obj.module_name = plugin_modname
71 PLUGIN_GRAPH = Graph([Node(
72 [PLUGINS[name] for name in p.dependencies()]
74 PLUGIN_GRAPH.topological_sort()
76 #class Commands(wx.Panel):
78 # def __init__(self, parent):
79 # # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
80 # wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))
82 # 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)
83 # imglist = wx.ImageList(16, 16, True, 2)
84 # imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))
85 # imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_EXECUTABLE_FILE, wx.ART_OTHER, wx.Size(16, 16)))
86 # self.CommandsTree.AssignImageList(imglist)
87 # self.CommandsTree.AddRoot('Commands and Settings', 0)
89 # self.ExecuteButton = wx.Button(self, -1, 'Execute')
91 # sizer = wx.BoxSizer(wx.VERTICAL)
92 # sizer.Add(self.CommandsTree, 1, wx.EXPAND)
93 # sizer.Add(self.ExecuteButton, 0, wx.EXPAND)
95 # self.SetSizer(sizer)
98 # def Initialize(self, plugins):
99 # tree_root = self.CommandsTree.GetRootItem()
100 # for plugin in plugins:
101 # filename = ''.join([plugin, '.ini'])
102 # path = lh.get_file_path(filename, ['plugins'])
103 # config = ConfigObj()
104 # if os.path.isfile(path):
105 # config.filename = path
107 # #append the ini file to the plugin
108 # plugin_root = self.CommandsTree.AppendItem(tree_root, plugin, 0, data=wx.TreeItemData(config))
110 # plugin_root = self.CommandsTree.AppendItem(tree_root, plugin, 0)
112 # #add all commands to the tree
113 # for command in plugins[plugin]:
114 # command_label = command.replace('do_', '')
115 # #do not add the ini file to the command (we'll access the ini file of the plugin (ie parent) instead, see above)
116 # self.CommandsTree.AppendItem(plugin_root, command_label, 1)
117 # self.CommandsTree.Expand(plugin_root)
119 def default_settings(self):
121 'plugins', help='Enable/disable default plugins.')]
122 for pnode in PLUGIN_GRAPH:
123 settings.append(Setting(p.name, str(PLUGIN_MODULES[p.module_name][1])))
124 for pnode in PLUGIN_GRAPH:
126 settings.extend(plugin.default_settings())
129 class Command (object):