4444import importlib
4545
4646
47- __version__ = "1.2.0.b3 "
47+ __version__ = "1.2.0"
4848
4949# Enable support for `from Qt import *`
5050__all__ = []
@@ -778,6 +778,32 @@ def _wrapinstance(ptr, base=None):
778778 return func (long (ptr ), base )
779779
780780
781+ def _isvalid (object ):
782+ """Check if the object is valid to use in Python runtime.
783+
784+ Usage:
785+ See :func:`QtCompat.isValid()`
786+
787+ Arguments:
788+ object (QObject): QObject to check the validity of.
789+
790+ """
791+
792+ assert isinstance (object , Qt .QtCore .QObject )
793+
794+ if hasattr (Qt , "_shiboken2" ):
795+ return getattr (Qt , "_shiboken2" ).isValid (object )
796+
797+ elif hasattr (Qt , "_shiboken" ):
798+ return getattr (Qt , "_shiboken" ).isValid (object )
799+
800+ elif hasattr (Qt , "_sip" ):
801+ return not getattr (Qt , "_sip" ).isdeleted (object )
802+
803+ else :
804+ raise AttributeError ("'module' has no attribute isValid" )
805+
806+
781807def _translate (context , sourceText , * args ):
782808 # In Qt4 bindings, translate can be passed 2 or 3 arguments
783809 # In Qt5 bindings, translate can be passed 2 arguments
@@ -968,6 +994,7 @@ def createWidget(self, class_name, parent=None, name=""):
968994 "QtUiTools.QUiLoader" : ["QtCompat.loadUi" , _loadUi ],
969995 "shiboken2.wrapInstance" : ["QtCompat.wrapInstance" , _wrapinstance ],
970996 "shiboken2.getCppPointer" : ["QtCompat.getCppPointer" , _getcpppointer ],
997+ "shiboken2.isValid" : ["QtCompat.isValid" , _isvalid ],
971998 "QtWidgets.qApp" : "QtWidgets.QApplication.instance()" ,
972999 "QtCore.QCoreApplication.translate" : [
9731000 "QtCompat.translate" , _translate
@@ -992,6 +1019,7 @@ def createWidget(self, class_name, parent=None, name=""):
9921019 "uic.loadUi" : ["QtCompat.loadUi" , _loadUi ],
9931020 "sip.wrapinstance" : ["QtCompat.wrapInstance" , _wrapinstance ],
9941021 "sip.unwrapinstance" : ["QtCompat.getCppPointer" , _getcpppointer ],
1022+ "sip.isdeleted" : ["QtCompat.isValid" , _isvalid ],
9951023 "QtWidgets.qApp" : "QtWidgets.QApplication.instance()" ,
9961024 "QtCore.QCoreApplication.translate" : [
9971025 "QtCompat.translate" , _translate
@@ -1024,6 +1052,7 @@ def createWidget(self, class_name, parent=None, name=""):
10241052 "QtUiTools.QUiLoader" : ["QtCompat.loadUi" , _loadUi ],
10251053 "shiboken.wrapInstance" : ["QtCompat.wrapInstance" , _wrapinstance ],
10261054 "shiboken.unwrapInstance" : ["QtCompat.getCppPointer" , _getcpppointer ],
1055+ "shiboken.isValid" : ["QtCompat.isValid" , _isvalid ],
10271056 "QtGui.qApp" : "QtWidgets.QApplication.instance()" ,
10281057 "QtCore.QCoreApplication.translate" : [
10291058 "QtCompat.translate" , _translate
@@ -1057,6 +1086,7 @@ def createWidget(self, class_name, parent=None, name=""):
10571086 "uic.loadUi" : ["QtCompat.loadUi" , _loadUi ],
10581087 "sip.wrapinstance" : ["QtCompat.wrapInstance" , _wrapinstance ],
10591088 "sip.unwrapinstance" : ["QtCompat.getCppPointer" , _getcpppointer ],
1089+ "sip.isdeleted" : ["QtCompat.isValid" , _isvalid ],
10601090 "QtCore.QString" : "str" ,
10611091 "QtGui.qApp" : "QtWidgets.QApplication.instance()" ,
10621092 "QtCore.QCoreApplication.translate" : [
@@ -1391,6 +1421,10 @@ def _pyside2():
13911421
13921422 if hasattr (Qt , "_QtCore" ):
13931423 Qt .__qt_version__ = Qt ._QtCore .qVersion ()
1424+ Qt .QtCompat .dataChanged = (
1425+ lambda self , topleft , bottomright , roles = None :
1426+ self .dataChanged .emit (topleft , bottomright , roles or [])
1427+ )
13941428
13951429 if hasattr (Qt , "_QtWidgets" ):
13961430 Qt .QtCompat .setSectionResizeMode = \
@@ -1438,6 +1472,10 @@ def _pyside():
14381472
14391473 if hasattr (Qt , "_QtCore" ):
14401474 Qt .__qt_version__ = Qt ._QtCore .qVersion ()
1475+ Qt .QtCompat .dataChanged = (
1476+ lambda self , topleft , bottomright , roles = None :
1477+ self .dataChanged .emit (topleft , bottomright )
1478+ )
14411479
14421480 _reassign_misplaced_members ("PySide" )
14431481 _build_compatibility_members ("PySide" )
@@ -1448,11 +1486,18 @@ def _pyqt5():
14481486
14491487 import PyQt5 as module
14501488 extras = ["uic" ]
1489+
14511490 try :
14521491 import sip
1453- extras . append ( sip . __name__ )
1492+ extras += [ " sip" ]
14541493 except ImportError :
1455- sip = None
1494+
1495+ # Relevant to PyQt5 5.11 and above
1496+ try :
1497+ from PyQt5 import sip
1498+ extras += ["sip" ]
1499+ except ImportError :
1500+ sip = None
14561501
14571502 _setup (module , extras )
14581503 if hasattr (Qt , "_sip" ):
@@ -1466,6 +1511,10 @@ def _pyqt5():
14661511 if hasattr (Qt , "_QtCore" ):
14671512 Qt .__binding_version__ = Qt ._QtCore .PYQT_VERSION_STR
14681513 Qt .__qt_version__ = Qt ._QtCore .QT_VERSION_STR
1514+ Qt .QtCompat .dataChanged = (
1515+ lambda self , topleft , bottomright , roles = None :
1516+ self .dataChanged .emit (topleft , bottomright , roles or [])
1517+ )
14691518
14701519 if hasattr (Qt , "_QtWidgets" ):
14711520 Qt .QtCompat .setSectionResizeMode = \
@@ -1542,6 +1591,10 @@ def _pyqt4():
15421591 if hasattr (Qt , "_QtCore" ):
15431592 Qt .__binding_version__ = Qt ._QtCore .PYQT_VERSION_STR
15441593 Qt .__qt_version__ = Qt ._QtCore .QT_VERSION_STR
1594+ Qt .QtCompat .dataChanged = (
1595+ lambda self , topleft , bottomright , roles = None :
1596+ self .dataChanged .emit (topleft , bottomright )
1597+ )
15451598
15461599 _reassign_misplaced_members ("PyQt4" )
15471600
@@ -1867,4 +1920,4 @@ def _install():
18671920# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18681921# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18691922# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1870- # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1923+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0 commit comments