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
|
|
|
|
2021-10-05 05:53:01 +02:00
|
|
|
try:
|
|
|
|
from PyQt6 import sip
|
|
|
|
from PyQt6.QtCore import *
|
|
|
|
|
|
|
|
# conflicting Qt and qFuzzyCompare definitions require an ignore
|
|
|
|
from PyQt6.QtGui import * # type: ignore[misc]
|
|
|
|
from PyQt6.QtNetwork import QLocalServer, QLocalSocket, QNetworkProxy
|
|
|
|
from PyQt6.QtWebChannel import QWebChannel
|
|
|
|
from PyQt6.QtWebEngineCore import *
|
|
|
|
from PyQt6.QtWebEngineWidgets import *
|
|
|
|
from PyQt6.QtWidgets import *
|
|
|
|
except:
|
|
|
|
from PyQt5.QtCore import * # type: ignore
|
|
|
|
from PyQt5.QtGui import * # type: ignore
|
|
|
|
from PyQt5.QtNetwork import ( # type: ignore
|
|
|
|
QLocalServer,
|
|
|
|
QLocalSocket,
|
|
|
|
QNetworkProxy,
|
|
|
|
)
|
|
|
|
from PyQt5.QtWebChannel import QWebChannel # type: ignore
|
|
|
|
from PyQt5.QtWebEngineCore import * # type: ignore
|
|
|
|
from PyQt5.QtWebEngineWidgets import * # type: ignore
|
|
|
|
from PyQt5.QtWidgets import * # type: ignore
|
|
|
|
|
|
|
|
try:
|
|
|
|
from PyQt5 import sip # type: ignore
|
|
|
|
except ImportError:
|
|
|
|
import sip # type: ignore
|
2019-12-20 10:19:03 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2021-10-07 07:36:50 +02:00
|
|
|
def qconnect(
|
|
|
|
signal: Union[Callable, pyqtSignal, pyqtBoundSignal], func: Callable
|
|
|
|
) -> None:
|
2021-10-08 07:55:38 +02: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
|