106
106
107
107
import sys
108
108
109
+ failures = {}
110
+ found = False
111
+
109
112
try :
110
113
# try PyQt5
111
114
from PyQt5 .QtCore import (
112
115
QCoreApplication , QEventLoop , QObject , QSocketNotifier , QTimer ,
113
116
)
114
- except ImportError as e0 :
115
- try :
116
- # try PySide2
117
- from PySide2 .QtCore import (
118
- QCoreApplication , QEventLoop , QObject , QSocketNotifier , QTimer ,
119
- )
120
- except ImportError as e1 :
121
- raise ImportError (
122
- "Neither PyQt5 nor PySide2 installed.\n PyQt5: {}\n PySide2: {})" .format (e0 , e1 )
123
- )
117
+ except ImportError as e :
118
+ failures ["PyQt5" ] = e
119
+ else :
120
+ found = True
121
+
122
+ try :
123
+ # try PyQt6
124
+ from PyQt6 .QtCore import (
125
+ QCoreApplication , QEventLoop , QObject , QSocketNotifier , QTimer ,
126
+ )
127
+ except ImportError as e :
128
+ failures ["PyQt6" ] = e
129
+ else :
130
+ found = True
131
+
132
+ try :
133
+ # try PySide2
134
+ from PySide2 .QtCore import (
135
+ QCoreApplication , QEventLoop , QObject , QSocketNotifier , QTimer ,
136
+ )
137
+ except ImportError as e :
138
+ failures ["PySide2" ] = e
139
+ else :
140
+ found = True
141
+
142
+ try :
143
+ # try PySide6
144
+ from PySide6 .QtCore import (
145
+ QCoreApplication , QEventLoop , QObject , QSocketNotifier , QTimer ,
146
+ )
147
+ except ImportError as e :
148
+ failures ["PySide6" ] = e
149
+ else :
150
+ found = True
151
+
152
+ if not found :
153
+ raise ImportError (
154
+ "No supported Qt wrapper found.\n {}" .format ("\n " .join ("{}: {}" .format (k , v ) for k , v in failures .items ()))
155
+ )
124
156
125
157
from twisted .internet .error import ReactorAlreadyInstalledError
126
158
from twisted .internet import posixbase
@@ -143,7 +175,7 @@ def __init__(self, parent, reactor, watcher, socketType):
143
175
fd = watcher .fileno ()
144
176
self .notifier = QSocketNotifier (fd , socketType , parent )
145
177
self .notifier .setEnabled (True )
146
- if socketType == QSocketNotifier .Read :
178
+ if socketType == QSocketNotifier .Type . Read :
147
179
self .fn = self .read
148
180
else :
149
181
self .fn = self .write
@@ -238,11 +270,11 @@ def _add(self, xer, primary, type):
238
270
239
271
def addReader (self , reader ):
240
272
"""Add a FileDescriptor for notification of data available to read."""
241
- self ._add (reader , self ._reads , QSocketNotifier .Read )
273
+ self ._add (reader , self ._reads , QSocketNotifier .Type . Read )
242
274
243
275
def addWriter (self , writer ):
244
276
"""Add a FileDescriptor for notification of data available to write."""
245
- self ._add (writer , self ._writes , QSocketNotifier .Write )
277
+ self ._add (writer , self ._writes , QSocketNotifier .Type . Write )
246
278
247
279
def _remove (self , xer , primary ):
248
280
"""
@@ -318,7 +350,13 @@ def run(self, installSignalHandlers=True):
318
350
else :
319
351
self ._blockApp = QEventLoop ()
320
352
self .runReturn (installSignalHandlers = installSignalHandlers )
321
- self ._blockApp .exec_ ()
353
+
354
+ exec_method = getattr (self ._blockApp , "exec" , None )
355
+ if exec_method is None :
356
+ exec_method = self ._blockApp .exec_
357
+
358
+ exec_method ()
359
+
322
360
if self .running :
323
361
self .stop ()
324
362
self .runUntilCurrent ()
0 commit comments