1616import attr
1717import outcome
1818import qts
19+ import qts .util
1920import trio
2021import trio .abc
2122
@@ -65,16 +66,12 @@ def register_event_type() -> None:
6566
6667 # assign to the global
6768 # TODO: https://bugreports.qt.io/browse/PYSIDE-1347
68- if qts .is_pyqt_5_wrapper :
69- _reenter_event_type = QtCore .QEvent .Type (event_hint )
70- elif qts .is_pyside_5_wrapper :
69+ if qts .is_pyside_5_wrapper :
7170 _reenter_event_type = typing .cast (
7271 typing .Callable [[int ], QtCore .QEvent .Type ], QtCore .QEvent .Type
7372 )(event_hint )
74- else : # pragma: no cover
75- raise qtrio .InternalError (
76- "You should not be here but you are running neither PyQt5 nor PySide2." ,
77- )
73+ else :
74+ _reenter_event_type = QtCore .QEvent .Type (event_hint )
7875
7976
8077def register_requested_event_type (requested_value : int | QtCore .QEvent .Type ) -> None :
@@ -99,17 +96,13 @@ def register_requested_event_type(requested_value: int | QtCore.QEvent.Type) ->
9996 raise qtrio .EventTypeAlreadyRegisteredError ()
10097
10198 # TODO: https://bugreports.qt.io/browse/PYSIDE-1468
102- if qts .is_pyqt_5_wrapper :
103- event_hint = QtCore .QEvent .registerEventType (requested_value )
104- elif qts .is_pyside_5_wrapper :
99+ if qts .is_pyside_5_wrapper :
105100 event_hint = typing .cast (
106101 typing .Callable [[int | QtCore .QEvent .Type ], int ],
107102 QtCore .QEvent .registerEventType ,
108103 )(requested_value )
109- else : # pragma: no cover
110- raise qtrio .InternalError (
111- "You should not be here but you are running neither PyQt5 nor PySide2." ,
112- )
104+ else :
105+ event_hint = QtCore .QEvent .registerEventType (requested_value )
113106
114107 if event_hint == - 1 :
115108 raise qtrio .EventTypeRegistrationFailedError ()
@@ -120,16 +113,12 @@ def register_requested_event_type(requested_value: int | QtCore.QEvent.Type) ->
120113
121114 # assign to the global
122115 # TODO: https://bugreports.qt.io/browse/PYSIDE-1347
123- if qts .is_pyqt_5_wrapper :
124- _reenter_event_type = QtCore .QEvent .Type (event_hint )
125- elif qts .is_pyside_5_wrapper :
116+ if qts .is_pyside_5_wrapper :
126117 _reenter_event_type = typing .cast (
127118 typing .Callable [[int ], QtCore .QEvent .Type ], QtCore .QEvent .Type
128119 )(event_hint )
129- else : # pragma: no cover
130- raise qtrio .InternalError (
131- "You should not be here but you are running neither PyQt5 nor PySide2." ,
132- )
120+ else :
121+ _reenter_event_type = QtCore .QEvent .Type (event_hint )
133122
134123
135124async def wait_signal (signal : "QtCore.SignalInstance" ) -> typing .Tuple [object , ...]:
@@ -541,17 +530,13 @@ def maybe_build_application() -> "QtGui.QGuiApplication":
541530 application : QtCore .QCoreApplication
542531
543532 # TODO: https://bugreports.qt.io/browse/PYSIDE-1467
544- if qts .is_pyqt_5_wrapper :
545- maybe_application = QtWidgets .QApplication .instance ()
546- elif qts .is_pyside_5_wrapper :
533+ if qts .is_pyside_5_wrapper :
547534 maybe_application = typing .cast (
548535 typing .Optional ["QtCore.QCoreApplication" ],
549536 QtWidgets .QApplication .instance (),
550537 )
551- else : # pragma: no cover
552- raise qtrio .InternalError (
553- "You should not be here but you are running neither PyQt5 nor PySide2." ,
554- )
538+ else :
539+ maybe_application = QtWidgets .QApplication .instance ()
555540
556541 if maybe_application is None :
557542 application = QtWidgets .QApplication (sys .argv [1 :])
@@ -660,7 +645,7 @@ def run(
660645 self .application .aboutToQuit .connect (_early_quit_warning )
661646
662647 if execute_application :
663- return_code = self . application . exec_ ( )
648+ return_code = qts . util . exec ( self . application )
664649
665650 self .outcomes = attr .evolve (
666651 self .outcomes ,
0 commit comments