forked from gdassori/BitcoinAVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins.py
105 lines (73 loc) · 2.55 KB
/
plugins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from util import print_error
import traceback, sys
from util import *
from i18n import _
plugins = []
def init_plugins(self):
import imp, pkgutil, __builtin__, os
global plugins
if __builtin__.use_local_modules:
fp, pathname, description = imp.find_module('plugins')
plugin_names = [name for a, name, b in pkgutil.iter_modules([pathname])]
plugin_names = filter( lambda name: os.path.exists(os.path.join(pathname,name+'.py')), plugin_names)
imp.load_module('electrum_plugins', fp, pathname, description)
plugin_modules = map(lambda name: imp.load_source('electrum_plugins.'+name, os.path.join(pathname,name+'.py')), plugin_names)
else:
import electrum_plugins
plugin_names = [name for a, name, b in pkgutil.iter_modules(electrum_plugins.__path__)]
plugin_modules = [ __import__('electrum_plugins.'+name, fromlist=['electrum_plugins']) for name in plugin_names]
for name, p in zip(plugin_names, plugin_modules):
try:
plugins.append( p.Plugin(self, name) )
except Exception:
print_msg(_("Error: cannot initialize plugin"),p)
traceback.print_exc(file=sys.stdout)
def run_hook(name, *args):
global plugins
for p in plugins:
if not p.is_enabled():
continue
f = getattr(p, name, None)
if not callable(f):
continue
try:
f(*args)
except Exception:
print_error("Plugin error")
traceback.print_exc(file=sys.stdout)
return
class BasePlugin:
def __init__(self, gui, name):
self.gui = gui
self.name = name
self.config = gui.config
def fullname(self):
return self.name
def description(self):
return 'undefined'
def requires_settings(self):
return False
def toggle(self):
if self.is_enabled():
if self.disable():
self.close()
else:
if self.enable():
self.init()
return self.is_enabled()
def enable(self):
self.set_enabled(True)
return True
def disable(self):
self.set_enabled(False)
return True
def init(self): pass
def close(self): pass
def is_enabled(self):
return self.is_available() and self.config.get('use_'+self.name) is True
def is_available(self):
return True
def set_enabled(self, enabled):
self.config.set_key('use_'+self.name, enabled, True)
def settings_dialog(self):
pass