Added inclusion logic to hooke.plugin
authorW. Trevor King <wking@drexel.edu>
Thu, 6 May 2010 12:37:52 +0000 (08:37 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 6 May 2010 12:37:52 +0000 (08:37 -0400)
hooke/__init__.py
hooke/hooke.py
hooke/plugin/__init__.py
hooke/plugin/autopeak.py
hooke/util/graph.py

index 694887e6bc884a28e36fc6f3f18ba94629b08644..7a2af6c25bb6af3d0f5fdef9958d9157e4fd3522 100644 (file)
@@ -1,3 +1,5 @@
+# COPYRIGHT
+
 """The hooke module does all the legwork for Hooke_ (BE).
 
 .. _hooke: http://code.google.com/p/hooke/
index 3d137f3c822955e3e5ea0cbe4c7732ed956bf12f..0bb6fc848d02d5a11ee9153bfb70ad1ff59a631c 100644 (file)
@@ -10,9 +10,8 @@ import Queue as queue
 import multiprocessing
 
 from . import config as config_mod
-from .plugin import PLUGINS
-from .driver import DRIVERS
-
+from . import plugin as plugin_mod
+from . import driver as driver_mod
 
 import copy
 import cStringIO
@@ -34,8 +33,8 @@ import time
 class Hooke(object):
     def __init__(self, config=None, debug=0):
         self.debug = debug
-        config_mod.DEFAULTS.extend(self.plugin_default_settings())
-        config_mod.DEFAULTS.extend(self.driver_default_settings())
+        config_mod.DEFAULTS.extend(plugin_mod.default_settings())
+        config_mod.DEFAULTS.extend(driver_mod.default_settings())
         if config == None:
             config = config_mod.HookeConfigParser(
                 paths=config_mod.DEFAULT_PATHS,
@@ -45,15 +44,15 @@ class Hooke(object):
         self.load_plugins()
         self.load_drivers()
 
-    def plugin_default_settings(self):
-        pass
-
     def driver_default_settings(self):
-        pass
+        settings = []
+        for driver in driver_mod.drivers:
+            settings.extend(driver_mod.default_settings(driver))
+        return settings
 
     def load_plugins(self):
-        pass
-
+        for plugin,value in self.config[plugins].items():
+        
     def load_drivers(self)
         pass
 
index a9f883737a8560d1da4a3144cfb0a62027784d38..b9e7988253342a3e061680d53c09a36bd804350a 100644 (file)
 #!/usr/bin/env python
-'''
-Commands and settings panel for Hooke
+"""The plugin module provides optional submodules that add new Hooke
+commands.
 
-Displays commands and settings for Hooke in a tree control
-(c) Dr. Rolf Schmidt, 2009
-'''
+All of the science happens in here.
+"""
 
-from configobj import ConfigObj
 import os.path
-from validate import Validator
-import wx
-
-import libhooke as lh
-
-class Commands(wx.Panel):
-
-    def __init__(self, parent):
-        # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
-        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))
-
-        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)
-        imglist = wx.ImageList(16, 16, True, 2)
-        imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))
-        imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_EXECUTABLE_FILE, wx.ART_OTHER, wx.Size(16, 16)))
-        self.CommandsTree.AssignImageList(imglist)
-        self.CommandsTree.AddRoot('Commands and Settings', 0)
-
-        self.ExecuteButton = wx.Button(self, -1, 'Execute')
-
-        sizer = wx.BoxSizer(wx.VERTICAL)
-        sizer.Add(self.CommandsTree, 1, wx.EXPAND)
-        sizer.Add(self.ExecuteButton, 0, wx.EXPAND)
-
-        self.SetSizer(sizer)
-        sizer.Fit(self)
-
-    def Initialize(self, plugins):
-        tree_root = self.CommandsTree.GetRootItem()
-        for plugin in plugins:
-            filename = ''.join([plugin, '.ini'])
-            path = lh.get_file_path(filename, ['plugins'])
-            config = ConfigObj()
-            if os.path.isfile(path):
-                config.filename = path
-                config.reload()
-                #append the ini file to the plugin
-                plugin_root = self.CommandsTree.AppendItem(tree_root, plugin, 0, data=wx.TreeItemData(config))
-            else:
-                plugin_root = self.CommandsTree.AppendItem(tree_root, plugin, 0)
-
-            #add all commands to the tree
-            for command in plugins[plugin]:
-                command_label = command.replace('do_', '')
-                #do not add the ini file to the command (we'll access the ini file of the plugin (ie parent) instead, see above)
-                self.CommandsTree.AppendItem(plugin_root, command_label, 1)
-            self.CommandsTree.Expand(plugin_root)
+
+from ..config import Setting
+from ..util.graph import Node, Graph
+
+PLUGIN_MODULES = [
+    ('autopeak', True),
+    ('curvetools', True),
+    ('cut', True),
+    ('fit', True),
+    ('flatfilts-rolf', True),
+    ('flatfilts', True),
+    ('generalclamp', True),
+    ('generaltccd', True),
+    ('generalvclamp', True),
+    ('jumpstat', True),
+    ('macro', True),
+    ('massanalysis', True),
+    ('multidistance', True),
+    ('multifit', True),
+    ('pcluster', True),
+    ('procplots', True),
+    ('review', True),
+    ('showconvoluted', True),
+    ('superimpose', True),
+    ('tutorial', True),
+    ('viewer', True),
+    ]
+"""List of plugin modules and whether they should be included by
+default.
+"""
+
+def Plugin (object):
+    """The pluggable collection of Hooke commands.
+
+    Fulfills the same role for Hooke that a software package does for
+    an operating system.
+    """
+    def dependencies(self):
+        """Return a list of Plugins we require."""
+        return []
+    def commands(self):
+        """Return a list of Commands provided."""
+        return []
+    def default_settings(self):
+        """Return a list of hooke.config.Settings() for any
+        configurable module settings."""
+        return []
+
+PLUGINS = {}
+"""(name,instance) :class:`dict` of all possible :class:`Plugin`\s.
+"""
+
+print __name__
+for plugin_modname,value in PLUGIN_MODULES:
+    this_mod = __import__(__name__, fromlist=[plugin_modname])
+    plugin_mod = getattr(this_mod, plugin_modname)
+    for objname in dir(plugin_mod):
+        obj = getattr(plugin_mod, objname)
+        if type(obj) == Plugin:
+            obj.module_name = plugin_modname
+            PLUGINS[p.name] = p
+
+PLUGIN_GRAPH = Graph([Node(
+            [PLUGINS[name] for name in p.dependencies()]
+            )])
+PLUGIN_GRAPH.topological_sort()
+
+#class Commands(wx.Panel):
+#
+#    def __init__(self, parent):
+#        # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
+#        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))
+#
+#        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)
+#        imglist = wx.ImageList(16, 16, True, 2)
+#        imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))
+#        imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_EXECUTABLE_FILE, wx.ART_OTHER, wx.Size(16, 16)))
+#        self.CommandsTree.AssignImageList(imglist)
+#        self.CommandsTree.AddRoot('Commands and Settings', 0)
+#
+#        self.ExecuteButton = wx.Button(self, -1, 'Execute')
+#
+#        sizer = wx.BoxSizer(wx.VERTICAL)
+#        sizer.Add(self.CommandsTree, 1, wx.EXPAND)
+#        sizer.Add(self.ExecuteButton, 0, wx.EXPAND)
+#
+#        self.SetSizer(sizer)
+#        sizer.Fit(self)
+#
+#    def Initialize(self, plugins):
+#        tree_root = self.CommandsTree.GetRootItem()
+#        for plugin in plugins:
+#            filename = ''.join([plugin, '.ini'])
+#            path = lh.get_file_path(filename, ['plugins'])
+#            config = ConfigObj()
+#            if os.path.isfile(path):
+#                config.filename = path
+#                config.reload()
+#                #append the ini file to the plugin
+#                plugin_root = self.CommandsTree.AppendItem(tree_root, plugin, 0, data=wx.TreeItemData(config))
+#            else:
+#                plugin_root = self.CommandsTree.AppendItem(tree_root, plugin, 0)
+#
+#            #add all commands to the tree
+#            for command in plugins[plugin]:
+#                command_label = command.replace('do_', '')
+#                #do not add the ini file to the command (we'll access the ini file of the plugin (ie parent) instead, see above)
+#                self.CommandsTree.AppendItem(plugin_root, command_label, 1)
+#            self.CommandsTree.Expand(plugin_root)
+
+def default_settings(self):
+    settings = [Setting(
+            'plugins', help='Enable/disable default plugins.')]
+    for pnode in PLUGIN_GRAPH:
+        settings.append(Setting(p.name, str(PLUGIN_MODULES[p.module_name][1])))      
+    for pnode in PLUGIN_GRAPH:
+        plugin = pnode.data
+        settings.extend(plugin.default_settings())
+    return settings
+
+class Command (object):
+    pass
index ab6117e5c60c80a62eeabb3d1dd206267524b7bf..dee9e8807784c02818879f6551b2a71618fad01e 100644 (file)
@@ -1,4 +1,10 @@
 # -*- coding: utf-8 -*-
+# COPYRIGHT
+
+"""The autopeak module provides :class:`Autopeak`, a
+:class:`hooke.plugin.Plugin` for automatically extracting force peaks
+(unfolding events) from force curves.
+"""
 
 from hooke.libhooke import WX_GOOD
 
@@ -331,3 +337,4 @@ class autopeakCommands(object):
 
         f.close()
         self.do_note('autopeak')
+
index bf7432edbb03b53ced70549366816a08088348a3..9e5ee9532b68b8415d308e9addd4e5e5ca303628 100644 (file)
@@ -1,6 +1,8 @@
 # COPYRIGHT
 
 """Define :class:`Graph`, a directed, acyclic graph structure.
+:class:`Graph`\s are composed of :class:`Node`\s, also defined by this
+module.
 """
 
 import bisect