Beispiel #1
0
 def eventFilter(self, source, event):
     ''' Event Filter '''
     if (event.type() == QEvent.MouseButtonPress
             and source is self.VManager.viewport()
             and self.VManager.itemAt(event.pos()) is None):
         self.VManager.clearSelection()
     return QDockWidget.eventFilter(self, source, event)
Beispiel #2
0
    def eventFilter(self, obj, event):
        if obj is self.__closeButton:
            etype = event.type()
            if etype == QEvent.MouseButtonPress:
                self.setExpanded(not self.__expanded)
                return True
            elif etype == QEvent.MouseButtonDblClick or \
                    etype == QEvent.MouseButtonRelease:
                return True
            # TODO: which other events can trigger the button (is the button
            # focusable).

        return QDockWidget.eventFilter(self, obj, event)
Beispiel #3
0
    def eventFilter(self, obj, e):
        if obj == self.command and e.type() == QEvent.KeyPress:
            history = self.device.history
            if e.modifiers() & Qt.ControlModifier:
                if e.key() == Qt.Key_H:
                    d = DeviceConsoleHistory(self.device.env.devices)
                    if d.exec_() == QDialog.Accepted:
                        self.command.setText(d.command)

                elif len(history) > 0:
                    if e.key() == Qt.Key_E:
                        self.command.setText(history[0])

                    if e.key() == Qt.Key_Down:
                        self.command.completer().setModel(
                            QStringListModel(history))
                        self.command.setText(' ')
                        self.command.completer().complete()
            return False

        return QDockWidget.eventFilter(self, obj, e)
Beispiel #4
0
    def eventFilter(self, obj, event):
        if event.type() == QEvent.KeyRelease and event.key() == Qt.Key_Delete:
            lists = self.nodesScene.selectedItems()
            for i in range(0, len(lists)):
                if lists[i].type() == 2:  #QGraphicsPathItem.Type:
                    self.DeleteConnection(lists[i])
                if lists[i].type() == 3:  #QGraphicsRectItem.Type
                    self.DeleteNode(self.GetNodeItem(lists[i]))
            self.clearConnection()
            self.updateConnectors()

        if event.type() == QEvent.GraphicsSceneMousePress and (
                self.connectTo or self.connectFrom):
            if (event.buttons() & Qt.LeftButton) != 0:
                p = event.scenePos()
                node = self.GetNode(p)
                if node is not None:
                    if self.connectTo is not None:
                        ido = node.GetOutputId(p)
                        if ido >= 0:
                            self.connectTo.inputs[self.idconnect].node = node
                            self.connectTo.inputs[self.idconnect].out = ido
                    if self.connectFrom is not None:
                        idi = node.GetInputId(p)
                        if idi >= 0:
                            node.inputs[idi].node = self.connectFrom
                            node.inputs[idi].out = self.idconnect
                self.clearConnection()
                self.updateConnectors()

        if event.type() == QEvent.GraphicsSceneContextMenu:
            p = event.scenePos()
            node = self.GetNode(p)
            self.clearConnection()
            if node is not None:
                idi = node.GetInputId(p)
                ido = node.GetOutputId(p)
                if idi >= 0:
                    self.connectTo = node
                    self.idconnect = idi
                elif ido >= 0:
                    self.connectFrom = node
                    self.idconnect = ido
                if idi >= 0 or ido >= 0:
                    return True

        if event.type() == QEvent.GraphicsSceneDragEnter or event.type(
        ) == QEvent.GraphicsSceneDragMove or event.type(
        ) == QEvent.GraphicsSceneDrop:
            event.acceptProposedAction()
            if event.type() == QEvent.GraphicsSceneDrop:
                bytearray = event.mimeData().data(
                    event.mimeData().formats()[0])
                data_items = self.decode_data(bytearray)
                text = data_items[0][Qt.DisplayRole].value()
                if text in NodesEditor.nodeCreator:
                    node = NodesEditor.nodeCreator[text]()
                    self.addNode(node).setPos(event.scenePos())
            return True

        if event.type() == QEvent.GraphicsSceneMouseMove:
            if (event.buttons() & Qt.LeftButton) != 0:
                self.updateConnectors()
            if self.connectTo is not None or self.connectFrom is not None:
                p1 = QPointF(0, 0)
                p2 = QPointF(0, 0)
                if self.connectFrom is not None:
                    p1 = event.scenePos()
                    p2 = self.connectFrom.GetOutputPoint(self.idconnect)
                if self.connectTo is not None:
                    p1 = self.connectTo.GetInputPoint(self.idconnect)
                    p2 = event.scenePos()
                self.connectItem = self.updateConnector(
                    self.connectItem, p1, p2, False)

        return QDockWidget.eventFilter(self, obj, event)