def showWidget(key, widgetType, refresh=False): global _globalQtObjects if refresh: # Close and remove widget, so we can test a new one. try: widget = _globalQtObjects.pop(key) except (KeyError, RuntimeError): pass else: # Widget might get deleted on close, watch out! if shiboken.isValid(widget): widget.close() if shiboken.isValid(widget): widget.deleteLater() # Prevent GC widget = _globalQtObjects.get(key) if widget is None or not shiboken.isValid(widget): widget = _globalQtObjects[key] = widgetType() try: widget.show() widget.raise_() except RuntimeError: # PySide-1 has a propensity to LIE that a widget # is still valid in C++ land. so we'll try # ONE MORE TIME widget = _globalQtObjects[key] = widgetType() widget.show() widget.raise_()
def testDelete(self): obj = ObjectType() child = ObjectType(obj) self.assertTrue(shiboken.isValid(obj)) self.assertTrue(shiboken.isValid(child)) # Note: this test doesn't assure that the object dtor was really called shiboken.delete(obj) self.assertFalse(shiboken.isValid(obj)) self.assertFalse(shiboken.isValid(child))
def testIsValid(self): self.assertTrue(shiboken.isValid(object())) self.assertTrue(shiboken.isValid(None)) bb = BlackBox() item = ObjectType() ticket = bb.keepObjectType(item) bb.disposeObjectType(ticket) self.assertFalse(shiboken.isValid(item))
def testNonCppWrapperClassDelete(self): """Would segfault when shiboken.delete called on obj not created from Python """ obj = sample.ObjectType() child = obj.createChild(None) shiboken.delete(child) assert not shiboken.isValid(child)
def allinstances(cls): """Return all instances that inherit from JB_Gui :returns: all instances that inherit from JB_Gui :rtype: list :raises: None """ JB_Gui._allinstances = weakref.WeakSet([i for i in cls._allinstances if shiboken.isValid(i)]) return list(cls._allinstances)
def isObjectValid(objectToTestObjIn): """ Determine if `objectToTestObjIn` is valid Args: objectToTestObjIn (obj): Object to test Returns: (bool): Is the object valid """ if Qt.IsPySide: import shiboken return shiboken.isValid(objectToTestObjIn) elif Qt.IsPySide2: import shiboken2 return shiboken2.isValid(objectToTestObjIn)
def isValid(widget): """ Check if a widget is valid in the backend :param widget: QtGui.QWidget :return: True if the widget still has a c++ object :rtype: bool """ if widget is None: return False if qt_lib == 'pyqt': if sip.isdeleted(widget): return False elif qt_lib == 'pyside': if not shiboken.isValid(widget): return False return True
def update_button(self, button, widget): """Update the icon of the button with the given widget if the widget does not is invalid, it is deleted from the tooltip automatically. :param button: the button to update :type button: QtGui.QAbstractButton :param widget: the widget to render as icon :type widget: QtGui.QWidget :returns: None :rtype: None :raises: None """ if not shiboken.isValid(widget): self.remove_widget(widget) return button.setIconSize(QtCore.QSize(self._iconw, self._iconh)) pix = QtGui.QPixmap(widget.size()) widget.render(pix) icon = QtGui.QIcon(pix) button.setIcon(icon)
def run(self, *args, **kwargs): """Start genesis :returns: None :rtype: None :raises: None """ if self.gw and shiboken.isValid(self.gw): self.gw.deleteLater() mayawin = maya_main_window() self.gw = self.GenesisWin(parent=mayawin) self.gw.last_file.connect(self.save_lastfile) if not self.gw.get_current_file(): c = self.get_config() try: f = models.TaskFile.objects.get(pk=c['lastfile']) except models.TaskFile.DoesNotExist: pass else: self.gw.browser.set_selection(f) self.gw.show()
def testClear(self): model = QStandardItemModel() root = model.invisibleRootItem() model.clear() self.assertFalse(shiboken.isValid(root))
def isValidQObj(qobj): return shiboken.isValid(qobj)
def _isdeleted(obj): return not shiboken.isValid(obj)
def _isdeleted(obj): return not shiboken.isValid(obj) _getSaveFileName = QtGui.QFileDialog.getSaveFileName