示例#1
0
    def dropMimeData(self, data, action, row, column, parent):  # pylint: disable=R0913
        """See QAbstractItemModel documentation"""
        if  parent.isValid() or \
                ( row == -1 and column == -1 ) or \
                action != Qt.MoveAction or \
                not data or \
                not data.hasFormat(self.mimeTypes()[0]):
            return False

        fromRow = data.data(self.mimeTypes()[0]).toInt()[0]

        if row >= len(self._workspace.sortedDocuments):
            row -= 1
        elif fromRow < row:
            row -= 1

        newDocuments = copy.copy(self._workspace.sortedDocuments)

        item = newDocuments.pop(fromRow)

        # if row > fromRow:
        #    row -= 1

        newDocuments.insert(row, item)

        self.rebuildMapping(self._workspace.sortedDocuments, newDocuments)

        self._manuallySorted = True

        QObject.parent(self).tvFiles.setCurrentIndex(self.documentIndex(item))

        return True
示例#2
0
    def dropMimeData(self, data, action, row, column, parent):  # pylint: disable=R0913
        """See QAbstractItemModel documentation"""
        if  parent.isValid() or \
                ( row == -1 and column == -1 ) or \
                action != Qt.MoveAction or \
                not data or \
                not data.hasFormat(self.mimeTypes()[0]):
            return False

        fromRow = data.data(self.mimeTypes()[0]).toInt()[0]

        if row >= len(self._workspace.sortedDocuments):
            row -= 1
        elif fromRow < row:
            row -= 1

        newDocuments = copy.copy(self._workspace.sortedDocuments)

        item = newDocuments.pop(fromRow)

        # if row > fromRow:
        #    row -= 1

        newDocuments.insert(row, item)

        self.rebuildMapping(self._workspace.sortedDocuments, newDocuments)

        self._manuallySorted = True

        QObject.parent(self).tvFiles.setCurrentIndex(self.documentIndex(item))

        return True
示例#3
0
    def sortDocuments(self, openedDocument=None):
        """Sort documents list according to current sort mode"""

        sortedDocuments = self._workspace.sortedDocuments
        if self._MRU:
            # Newly-opened documents aren't yet the currentDocument, so we must
            # use that if supplied.
            cd = openedDocument or self._workspace.currentDocument()
            # When the last document is closed, it's been removed from
            # sortedDocuments, but self._workspace.currentDocument() hasn't been
            # updated yet. Avoid this case.
            if cd in sortedDocuments:
                # Move this document to the beginning of the list.
                numericIndex = sortedDocuments.index(cd)
                sortedDocuments.insert(0, sortedDocuments.pop(numericIndex))
        elif not self._manuallySorted:
            sortedDocuments = sorted(sortedDocuments,
                                     key=lambda d: d.filePath() or '')
        self.rebuildMapping(sortedDocuments, sortedDocuments)

        # Scroll the view. In MRU mode, correct the selected index, since
        # rebuildMapping will corrupt it. If a document was just opened, avoid
        # this since its Qutepart widget hasn't been added to the list of opened
        # widgets, causing errors such as "QStackedWidget::setCurrentWidget:
        # widget 0x4b48be8 not contained in stack" if the code below runs.
        if self._MRU and not openedDocument:
            QObject.parent(self).tvFiles.setCurrentIndex(
                self.createIndex(0, 0, cd))
        selected = QObject.parent(
            self).tvFiles.selectionModel().selectedIndexes()
        if selected:
            QObject.parent(self).tvFiles.scrollTo(selected[0])
示例#4
0
    def sortDocuments(self, openedDocument=None):
        """Sort documents list according to current sort mode"""

        sortedDocuments = self._workspace.sortedDocuments
        if self._MRU:
            # Newly-opened documents aren't yet the currentDocument, so we must
            # use that if supplied.
            cd = openedDocument or self._workspace.currentDocument()
            # When the last document is closed, it's been removed from
            # sortedDocuments, but self._workspace.currentDocument() hasn't been
            # updated yet. Avoid this case.
            if cd in sortedDocuments:
                # Move this document to the beginning of the list.
                numericIndex = sortedDocuments.index(cd)
                sortedDocuments.insert(0, sortedDocuments.pop(numericIndex))
        elif not self._manuallySorted:
            sortedDocuments = sorted(sortedDocuments,
                                     key=lambda d: d.filePath() or '')
        self.rebuildMapping(sortedDocuments, sortedDocuments)

        # Scroll the view. In MRU mode, correct the selected index, since
        # rebuildMapping will corrupt it. If a document was just opened, avoid
        # this since its Qutepart widget hasn't been added to the list of opened
        # widgets, causing errors such as "QStackedWidget::setCurrentWidget:
        # widget 0x4b48be8 not contained in stack" if the code below runs.
        if self._MRU and not openedDocument:
            QObject.parent(self).tvFiles.setCurrentIndex(self.createIndex(0, 0, cd))
        selected = QObject.parent(self).tvFiles.selectionModel().selectedIndexes()
        if selected:
            QObject.parent(self).tvFiles.scrollTo(selected[0])
示例#5
0
 def sortDocuments(self):
     """Sort documents list according to current sort mode"""
     sortedDocuments = self._workspace.sortedDocuments
     if not self._manuallySorted:
         sortedDocuments = sorted(sortedDocuments,
                                  key=lambda d: d.filePath() or '')
     self.rebuildMapping(self._workspace.sortedDocuments, sortedDocuments)
     # scroll the view
     selected = QObject.parent(self).tvFiles.selectionModel().selectedIndexes()
     if selected:
         QObject.parent(self).tvFiles.scrollTo(selected[0])
示例#6
0
 def sortDocuments(self):
     """Sort documents list according to current sort mode"""
     sortedDocuments = self._workspace.sortedDocuments
     if not self._manuallySorted:
         sortedDocuments = sorted(sortedDocuments,
                                  key=lambda d: d.filePath() or '')
     self.rebuildMapping(self._workspace.sortedDocuments, sortedDocuments)
     # scroll the view
     selected = QObject.parent(
         self).tvFiles.selectionModel().selectedIndexes()
     if selected:
         QObject.parent(self).tvFiles.scrollTo(selected[0])
示例#7
0
    def _onDocumentClosed(self, document):
        """Document has been closed. Unhandle it
        """
        index = self._workspace.sortedDocuments.index(document)

        if index == -1:
            return

        # scroll the view
        QObject.parent(self).startModifyModel()
        self.beginRemoveRows(QModelIndex(), index, index)
        self._workspace.sortedDocuments.remove(document)
        self.endRemoveRows()
        QObject.parent(self).finishModifyModel()
示例#8
0
    def _onDocumentClosed(self, document):
        """Document has been closed. Unhandle it
        """
        index = self._workspace.sortedDocuments.index(document)

        if index == -1:
            return

        # scroll the view
        QObject.parent(self).startModifyModel()
        self.beginRemoveRows(QModelIndex(), index, index)
        self._workspace.sortedDocuments.remove(document)
        self.endRemoveRows()
        QObject.parent(self).finishModifyModel()
示例#9
0
    def setModel(self, model):
        """
        Reimplemented.

        Parameters
        ----------
        model : QAbstractItemModel
        """
        if model is self.__completerModel:
            return

        if self.__completerModel is not None:
            self.__completerModel.dataChanged.disconnect(
                self.__initDynamicModel)
            self.__completerModel.rowsInserted.disconnect(
                self.__initDynamicModel)
            self.__completerModel.rowsRemoved.disconnect(
                self.__initDynamicModel)

            if QObject.parent(self.__completerModel) is self:
                self.__completerModel.deleteLater()
            self.__completerModel = None

        self.__completerModel = model

        if self.__completerModel is not None:
            self.__completerModel.dataChanged.connect(self.__initDynamicModel)
            self.__completerModel.rowsInserted.connect(self.__initDynamicModel)
            self.__completerModel.rowsRemoved.connect(self.__initDynamicModel)

        self.__initDynamicModel()
示例#10
0
    def resolve_item_up_changed(self, item: QObject) -> None:
        self.update_item_changed(item)

        parent = item.parent()
        if not parent or not parent.isCheckable():
            return

        parent.setCheckState(Qt.PartiallyChecked)
        self.update_item_changed(parent)
        self.item_check_parent(parent)
示例#11
0
    def resolve_item_up_changed(self, item: QObject) -> None:
        self.update_item_changed(item)

        parent = item.parent()
        if not parent or not parent.isCheckable():
            return

        parent.setCheckState(Qt.PartiallyChecked)
        self.update_item_changed(parent)
        self.item_check_parent(parent)
示例#12
0
    def resolve_item_up_changed(self, item: QObject) -> None:
        """Update the state of the parent."""
        self.update_item_changed(item)

        parent = item.parent()
        if not (parent and parent.isCheckable()):
            return

        parent.setCheckState(Qt.PartiallyChecked)
        self.update_item_changed(parent)
        self.item_check_parent(parent)
示例#13
0
def notify_wheel_event(app: QtWidgets.QApplication,
                       obj: QtCore.QObject,
                       event: QtCore.QEvent):
    """Notify obj or obj.parent() based on orientation lock state"""

    update_lock_orientation(event)

    if (event.orientation() == locked_orientation
        and (type(obj) is not QtGui.QScrollBar
             or obj.orientation() == locked_orientation)):

        return super(type(app), app).notify(obj, event)
    else:
        return super(type(app), app).notify(obj.parent(), event)
示例#14
0
    def QObject对象名称和属性(self):
        obj0 = QObject()
        obj1 = QObject()
        obj2 = QObject()
        obj3 = QObject()
        obj4 = QObject()
        obj5 = QObject()
        obj2.setObjectName("2")
        obj3.setObjectName("3")
        print("obj0", obj0)
        print("obj1", obj1)
        print("obj2", obj2)
        print("obj3", obj3)
        print("obj4", obj4)
        print("obj5", obj5)

        obj1.setParent(obj0)
        obj2.setParent(obj0)
        obj3.setParent(obj1)
        obj4.setParent(obj2)
        obj5.setParent(obj2)

        print(obj1.parent())
        print(obj2.parent())
        print(obj0.children())
        print(obj0.findChildren(QObject, None, Qt.FindChildrenRecursively))
        print(obj0.findChild(QObject, "2", Qt.FindChildrenRecursively))
        #********************内存管理***************************开始
        obj1 = QObject()
        self.obj1 = obj1
        obj2 = QObject()
        obj2.setParent(obj1)

        # 监听obj2对象被释放

        obj2.destroyed.connect(lambda _: print("obj2对象被释放了"))
        del self.obj1
示例#15
0
 def eventFilter(self, watched: QObject, event: QEvent) -> bool:
     return self._interpreter.eventFilter(watched.parent(), event)
示例#16
0
def get_parent(widget: QObject):
    if callable(widget.parent) is False:
        ## some objects has "parent" attribute instead of "parent" method
        ## e.g. matplotlib's NavigationToolbar
        return None
    return widget.parent()