Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Add PyQt6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
erdewit committed Apr 27, 2021
1 parent e3fdea5 commit 006fcfc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
4 changes: 2 additions & 2 deletions examples/qt_ticker_table.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio

import PyQt5.QtWidgets as qt
# import PySide2.QtWidgets as qt
# import PySide6.QtWidgets as qt

from ib_insync import IB, util
from ib_insync.contract import * # noqa
Expand Down Expand Up @@ -102,7 +102,7 @@ def closeEvent(self, ev):
if __name__ == '__main__':
util.patchAsyncio()
util.useQt()
# util.useQt('PySide2')
# util.useQt('PySide6')
window = Window('127.0.0.1', 7497, 1)
window.resize(600, 400)
window.show()
Expand Down
21 changes: 8 additions & 13 deletions ib_insync/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,29 +459,24 @@ def useQt(qtLib: str = 'PyQt5', period: float = 0.01):
def qt_step():
loop.call_later(period, qt_step)
if not stack:
qloop = QEventLoop()
timer = QTimer()
qloop = qc.QEventLoop()
timer = qc.QTimer()
timer.timeout.connect(qloop.quit)
stack.append((qloop, timer))
qloop, timer = stack.pop()
timer.start(0)
qloop.exec_()
qloop.exec() if qtLib == 'PyQt6' else qloop.exec_()
timer.stop()
stack.append((qloop, timer))
qApp.processEvents()

if qtLib not in ('PyQt5', 'PySide2', 'PySide6'):
if qtLib not in ('PyQt5', 'PyQt6', 'PySide2', 'PySide6'):
raise RuntimeError(f'Unknown Qt library: {qtLib}')
if qtLib == 'PyQt5':
from PyQt5.Qt import QApplication, QTimer, QEventLoop
elif qtLib == 'PySide6':
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import QTimer, QEventLoop
else:
from PySide2.QtWidgets import QApplication
from PySide2.QtCore import QTimer, QEventLoop
from importlib import import_module
qc = import_module(qtLib + '.QtCore')
qw = import_module(qtLib + '.QtWidgets')
global qApp
qApp = QApplication.instance() or QApplication(sys.argv) # type: ignore
qApp = qw.QApplication.instance() or qw.QApplication(sys.argv)
loop = asyncio.get_event_loop()
stack: list = []
qt_step()
Expand Down

0 comments on commit 006fcfc

Please sign in to comment.