Import plugins at startup to allow to modify/add widgets or any other stuff
This commit is contained in:
1 parent
60f876214c
commit
903ca05110
2 files changed
+11
-5
No files matched your search
+1
-1
@@ -15,6 +15,7 @@ from tryton.gui.window import FilesActions
|
||||
import re
|
||||
import base64
|
||||
import tryton.translate as translate
|
||||
import tryton.plugin
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
@@ -718,7 +719,6 @@ class Main(object):
|
||||
except_id=except_id)
|
||||
|
||||
def sig_plugin_execute(self, widget):
|
||||
import tryton.plugin
|
||||
page = self.notebook.get_current_page()
|
||||
datas = {
|
||||
'model': self.pages[page].model,
|
||||
|
||||
+10
-4
@@ -3,18 +3,24 @@ import os
|
||||
import imp
|
||||
|
||||
PLUGINS_PATH = os.path.join(os.path.dirname(__file__), 'plugins')
|
||||
MODULES = []
|
||||
|
||||
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]))
|
||||
MODULES.append(module)
|
||||
except Exception, exception:
|
||||
continue
|
||||
|
||||
def execute(datas, parent):
|
||||
result = {}
|
||||
|
||||
for plugin in os.listdir(PLUGINS_PATH):
|
||||
module = os.path.splitext(plugin)[0]
|
||||
for module in MODULES:
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user