OSDN Git Service

Add board plugin.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Mon, 18 Sep 2006 03:49:45 +0000 (12:49 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Mon, 18 Sep 2006 03:49:45 +0000 (12:49 +0900)
src/FukuiNoNamari/board_plugins.py [new file with mode: 0644]
src/FukuiNoNamari/board_window.py

diff --git a/src/FukuiNoNamari/board_plugins.py b/src/FukuiNoNamari/board_plugins.py
new file mode 100644 (file)
index 0000000..46f3b4a
--- /dev/null
@@ -0,0 +1,50 @@
+import os.path
+from glob import glob
+import imp
+import traceback
+import itertools
+
+import config
+
+base_path = os.path.join(config.get_config_dir_path(), "scripts")
+version = (0, 1)
+
+def generate_board_plugin():
+    plugin_list = []
+    for module_path in glob(os.path.join(base_path, "board_*.py")):
+        module_name, ext = os.path.splitext(os.path.basename(module_path))
+        try:
+            try:
+                file, filename, description = imp.find_module(
+                    module_name, [base_path])
+                module = imp.load_module(
+                    module_name, file, filename, description)
+            finally:
+                if file:
+                    file.close()
+        except ImportError:
+            traceback.print_exc()
+        else:
+            yield module
+
+def check_compatible(plugin_version):
+    if version[0] > plugin_version[0]:
+        return False
+    elif version[0] < plugin_version[0]:
+        return True
+    else:
+        return version[1] <= plugin_version[1]
+
+def load_plugin(plugin_module, treeview, menuitem):
+    try:
+        if check_compatible(plugin_module.version):
+            plugin_module.BoardPlugin(treeview, menuitem)
+        else:
+            print plugin_module.__file__, "not compatible", \
+                  plugin_module.version
+    except:
+        traceback.print_exc()
+    
+def load(treeview, menuitem):
+    for i in itertools.imap(lambda e: load_plugin(e, treeview, menuitem),
+                            generate_board_plugin()): -1
index 3478f1b..f0745d6 100644 (file)
@@ -37,6 +37,7 @@ import winwrapbase
 from misc import ThreadInvoker
 import bookmark_list
 import bookmark_window
+import board_plugins
 
 GLADE_FILENAME = "board_window.glade"
 
@@ -131,6 +132,10 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
                   "on_popup_menu_open_activate": self.on_open_thread}
         self.widget_tree.signal_autoconnect(sigdic)
 
+        # menu plugins
+        self.edit1 = self.widget_tree.get_widget("edit1").get_submenu()
+        board_plugins.load(self.treeview, self.edit1)
+
         self.restore()
         self.window.show()