2019-02-05 04:59:03 +01:00
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
2012-12-21 08:51:59 +01:00
|
|
|
# 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
|
2013-12-18 23:41:29 +01:00
|
|
|
|
|
|
|
import os
|
2019-12-20 10:19:03 +01:00
|
|
|
import sys
|
|
|
|
import traceback
|
2020-05-04 05:23:08 +02:00
|
|
|
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
|
2020-08-02 02:16:54 +02:00
|
|
|
from PyQt5.QtNetwork import QLocalServer, QLocalSocket, QNetworkProxy
|
2020-07-31 00:49:05 +02:00
|
|
|
from PyQt5.QtWebChannel import QWebChannel
|
2020-06-02 09:56:15 +02:00
|
|
|
from PyQt5.QtWebEngineWidgets import *
|
2019-12-20 10:19:03 +01:00
|
|
|
from PyQt5.QtWidgets import *
|
|
|
|
|
|
|
|
from anki.utils import isMac, isWin
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2016-05-31 10:51:40 +02:00
|
|
|
# fix buggy ubuntu12.04 display of language selector
|
|
|
|
os.environ["LIBOVERLAY_SCROLLBAR"] = "0"
|
|
|
|
|
2013-12-18 23:41:29 +01:00
|
|
|
|
2018-10-23 08:02:59 +02:00
|
|
|
try:
|
|
|
|
from PyQt5 import sip
|
|
|
|
except ImportError:
|
2019-12-23 01:34:10 +01:00
|
|
|
import sip # type: ignore
|
2013-12-18 23:41:29 +01:00
|
|
|
|
2019-03-04 02:22:40 +01:00
|
|
|
|
2021-02-01 14:28:21 +01:00
|
|
|
def debug() -> None:
|
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()
|
2021-10-02 15:13:24 +02:00
|
|
|
set_trace() # pylint: disable=forgotten-debug-statement
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2013-12-18 23:41:29 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
if os.environ.get("DEBUG"):
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2021-02-02 14:30:53 +01:00
|
|
|
def info(type, value, tb) -> None: # type: ignore
|
2012-12-21 08:51:59 +01:00
|
|
|
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
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
pm()
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2012-12-21 08:51:59 +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
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-10-05 03:06:34 +02:00
|
|
|
if qtmajor < 5 or (qtmajor == 5 and qtminor < 14):
|
2019-03-04 07:54:22 +01:00
|
|
|
raise Exception("Anki does not support your Qt version.")
|
2020-01-15 22:41:23 +01:00
|
|
|
|
2020-01-15 22:53:12 +01:00
|
|
|
|
2020-05-04 05:23:08 +02:00
|
|
|
def qconnect(signal: Union[Callable, pyqtSignal], func: Callable) -> None:
|
2020-01-15 22:41:23 +01:00
|
|
|
"Helper to work around type checking not working with signal.connect(func)."
|
2020-01-15 22:53:12 +01:00
|
|
|
signal.connect(func) # type: ignore
|