Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
 def update_data(self):
     # TODO dump data
     # NOTE 清理已经删除的对象
     QtWidgets.QApplication.processEvents()
     self.group_list = [grp for grp in self.group_list if isValid(grp)]
     for grp in self.group_list:
         grp.item_list = [item for item in grp.item_list if isValid(item)]
         for item in grp.item_list:
             print(item)
Ejemplo n.º 3
0
 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))
Ejemplo n.º 4
0
    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))
Ejemplo n.º 5
0
 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))
Ejemplo n.º 6
0
    def onThreadOutput(text):
        if not shiboken.isValid(ui) or not shiboken.isValid(ui.progressText): return

        ui.progressText.moveCursor(QTextCursor.End)
        if text[0] == "\r":
            #cursor = QTextCursor(ui.progressText.textCursor())
            ui.progressText.moveCursor(QTextCursor.StartOfLine, QTextCursor.KeepAnchor)
            ui.progressText.moveCursor(QTextCursor.PreviousCharacter, QTextCursor.KeepAnchor)

        ui.progressText.insertHtml(text.replace('\n', '<br />'))
Ejemplo n.º 7
0
    def _read_from_capture(self):
        if self._is_stopped.isSet():
            return

        ret, frame = self.read()
        if ret and shiboken2.isValid(self):
            self.readFinished.emit(frame.copy())
Ejemplo n.º 8
0
 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 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)
Ejemplo n.º 10
0
 def _addGraphView(self, subConfig):
     g = subConfig.getGraph()
     # remove already deleted graph views from internal list
     valid_graphViews = []
     for gv in self._graphViews:
         if shiboken2.isValid(gv):  # pylint: disable=no-member
             valid_graphViews.append(gv)
     self._graphViews = valid_graphViews
     # check if graph view is already there
     for gv in self._graphViews:
         if gv.widget().scene().graph == g:
             logger.info("Graph view already exists.")
             return
     # create new graph view
     srv = Services.getService("MainWindow")
     graphDw = srv.newDockWidget("Graph (%s)" % (subConfig.getName()),
                                 parent=None,
                                 defaultArea=Qt.RightDockWidgetArea,
                                 allowedArea=Qt.RightDockWidgetArea
                                 | Qt.BottomDockWidgetArea)
     graphDw.setAttribute(Qt.WA_DeleteOnClose, True)
     assert isinstance(graphDw, QDockWidget)
     graphView = GraphEditorView(graphDw)
     graphView.setScene(GraphScene(subConfig.getGraph(), graphDw))
     graphDw.setWidget(graphView)
     self._graphViews.append(graphDw)
     graphDw.visibleChanged.connect(self._removeGraphViewFromList)
Ejemplo n.º 11
0
def isValidQtObject(obj):
    """
    Does the Python object given contain a valid Qt reference pointer?

    Only supports host 'maya'.

    :param obj: Qt class object.

    :returns: Is the given object valid in C++?
    :rtype: bool
    """
    v = None
    host = getHostApplication()
    if host == 'standalone':
        raise NotImplementedError
    elif host == 'maya':
        try:
            from shiboken2 import isValid
        except ImportError:
            from shiboken import isValid
        v = isValid(obj)
    else:
        raise NotImplementedError
    assert isinstance(v, bool) is True
    return v
Ejemplo n.º 12
0
    def items(self):
        remove = []
        for item in self.itemList:
            if not shiboken2.isValid(item):
                remove.append(item)

        [self.itemList.remove(r) for r in remove]
        return self.itemList
Ejemplo n.º 13
0
        def eventFilter(self, obj, event):
            if obj.isWidgetType() and event.type() == QEvent.MouseButtonPress \
                    and self.target in obj.window().findChildren(QWidget) \
                    and self.target.underMouse() and not self.target.isEnabled():
                self.dispatch()
                obj.setFocus()

            if shiboken is not None and not shiboken.isValid(obj):
                return False
            return super().eventFilter(obj, event)
Ejemplo n.º 14
0
def for_loop_files(paths, interval=100, parent=None, objectName=""):
    timer = QtCore.QTimer(parent=parent, singleShot=True, interval=interval)
    if objectName:
        timer.setObjectName(objectName)
    loop = QtCore.QEventLoop(timer)
    timer.timeout.connect(loop.quit)
    timer.destroyed.connect(loop.quit)
    for path in paths:
        if shiboken2.isValid(timer):
            timer.start()
            loop.exec_()
            yield path
Ejemplo n.º 15
0
 def deleteChild(self, name):
     """
     Remove a child collection.
     :param name: the name of the collection.
     :return: None
     """
     assertMainThread()
     cc = self.getChildCollection(name)
     for c in cc.children():
         if isinstance(c, PropertyCollectionImpl):
             cc.deleteChild(c.objectName())
     if shiboken2.isValid(cc): # pylint: disable=no-member
         shiboken2.delete(cc) # pylint: disable=no-member
Ejemplo n.º 16
0
 def kitsuInit(self):
     if shiboken2.isValid(self.loadL):
         self.loadL.hide()
         if self.session == -1:
             nuke.message("Please login to kitsu.")
         elif self.session == -2:
             nuke.message(
                 "Your kitsu account does not have the permission to create shots."
             )
         elif self.session:
             self.session.onPostedComment[str].connect(self.onPostResult)
             self.loadProjects()
             self.loadTasks()
Ejemplo n.º 17
0
    def update(self):
        """
        Called periodically to synchronize model with added log records

        :return: None
        """
        assertMainThread()
        if not shiboken2.isValid(self):  # pylint: disable=no-member
            return
        if not self.queue.empty():
            self._model.update(self.queue)
            if self.follow:
                self.scrollToBottom()
Ejemplo n.º 18
0
def getWidgetByName(name):
    hasHandle = hasattr(hou.session, name)
    if not hasHandle or (hasHandle and getattr(hou.session, name) and
                         not shiboken2.isValid(getattr(hou.session, name))):
        allWidgets = QtWidgets.QApplication.allWidgets()
        for w in allWidgets:
            if name in w.windowTitle():
                setattr(hou.session, name, w)
                break

    if not hasattr(hou.session, name):
        return None

    return getattr(hou.session, name)
Ejemplo n.º 19
0
    def _dereferenceItem(self, item):
        # Ask for object deletion if parented to the model
        if shiboken2.isValid(item) and item.parent() == self:
            # delay deletion until the next event loop
            # This avoids warnings when the QML engine tries to evaluate (but should not)
            # an object that has already been deleted
            self.requestDeletion.emit(item)

        if not self._keyAttrName:
            return
        key = getattr(item, self._keyAttrName, None)
        if key is None:
            return
        assert key in self._objectByKey
        del self._objectByKey[key]
Ejemplo n.º 20
0
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)
Ejemplo n.º 21
0
def isValidQtObject(obj):
    """
    Does a Python object contain a valid Qt reference pointer?
    """
    v = None
    host = getHostApplication()
    if host == 'standalone':
        raise NotImplementedError
    elif host == 'maya':
        try:
            from shiboken2 import isValid
        except ImportError:
            from shiboken import isValid
        v = isValid(obj)
    else:
        raise NotImplementedError
    assert isinstance(v, bool) is True
    return v
Ejemplo n.º 22
0
def is_valid_widget(widget):
    """
    Checks if a widget is a valid in the backend
    :param widget: QWidget
    :return: bool, True if the widget still has a C++ object, False otherwise
    """

    if widget is None:
        return False

    # Added try because Houdini does not includes Shiboken library by default
    # TODO: When Houdini app class implemented, add cleaner way
    try:
        if not shiboken.isValid(widget):
            return False
    except Exception:
        return True

    return True
Ejemplo n.º 23
0
def is_deleted(obj) -> bool:
    if qt.API == "pyside2":
        import shiboken2

        return not shiboken2.isValid(obj)
    elif qt.API == "pyside6":
        import shiboken6

        return not shiboken6.isValid(obj)
    elif qt.API == "pyqt5":
        try:
            from PyQt5 import sip
        except ImportError:
            import sip  # type: ignore[import, no-redef]
        return sip.isdeleted(obj)
    else:
        try:
            from PyQt6 import sip
        except ImportError:
            import sip  # type: ignore[import, no-redef]
        return sip.isdeleted(obj)
Ejemplo n.º 24
0
def for_loop_files(path, interval=100, extensions=(), parent=None, objectName=""):
    timer = QtCore.QTimer(parent=parent, singleShot=True, interval=interval)
    if objectName:
        timer.setObjectName(objectName)
    loop = QtCore.QEventLoop(timer)
    timer.timeout.connect(loop.quit)
    timer.destroyed.connect(loop.quit)
    for root, dirs, files in os.walk(path):
        # print(files)
        for name in files:
            base, ext = os.path.splitext(name)
            # print(ext)
            if extensions:
                if ext in extensions:
                    print(extensions)
                    if shiboken2.isValid(timer):
                        timer.start()
                        loop.exec_()
                        yield os.path.join(root, name)
            else:
                yield os.path.join(root, name)
Ejemplo n.º 25
0
 def _isdeleted(obj):
     return not shiboken2.isValid(obj)
Ejemplo n.º 26
0
def safeDelete(obj: QObject) -> None:
    """ Calls deleteLater() on a QObject, doing nothing if the object was already deleted """
    if obj and shiboken2.isValid(obj):
        obj.deleteLater()
Ejemplo n.º 27
0
    def testClear(self):

        model = QStandardItemModel()
        root = model.invisibleRootItem()
        model.clear()
        self.assertFalse(shiboken.isValid(root))
Ejemplo n.º 28
0
def _is_valid(obj):
    if not shbkn.isValid(obj):
        txm.txm_log().warning('%r IS INVALID !!', obj)
        return False
    return True
Ejemplo n.º 29
0
def getIsPointerValid(widget):
    return shiboken.isValid(widget)
Ejemplo n.º 30
0
def is_object_deleted(widget_obj):
    """
    checks if the object is deleted.
    :return: <bool> True for yes. <bool> False for no.
    """
    return isValid(widget_obj)