-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyqt.py
64 lines (54 loc) · 1.64 KB
/
myqt.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
# -*- coding: utf-8 -*-
"""
Helper for import PyQt5/PtQt4
see
http://mikeboers.com/blog/2015/07/04/static-libraries-in-a-dynamic-world#the-fold
"""
class ModuleProxy(object):
def __init__(self, prefixes, modules):
self.prefixes = prefixes
self.modules = modules
def __getattr__(self, name):
for prefix in self.prefixes:
fullname = prefix + name
for module in self.modules:
obj = getattr(module, fullname, None)
if obj is not None:
setattr(self, name, obj) # cache it
return obj
raise AttributeError(name)
from PyQt5 import QtCore, QtGui, QtWidgets
QT_MODE = None
try:
import PyQt5
from PyQt5 import QtCore, QtGui, QtWidgets
QT_MODE = 'PyQt5'
except :
try:
import PyQt4
from PyQt4 import QtCore, QtGui
QT_MODE = 'PyQt4'
except ImportError:
print('no PyQt5/PyQt4')
if QT_MODE == 'PyQt5':
#~ from PyQt5 import QtCore, QtGui, QtWidgets
QT = ModuleProxy(['', 'Q', 'Qt'], [QtCore.Qt, QtCore, QtGui, QtWidgets])
elif QT_MODE == 'PyQt4':
#~ from PyQt4 import QtCore, QtGui
QT = ModuleProxy(['', 'Q', 'Qt'], [QtCore.Qt, QtCore, QtGui])
else:
QT = None
if QT is not None:
from pyqtgraph import mkQApp
def DebugDecorator(func):
def wrapper(*args, **kargs):
#~ print('DebugDecorator', *args, *kargs)
try:
ret = func(*args, **kargs)
return ret
except Exception as e:
print('#'*20)
print('# ERROR IN {}'.format(func) * 5 )
print('#', e)
print('#'*20)
return wrapper