From: Aiwota Programmer Date: Fri, 29 Sep 2006 00:01:06 +0000 (+0900) Subject: Add BoardPluginBase and export widget_tree. X-Git-Tag: v0.2~3 X-Git-Url: http://git.sourceforge.jp/view?p=fukui-no-namari%2Ffukui-no-namari.git;a=commitdiff_plain;h=e0b80d63e09b198874e60ec01ab6a54b5e81fd1c Add BoardPluginBase and export widget_tree. --- diff --git a/src/FukuiNoNamari/board_plugin_base.py b/src/FukuiNoNamari/board_plugin_base.py new file mode 100644 index 0000000..84886b4 --- /dev/null +++ b/src/FukuiNoNamari/board_plugin_base.py @@ -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 diff --git a/src/FukuiNoNamari/board_plugins.py b/src/FukuiNoNamari/board_plugins.py index 8e1cd73..13f00e3 100644 --- a/src/FukuiNoNamari/board_plugins.py +++ b/src/FukuiNoNamari/board_plugins.py @@ -22,9 +22,10 @@ import traceback import itertools import config +from board_plugin_base import BoardPluginBase base_path = os.path.join(config.get_config_dir_path(), "scripts") -version = (0, 1) +version = (0, 2) def generate_board_plugin(): plugin_list = [] @@ -52,16 +53,20 @@ def check_compatible(plugin_version): 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): - 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() -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 diff --git a/src/FukuiNoNamari/board_window.py b/src/FukuiNoNamari/board_window.py index 2e5eef6..97bb3e6 100644 --- a/src/FukuiNoNamari/board_window.py +++ b/src/FukuiNoNamari/board_window.py @@ -87,7 +87,7 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData): 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() @@ -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.menu_edit = self.widget_tree.get_widget("menu_edit").get_submenu() def set_status(self, text): self.statusbar.set_status(text)