testbuttonplugin.py
2.5 KB
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
# TODO: CAMPid 0970432108721340872130742130870874321
import importlib
import pkg_resources
major = None
def import_it(*segments):
global major
if major is None:
options = [5, 6]
else:
options = [major]
error = None
for major in options:
# TODO: this is not great but the plugin gets imported directly rather
# than as part of the module so... could add some code here on
# build or something. but yeah, all kind of a mess. require an
# env var be set, etc.
try:
m = {
"pyqt_tools": "pyqt{major}_tools".format(major=major),
"pyqt_plugins": "pyqt{major}_plugins".format(major=major),
"qt_tools": "qt{major}_tools".format(major=major),
"qt_applications": "qt{major}_applications".format(major=major),
"PyQt": "PyQt{major}".format(major=major),
}
majored = [m[segments[0]], *segments[1:]]
return importlib.import_module(".".join(majored))
except ModuleNotFoundError as e:
if error is None:
error = e
continue
else:
raise e from error
qt_tools = import_it("qt_tools")
QtGui = import_it("PyQt", "QtGui")
QtDesigner = import_it("PyQt", "QtDesigner")
pyqt_plugins = import_it("pyqt_plugins")
import_it("pyqt_plugins", "tests", "testbutton")
class TestButtonPlugin(QtDesigner.QPyDesignerCustomWidgetPlugin):
# https://wiki.python.org/moin/PyQt/Using_Python_Custom_Widgets_in_Qt_Designer
def __init__(self, parent=None):
super().__init__(parent=parent)
self.initialized = False
def initialize(self, core):
if self.initialized:
return
self.initialized = True
def isInitialized(self):
return self.initialized
def createWidget(self, parent):
return pyqt_plugins.tests.testbutton.TestButton(parent)
def name(self):
return pyqt_plugins.tests.testbutton.TestButton.__name__
def group(self):
return 'pyqt{}-tools'.format(major)
def icon(self):
return QtGui.QIcon()
def toolTip(self):
return 'pyqt{}-tools Test Button Tool Tip'.format(major)
def whatsThis(self):
return 'pyqt{}-tools Test Button What\'s this'.format(major)
def isContainer(self):
return False
def includeFile(self):
return 'pyqt{}_plugins.tests.testbutton'.format(major)