forked from tim37021/Inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginLoader.py
48 lines (39 loc) · 1.32 KB
/
PluginLoader.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
class PluginLoader(object):
def __init__(self, path):
self._path = path
def install(self):
pass
@property
def uri(self):
return self._path
class QMLPluginLoader(PluginLoader):
def __init__(self, path):
PluginLoader.__init__(self, path)
class PythonPluginLoader(PluginLoader):
def __init__(self, path):
PluginLoader.__init__(self, path)
def install(self):
from PySide2.QtQml import qmlRegisterType
import importlib
pkg = importlib.import_module(self._path)
for export in pkg.qmlexports:
qmlRegisterType(
export['class'],
export['uri'],
export['major'],
export['minor'],
export['exportName']
)
def scan_plugins(folder, prefix=''):
import os
from os import listdir
ret = []
for fn in listdir(folder):
if os.path.isdir(os.path.join(folder, fn)):
if os.path.isfile(os.path.join(folder, fn, '__init__.py')):
ret.append(PythonPluginLoader('%s.%s'%(prefix, fn)))
elif os.path.isfile(os.path.join(folder, fn, 'qmldir')):
ret.append(QMLPluginLoader('%s.%s'%(prefix, fn)))
else:
ret += scan_plugins(os.path.join(folder, fn), fn)
return ret