1 # -----------------------------------------------------------------------------
2 # Copyright © 2014-2015 Colin Duquesnoy
3 # Copyright © 2009- The Spyder Development Team
5 # Licensed under the terms of the MIT License
6 # (see LICENSE.txt for details)
7 # -----------------------------------------------------------------------------
9 """Provides QtCore classes and functions."""
10 from typing
import TYPE_CHECKING
12 from . import PYQT6
, PYQT5
, PYSIDE2
, PYSIDE6
15 from PyQt5
.QtCore
import *
16 from PyQt5
.QtCore
import pyqtSignal
as Signal
17 from PyQt5
.QtCore
import pyqtBoundSignal
as SignalInstance
18 from PyQt5
.QtCore
import pyqtSlot
as Slot
19 from PyQt5
.QtCore
import pyqtProperty
as Property
20 from PyQt5
.QtCore
import QT_VERSION_STR
as __version__
22 # For issue #153 and updated for issue #305
23 from PyQt5
.QtCore
import QDate
, QDateTime
, QTime
24 QDate
.toPython
= lambda self
, *args
, **kwargs
: self
.toPyDate(*args
, **kwargs
)
25 QDateTime
.toPython
= lambda self
, *args
, **kwargs
: self
.toPyDateTime(*args
, **kwargs
)
26 QTime
.toPython
= lambda self
, *args
, **kwargs
: self
.toPyTime(*args
, **kwargs
)
28 # Map missing methods on PyQt5 5.12
29 QTextStreamManipulator
.exec_
= lambda self
, *args
, **kwargs
: self
.exec(*args
, **kwargs
)
31 # Those are imported from `import *`
32 del pyqtSignal
, pyqtBoundSignal
, pyqtSlot
, pyqtProperty
, QT_VERSION_STR
35 from PyQt6
import QtCore
36 from PyQt6
.QtCore
import *
37 from PyQt6
.QtCore
import pyqtSignal
as Signal
38 from PyQt6
.QtCore
import pyqtBoundSignal
as SignalInstance
39 from PyQt6
.QtCore
import pyqtSlot
as Slot
40 from PyQt6
.QtCore
import pyqtProperty
as Property
41 from PyQt6
.QtCore
import QT_VERSION_STR
as __version__
43 # For issue #153 and updated for issue #305
44 from PyQt6
.QtCore
import QDate
, QDateTime
, QTime
45 QDate
.toPython
= lambda self
, *args
, **kwargs
: self
.toPyDate(*args
, **kwargs
)
46 QDateTime
.toPython
= lambda self
, *args
, **kwargs
: self
.toPyDateTime(*args
, **kwargs
)
47 QTime
.toPython
= lambda self
, *args
, **kwargs
: self
.toPyTime(*args
, **kwargs
)
50 # Seems like there is an error with sip. Without first
51 # trying to import `PyQt6.QtGui.Qt`, some functions like
52 # `PyQt6.QtCore.Qt.mightBeRichText` are missing.
55 from PyQt6
.QtGui
import Qt
60 QCoreApplication
.exec_
= QCoreApplication
.exec
61 QEventLoop
.exec_
= lambda self
, *args
, **kwargs
: self
.exec(*args
, **kwargs
)
62 QThread
.exec_
= lambda self
, *args
, **kwargs
: self
.exec(*args
, **kwargs
)
63 QTextStreamManipulator
.exec_
= lambda self
, *args
, **kwargs
: self
.exec(*args
, **kwargs
)
65 QLibraryInfo
.location
= QLibraryInfo
.path
67 # Those are imported from `import *`
68 del pyqtSignal
, pyqtBoundSignal
, pyqtSlot
, pyqtProperty
, QT_VERSION_STR
70 # Allow unscoped access for enums inside the QtCore module
71 from .enums_compat
import promote_enums
75 # Alias deprecated ItemDataRole enum values removed in Qt6
76 Qt
.BackgroundColorRole
= Qt
.ItemDataRole
.BackgroundColorRole
= Qt
.BackgroundRole
77 Qt
.TextColorRole
= Qt
.ItemDataRole
.TextColorRole
= Qt
.ForegroundRole
78 # Alias for MiddleButton removed in PyQt6 but available in PyQt5, PySide2 and PySide6
79 Qt
.MidButton
= Qt
.MiddleButton
82 from PySide2
.QtCore
import *
84 try: # may be limited to PySide-5.11a1 only
85 from PySide2
.QtGui
import QStringListModel
90 __version__
= PySide2
.QtCore
.__version
__
92 # Missing QtGui utility functions on Qt
93 if getattr(Qt
, 'mightBeRichText', None) is None:
95 from PySide2
.QtGui
import Qt
as guiQt
96 Qt
.mightBeRichText
= guiQt
.mightBeRichText
99 # Fails with PySide2 5.12.0
103 from PySide6
.QtCore
import *
104 import PySide6
.QtCore
105 __version__
= PySide6
.QtCore
.__version
__
107 # Missing QtGui utility functions on Qt
108 if getattr(Qt
, 'mightBeRichText', None) is None:
109 from PySide6
.QtGui
import Qt
as guiQt
110 Qt
.mightBeRichText
= guiQt
.mightBeRichText
113 # Alias deprecated ItemDataRole enum values removed in Qt6
114 Qt
.BackgroundColorRole
= Qt
.ItemDataRole
.BackgroundColorRole
= Qt
.BackgroundRole
115 Qt
.TextColorRole
= Qt
.ItemDataRole
.TextColorRole
= Qt
.ForegroundRole
116 Qt
.MidButton
= Qt
.MiddleButton
118 # Map DeprecationWarning methods
119 QCoreApplication
.exec_
= QCoreApplication
.exec
120 QEventLoop
.exec_
= lambda self
, *args
, **kwargs
: self
.exec(*args
, **kwargs
)
121 QThread
.exec_
= lambda self
, *args
, **kwargs
: self
.exec(*args
, **kwargs
)
122 QTextStreamManipulator
.exec_
= lambda self
, *args
, **kwargs
: self
.exec(*args
, **kwargs
)
123 QLibraryInfo
.location
= QLibraryInfo
.path