From 1252a17f267203ae758545c855f9465da1d2e256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 6 Feb 2008 22:19:35 +0100 Subject: [PATCH] Add plugin and workflow plugin --- tryton/gui/main.py | 4 ++-- tryton/gui/window/tree.py | 4 ++++ tryton/gui/window/view_tree/view_tree.py | 12 +++--------- tryton/plugin.py | 25 ++++++++++++++++++++++++ tryton/plugins/workflow/__init__.py | 19 ++++++++++++++++++ 5 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 tryton/plugin.py create mode 100644 tryton/plugins/workflow/__init__.py diff --git a/tryton/gui/main.py b/tryton/gui/main.py index 69a1198621..e4bd56d8e4 100644 --- a/tryton/gui/main.py +++ b/tryton/gui/main.py @@ -753,14 +753,14 @@ class Main(object): except_id=except_id) def sig_plugin_execute(self, widget): - import plugins + import tryton.plugin page = self.notebook.get_current_page() datas = { 'model': self.pages[page].model, 'ids': self.pages[page].ids_get(), 'id': self.pages[page].id_get(), } - plugins.execute(datas) + tryton.plugin.execute(datas, self.window) @staticmethod def sig_quit(widget): diff --git a/tryton/gui/window/tree.py b/tryton/gui/window/tree.py index 8640b8e7bd..8d6f9c34f5 100644 --- a/tryton/gui/window/tree.py +++ b/tryton/gui/window/tree.py @@ -237,6 +237,10 @@ class Tree(SignalEvent): res = self.tree_res.sel_ids_get() return res + def id_get(self): + res = self.tree_res.sel_id_get() + return res + def sig_save_as(self, widget=None): win = WinExport(self.model, self.ids_get(), self.tree_res.fields, [], parent=self.window, diff --git a/tryton/gui/window/view_tree/view_tree.py b/tryton/gui/window/view_tree/view_tree.py index 9976a14950..cb954ec786 100644 --- a/tryton/gui/window/view_tree/view_tree.py +++ b/tryton/gui/window/view_tree/view_tree.py @@ -332,15 +332,9 @@ class ViewTree(object): return [int(model.get_value(model.get_iter(x), 0)) for x in iters] def sel_id_get(self): - sel = self.view.get_selection().get_selected() - if sel == None: - return None - (model, i) = sel - if not i: - return None - res = model.get_value(i, 0) - if res != None: - return int(res) + res = self.sel_ids_get() + if res: + res = res[0] return res def value_get(self, col): diff --git a/tryton/plugin.py b/tryton/plugin.py new file mode 100644 index 0000000000..9db0c3beeb --- /dev/null +++ b/tryton/plugin.py @@ -0,0 +1,25 @@ +import common +import os +import imp + +PLUGINS_PATH = os.path.join(os.path.dirname(__file__), 'plugins') + +def execute(datas, parent): + result = {} + + for plugin in os.listdir(PLUGINS_PATH): + module = os.path.splitext(plugin)[0] + try: + module = imp.load_module(module, *imp.find_module(module, [PLUGINS_PATH])) + for name, func in module.get_plugins(datas['model']): + result[name] = func + except Exception, exception: + print exception + continue + if not result: + common.message(_('No available plugin for this resource!'), parent) + return False + res = common.selection(_('Choose a Plugin'), result, parent, alwaysask=True) + if res: + res[1](datas, parent) + return True diff --git a/tryton/plugins/workflow/__init__.py b/tryton/plugins/workflow/__init__.py new file mode 100644 index 0000000000..c2783d01c3 --- /dev/null +++ b/tryton/plugins/workflow/__init__.py @@ -0,0 +1,19 @@ +from tryton.action import Action + +def workflow_print(datas, parent): + datas = datas.copy() + datas['nested'] = False + Action.exec_report('workflow.instance.graph', datas) + return True + +def workflow_print_complex(datas, parent): + datas = datas.copy() + datas['nested'] = True + Action.exec_report('workflow.instance.graph', datas) + return True + +def get_plugins(model): + return [ + (_('Print Workflow'), workflow_print), + (_('Print Workflow (Complex)'), workflow_print_complex), + ]