OSDN Git Service

Add BoardPluginBase and export widget_tree.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 29 Sep 2006 00:01:06 +0000 (09:01 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 29 Sep 2006 00:39:11 +0000 (09:39 +0900)
src/FukuiNoNamari/board_plugin_base.py [new file with mode: 0644]
src/FukuiNoNamari/board_plugins.py
src/FukuiNoNamari/board_window.py

diff --git a/src/FukuiNoNamari/board_plugin_base.py b/src/FukuiNoNamari/board_plugin_base.py
new file mode 100644 (file)
index 0000000..84886b4
--- /dev/null
@@ -0,0 +1,30 @@
+# Copyright (C) 2006 by Aiwota Programmer
+# aiwotaprog@tetteke.tk
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+
+# base class for Board Plugin
+class BoardPluginBase:
+
+    # second argument is GtkTreeView widget
+    # third argument is GtkMenuItem widget
+    def __init__(self, widget_tree):
+        self.widget_tree = widget_tree
+        self.initialize()
+
+    # please override
+    def initialize(self):
+        pass
index 8e1cd73..13f00e3 100644 (file)
@@ -22,9 +22,10 @@ import traceback
 import itertools
 
 import config
 import itertools
 
 import config
+from board_plugin_base import BoardPluginBase
 
 base_path = os.path.join(config.get_config_dir_path(), "scripts")
 
 base_path = os.path.join(config.get_config_dir_path(), "scripts")
-version = (0, 1)
+version = (0, 2)
 
 def generate_board_plugin():
     plugin_list = []
 
 def generate_board_plugin():
     plugin_list = []
@@ -52,16 +53,20 @@ def check_compatible(plugin_version):
     else:
         return version[1] <= plugin_version[1]
 
     else:
         return version[1] <= plugin_version[1]
 
-def load_plugin(plugin_module, treeview, menuitem):
+def load_plugin(plugin_module, widget_tree):
     try:
         if check_compatible(plugin_module.version):
     try:
         if check_compatible(plugin_module.version):
-            plugin_module.BoardPlugin(treeview, menuitem)
+            klass = plugin_module.BoardPlugin
+            if issubclass(klass, BoardPluginBase):
+                klass(widget_tree)
+            else:
+                print klass, "is not subclass of BoardPluginBase"
         else:
             print plugin_module.__file__, "not compatible", \
                   plugin_module.version
     except:
         traceback.print_exc()
     
         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),
+def load(widget_tree):
+    for i in itertools.imap(lambda e: load_plugin(e, widget_tree),
                             generate_board_plugin()): -1
                             generate_board_plugin()): -1
index 2e5eef6..97bb3e6 100644 (file)
@@ -87,7 +87,7 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
         self.treeview.set_fixed_height_mode(True)
 
         # menu plugins
         self.treeview.set_fixed_height_mode(True)
 
         # menu plugins
-        board_plugins.load(self.treeview, self.menu_edit)
+        board_plugins.load(self.widget_tree)
 
         self.restore()
         self.window.show()
 
         self.restore()
         self.window.show()
@@ -104,7 +104,6 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
         self.filterbar = self.widget_tree.get_widget(
             "bonobodockitem_filterbar")
         self.entry_filterbar = self.widget_tree.get_widget("entry_filterbar")
         self.filterbar = self.widget_tree.get_widget(
             "bonobodockitem_filterbar")
         self.entry_filterbar = self.widget_tree.get_widget("entry_filterbar")
-        self.menu_edit = self.widget_tree.get_widget("menu_edit").get_submenu()
 
     def set_status(self, text):
         self.statusbar.set_status(text)
 
     def set_status(self, text):
         self.statusbar.set_status(text)