Skip to content

Commit 281cb42

Browse files
committed
Drop support for PyQt4 and PySide
1 parent 81c72c4 commit 281cb42

File tree

2 files changed

+18
-123
lines changed

2 files changed

+18
-123
lines changed

src/Display/backend.py

Lines changed: 16 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
# backend constants
44
WX = "wx"
5-
PYSIDE = "qt-pyside"
65
PYSIDE2 = "qt-pyside2"
7-
PYQT4 = "qt-pyqt4"
86
PYQT5 = "qt-pyqt5"
97

108
# backend module
11-
HAVE_PYQT5, HAVE_PYQT4, HAVE_PYSIDE, HAVE_PYSIDE2, HAVE_WX = False, False, False, False, False
9+
HAVE_PYQT5, HAVE_PYSIDE2, HAVE_WX = False, False, False
1210

1311
# is any backend imported?
1412
HAVE_BACKEND = False
@@ -35,42 +33,6 @@ def load_pyqt5():
3533
return HAVE_PYQT5
3634

3735

38-
def load_pyqt4():
39-
""" returns True is PyQt4 found, else False
40-
"""
41-
global HAVE_PYQT4, QtCore, QtGui, QtWidgets, QtOpenGL
42-
43-
# backend already loaded, dont load another one
44-
if loaded_backend():
45-
return False
46-
47-
try:
48-
from PyQt4 import QtCore, QtGui, QtOpenGL
49-
QtWidgets = QtGui
50-
HAVE_PYQT4 = True
51-
except ImportError:
52-
HAVE_PYQT4 = False
53-
return HAVE_PYQT4
54-
55-
56-
def load_pyside():
57-
""" returns True is PySide found, else False
58-
"""
59-
global HAVE_PYSIDE, QtCore, QtGui, QtWidgets, QtOpenGL
60-
61-
# backend already loaded, dont load another one
62-
if loaded_backend():
63-
return False
64-
65-
try:
66-
from PySide import QtCore, QtGui, QtOpenGL
67-
QtWidgets = QtGui
68-
HAVE_PYSIDE = True
69-
except ImportError:
70-
HAVE_PYSIDE = False
71-
return HAVE_PYSIDE
72-
73-
7436
def load_pyside2():
7537
""" returns True is PySide2 found, else False
7638
"""
@@ -115,47 +77,38 @@ def get_loaded_backend():
11577

11678
def load_any_qt_backend():
11779
""" loads any qt based backend. First try to load
118-
PyQt5, then PyQt4 and finally PySide. Raise an exception
119-
if none of them are available
80+
PyQt5, then PySide2. Raise an exception if none of them are available
12081
"""
12182
pyqt5_loaded = False
122-
pyqt4_loaded = False
123-
pyside_loaded = False
12483
# by default, load PyQt5
12584
pyqt5_loaded = load_backend(PYQT5)
12685
if not pyqt5_loaded:
127-
# load pyqt4
128-
pyqt4_loaded = load_backend(PYQT4)
129-
# finally try to load pyside
130-
if not pyqt4_loaded:
131-
pyside2_loaded = load_backend(PYSIDE2)
132-
if not pyside2_loaded:
133-
pyside_loaded = load_backend(PYSIDE)
134-
if not (pyqt5_loaded or pyqt4_loaded or pyside2_loaded or pyside_loaded):
135-
raise AssertionError("None of the PyQt5, PtQt4, PySide2 or PySide backend can be loaded")
86+
pyside2_loaded = load_backend(PYSIDE2)
87+
if not (pyqt5_loaded or pyside2_loaded):
88+
raise AssertionError("None of the PyQt5 or PySide2 can be loaded")
13689
else:
13790
return True
13891

13992

14093
def load_backend(backend_str=None):
14194
""" loads a gui backend
14295
143-
If no Qt (such as PyQt5, PyQt4 or PySide) backend is found, wx is loaded
96+
If no Qt backend is found (PyQt5 or PySide), wx is loaded
14497
14598
The search order for pythonocc compatible gui modules is:
146-
PyQt5, PyQt4, PySide2, PySide, Wx
99+
PyQt5, PySide2, wx
147100
148101
Note
149102
----
150-
Wx is imported when no Qt backend is found.
103+
wx is imported when no Qt backend is found.
151104
152105
Parameters
153106
----------
154107
backend_str : str
155108
156109
specifies which backend to load
157110
158-
backend_str is one of ( "qt-pyqt5", "qt-pyqt4", ""qt-pyside2", qt-pyside", "wx" )
111+
backend_str is one of ( "qt-pyqt5", "qt-pyside2", "wx" )
159112
160113
if no value has been set, load the first module in gui module search
161114
order
@@ -164,7 +117,7 @@ def load_backend(backend_str=None):
164117
-------
165118
str
166119
the name of the loaded backend
167-
one of ( "qt-pyqt5", "qt-pyqt4", "qt-pyside2", "qt-pyside", "wx" )
120+
one of ( "qt-pyqt5", "qt-pyside2", "wx" )
168121
169122
Raises
170123
------
@@ -186,7 +139,7 @@ def load_backend(backend_str=None):
186139
return BACKEND_MODULE
187140

188141
if backend_str is not None:
189-
compatible_backends = (PYQT5, PYQT4, PYSIDE2, PYSIDE, WX)
142+
compatible_backends = (PYQT5, PYSIDE2, WX)
190143
if not backend_str in compatible_backends:
191144
msg = "incompatible backend_str specified: {0}\n" \
192145
"backend is one of : {1}".format(backend_str,
@@ -204,22 +157,6 @@ def load_backend(backend_str=None):
204157
msg = "{0} backend could not be loaded".format(backend_str)
205158
log.exception(msg)
206159
raise ValueError(msg)
207-
else:
208-
pass
209-
210-
if backend_str == PYQT4 or (backend_str is None and not HAVE_BACKEND):
211-
if load_pyqt4():
212-
HAVE_BACKEND = True
213-
BACKEND_MODULE = 'qt-pyqt4'
214-
log.info("backend loaded: {0}".format(BACKEND_MODULE))
215-
return BACKEND_MODULE
216-
elif backend_str == PYQT4 and not HAVE_BACKEND:
217-
msg = "{0} backend could not be loaded".format(backend_str)
218-
log.exception(msg)
219-
raise ValueError(msg)
220-
221-
else:
222-
pass
223160

224161
if backend_str == PYSIDE2 or (backend_str is None and not HAVE_BACKEND):
225162
if load_pyside2():
@@ -231,21 +168,6 @@ def load_backend(backend_str=None):
231168
msg = "{0} could not be loaded".format(backend_str)
232169
log.exception(msg)
233170
raise ValueError(msg)
234-
else:
235-
pass
236-
237-
if backend_str == PYSIDE or (backend_str is None and not HAVE_BACKEND):
238-
if load_pyside():
239-
HAVE_BACKEND = True
240-
BACKEND_MODULE = 'qt-pyside'
241-
log.info("backend loaded: {0}".format(BACKEND_MODULE))
242-
return BACKEND_MODULE
243-
elif backend_str == PYSIDE and not HAVE_BACKEND:
244-
msg = "{0} backend could not be loaded".format(backend_str)
245-
log.exception(msg)
246-
raise ValueError(msg)
247-
else:
248-
pass
249171

250172
if backend_str == WX or (backend_str is None and not HAVE_BACKEND):
251173
if load_wx():
@@ -257,13 +179,10 @@ def load_backend(backend_str=None):
257179
msg = "{0} backend could not be loaded".format(backend_str)
258180
log.exception(msg)
259181
raise ValueError(msg)
260-
else:
261-
pass
262182

263183
if not HAVE_BACKEND:
264184
raise ImportError("No compliant GUI library could be imported.\n"
265-
"Either PyQt5, PyQt4, PySide2, PySide, or wxPython "
266-
"is required")
185+
"Either PyQt5, PPySide2 or wxPython is required")
267186

268187

269188
def get_qt_modules():
@@ -272,7 +191,7 @@ def get_qt_modules():
272191
Returns
273192
-------
274193
tuple : ( QtCore, QtGui, QtWidgets, QtOpenGL )
275-
here QtWidgets shadows QtGui when a PyQt4 or PySide module is loaded
194+
here QtWidgets shadows QtGui when a PySide module is loaded
276195
this is the most coherent way to get PyQt5 compliant code
277196
278197
Raises
@@ -281,20 +200,20 @@ def get_qt_modules():
281200
ValueError
282201
when no Qt backend has been yet loaded
283202
informs the user to call `load_backend` or that no Qt python module
284-
( PyQt5, PyQt4 or PySide ) is found
203+
( PyQt5, PySide ) is found
285204
286205
"""
287206
if not HAVE_BACKEND:
288207
raise ValueError("no backend has been imported yet with "
289208
"``load_backend``... ")
290209

291-
if HAVE_PYQT5 or HAVE_PYQT4 or HAVE_PYSIDE2 or HAVE_PYSIDE:
210+
if HAVE_PYQT5 or HAVE_PYSIDE2:
292211
return QtCore, QtGui, QtWidgets, QtOpenGL
293212
elif HAVE_WX:
294213
raise ValueError("the Wx backend is already loaded")
295214
else:
296215
msg = ("no Qt backend is loaded, hence cannot return any modules\n"
297-
"either you havent got PyQt5, PyQt4, PySide2 or PySide installed\n"
216+
"either you havent got PyQt5 or PySide2 installed\n"
298217
"or you havent yet loaded a backend with the "
299218
"`OCC.Display.backend.load_backend` function")
300219
raise ValueError(msg)

src/Display/qtDisplay.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,6 @@ def __init__(self, parent=None):
5555

5656
self.setAutoFillBackground(False)
5757

58-
def GetHandle(self):
59-
''' returns an the identifier of the GUI widget.
60-
It must be an integer
61-
'''
62-
win_id = self.winId() # this returns either an int or voitptr
63-
if "%s" % type(win_id) == "<type 'PyCObject'>": # PySide
64-
### with PySide, self.winId() does not return an integer
65-
if sys.platform == "win32":
66-
## Be careful, this hack is py27 specific
67-
## does not work with python31 or higher
68-
## since the PyCObject api was changed
69-
ctypes.pythonapi.PyCObject_AsVoidPtr.restype = ctypes.c_void_p
70-
ctypes.pythonapi.PyCObject_AsVoidPtr.argtypes = [ctypes.py_object]
71-
win_id = ctypes.pythonapi.PyCObject_AsVoidPtr(win_id)
72-
elif not isinstance(win_id, int): # PyQt4 or 5
73-
## below integer cast may be required because self.winId() can
74-
## returns a sip.voitptr according to the PyQt version used
75-
## as well as the python version
76-
win_id = int(win_id)
77-
return win_id
78-
7958
def resizeEvent(self, event):
8059
super(qtBaseViewer, self).resizeEvent(event)
8160
self._display.View.MustBeResized()
@@ -120,7 +99,7 @@ def qApp(self, value):
12099
self._qApp = value
121100

122101
def InitDriver(self):
123-
self._display.Create(window_handle=self.GetHandle(), parent=self)
102+
self._display.Create(window_handle=int(self.winId()), parent=self)
124103
# background gradient
125104
self._display.SetModeShaded()
126105
self._inited = True
@@ -183,10 +162,7 @@ def paintEvent(self, event):
183162
painter.drawRect(rect)
184163

185164
def wheelEvent(self, event):
186-
try: # PyQt4/PySide
187-
delta = event.delta()
188-
except: # PyQt5
189-
delta = event.angleDelta().y()
165+
delta = event.angleDelta().y()
190166
if delta > 0:
191167
zoom_factor = 2.
192168
else:

0 commit comments

Comments
 (0)