Coverage for C:\Repos\leo-editor\leo\core\leoQt6.py: 76%
104 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
1#@+leo-ver=5-thin
2#@+node:ekr.20210407011013.1: * @file leoQt6.py
3"""
4Import wrapper for pyQt6.
6For Qt6, plugins are responsible for loading all optional modules.
8"""
10# For now, suppress all mypy checks
11# type: ignore
13# pylint: disable=unused-import,no-name-in-module,c-extension-no-member,import-error
15# Required imports
16from typing import Any
17from PyQt6 import QtCore, QtGui, QtWidgets
18from PyQt6.QtCore import Qt, QUrl
19from PyQt6.QtGui import QAction, QActionGroup, QCloseEvent
20from PyQt6.QtCore import pyqtSignal as Signal
21#
22# For pyflakes.
23assert QtCore and QtGui and QtWidgets
24assert QAction and QActionGroup
25assert QCloseEvent
26assert Qt and QUrl and Signal
27#
28# Standard abbreviations.
29QtConst = Qt
30qt_version = QtCore.QT_VERSION_STR
31#
32# Optional imports: #2005
33# Must import this before creating the GUI
34has_WebEngineWidgets = False
35try:
36 from PyQt6 import QtWebEngineWidgets
37 from PyQt6 import QtWebEngineCore # included with PyQt6-WebEngine
38 assert QtWebEngineWidgets
39 has_WebEngineWidgets = True
40except ImportError:
41 print('No Qt6 QtWebEngineWidgets')
42 print('pip install PyQt6-WebEngine')
44try:
45 from PyQt6 import QtPrintSupport as printsupport
46except Exception:
47 printsupport = None
49try:
50 from PyQt6 import Qsci
51except ImportError:
52 Qsci = None
53try:
54 import PyQt6.QtSvg as QtSvg
55except ImportError:
56 QtSvg = None
57try:
58 from PyQt6 import uic
59except ImportError:
60 uic = None
61#
62# #2005: Do not import these by default. All of these *do* work.
63if 0:
64 try:
65 from PyQt6 import QtDesigner
66 except Exception:
67 QtDesigner = None
68 try:
69 from PyQt6 import QtOpenGL
70 except Exception:
71 QtOpenGL = None
72 try:
73 from PyQt6 import QtMultimedia
74 except ImportError:
75 QtMultimedia = None
76 try:
77 from PyQt6 import QtNetwork
78 except Exception:
79 QtNetwork = None
80#
81# Enumerations, with (sheesh) variable spellings.
82try:
83 # New spellings (6.1+): mostly singular.
84 Alignment = QtCore.Qt.AlignmentFlag
85 ControlType = QtWidgets.QSizePolicy.ControlType
86 DropAction = QtCore.Qt.DropAction
87 ItemFlag = QtCore.Qt.ItemFlag
88 KeyboardModifier = QtCore.Qt.KeyboardModifier
89 Modifier = QtCore.Qt.Modifier
90 MouseButton = QtCore.Qt.MouseButton
91 Orientation = QtCore.Qt.Orientation
92 StandardButton = QtWidgets.QDialogButtonBox.StandardButton
93 TextInteractionFlag = QtCore.Qt.TextInteractionFlag
94 ToolBarArea = QtCore.Qt.ToolBarArea
95 WidgetAttribute = QtCore.Qt.WidgetAttribute # #2347
96 WindowType = QtCore.Qt.WindowType
97 WindowState = QtCore.Qt.WindowState
98except AttributeError:
99 # Old spellings (6.0): mostly plural.
100 Alignment = QtCore.Qt.Alignment # type:ignore
101 ControlType = QtWidgets.QSizePolicy.ControlTypes # type:ignore
102 DropAction = QtCore.Qt.DropActions # type:ignore
103 ItemFlag = QtCore.Qt.ItemFlags # type:ignore
104 KeyboardModifier = QtCore.Qt.KeyboardModifiers # type:ignore
105 Modifier = QtCore.Qt.Modifiers # type:ignore
106 MouseButton = QtCore.Qt.MouseButtons # type:ignore
107 Orientation = QtCore.Qt.Orientations # type:ignore
108 StandardButton = QtWidgets.QDialog.StandardButtons # type:ignore
109 TextInteractionFlag = QtCore.Qt.TextInteractionFlags # type:ignore
110 ToolBarArea = QtCore.Qt.ToolBarAreas # type:ignore
111 WindowType = QtCore.Qt.WindowFlags # type:ignore
112 WindowState = QtCore.Qt.WindowStates # type:ignore
113#
114# Other enums.
115ButtonRole = QtWidgets.QMessageBox.ButtonRole
116ContextMenuPolicy = QtCore.Qt.ContextMenuPolicy
117DialogCode = QtWidgets.QDialog.DialogCode
118EndEditHint = QtWidgets.QAbstractItemDelegate.EndEditHint
119FocusPolicy = QtCore.Qt.FocusPolicy
120FocusReason = QtCore.Qt.FocusReason
121Format = QtGui.QImage.Format
122GlobalColor = QtCore.Qt.GlobalColor
123Icon = QtWidgets.QMessageBox.Icon
124Information = QtWidgets.QMessageBox.Icon.Information
125ItemDataRole = QtCore.Qt.ItemDataRole # 2347
126Key = QtCore.Qt.Key
127MoveMode = QtGui.QTextCursor.MoveMode
128MoveOperation = QtGui.QTextCursor.MoveOperation
129Policy = QtWidgets.QSizePolicy.Policy
130ScrollBarPolicy = QtCore.Qt.ScrollBarPolicy
131SelectionBehavior = QtWidgets.QAbstractItemView.SelectionBehavior
132SelectionMode = QtWidgets.QAbstractItemView.SelectionMode
133Shadow = QtWidgets.QFrame.Shadow
134Shape = QtWidgets.QFrame.Shape
135SizeAdjustPolicy = QtWidgets.QComboBox.SizeAdjustPolicy
136SliderAction = QtWidgets.QAbstractSlider.SliderAction
137SolidLine = QtCore.Qt.PenStyle.SolidLine
138StandardPixmap = QtWidgets.QStyle.StandardPixmap
139Style = QtGui.QFont.Style
140TextOption = QtGui.QTextOption
141Type = QtCore.QEvent.Type
142UnderlineStyle = QtGui.QTextCharFormat.UnderlineStyle
143QWebEngineSettings: Any
144WebEngineAttribute: Any
145if has_WebEngineWidgets:
146 QWebEngineSettings = QtWebEngineCore.QWebEngineSettings
147 WebEngineAttribute = QWebEngineSettings.WebAttribute
148else:
149 QWebEngineSettings = None
150 WebEngineAttribute = None
152Weight = QtGui.QFont.Weight
153WrapMode = QtGui.QTextOption.WrapMode
154#@-leo