anki/qt/aqt/qt.py

63 lines
1.6 KiB
Python
Raw Normal View History

2019-02-05 04:59:03 +01:00
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
2019-03-04 08:25:19 +01:00
# make sure not to optimize imports on this file
# pylint: disable=unused-import
import os
2019-12-20 10:19:03 +01:00
import sys
import traceback
from typing import Callable, Union
2019-12-20 10:19:03 +01:00
from PyQt5.Qt import * # type: ignore
from PyQt5.QtCore import *
2019-12-23 01:34:10 +01:00
from PyQt5.QtCore import pyqtRemoveInputHook # pylint: disable=no-name-in-module
2019-12-20 10:19:03 +01:00
from PyQt5.QtGui import * # type: ignore
from PyQt5.QtNetwork import QLocalServer, QLocalSocket, QNetworkProxy
from PyQt5.QtWebChannel import QWebChannel
from PyQt5.QtWebEngineWidgets import *
2019-12-20 10:19:03 +01:00
from PyQt5.QtWidgets import *
from anki.utils import isMac, isWin
# fix buggy ubuntu12.04 display of language selector
os.environ["LIBOVERLAY_SCROLLBAR"] = "0"
try:
from PyQt5 import sip
except ImportError:
2019-12-23 01:34:10 +01:00
import sip # type: ignore
def debug():
2019-03-04 07:54:22 +01:00
from pdb import set_trace
2019-12-23 01:34:10 +01:00
2019-03-04 07:54:22 +01:00
pyqtRemoveInputHook()
set_trace()
if os.environ.get("DEBUG"):
2019-12-23 01:34:10 +01:00
def info(type, value, tb):
for line in traceback.format_exception(type, value, tb):
sys.stdout.write(line)
pyqtRemoveInputHook()
from pdb import pm
2019-12-23 01:34:10 +01:00
pm()
2019-12-23 01:34:10 +01:00
sys.excepthook = info
2019-12-23 01:34:10 +01:00
qtmajor = (QT_VERSION & 0xFF0000) >> 16
qtminor = (QT_VERSION & 0x00FF00) >> 8
qtpoint = QT_VERSION & 0xFF
if qtmajor != 5 or qtminor < 9 or qtminor == 10:
2019-03-04 07:54:22 +01:00
raise Exception("Anki does not support your Qt version.")
def qconnect(signal: Union[Callable, pyqtSignal], func: Callable) -> None:
"Helper to work around type checking not working with signal.connect(func)."
signal.connect(func) # type: ignore