def mouseRightButtonPressed(self, obj, event): pos = gridPos(event.scenePos()) item = self.itemAt(pos) if isinstance(item, Block): self.menuBlk.exec_(event.screenPos()) else: pass
def mousePressEvent(self, event): pos = gridPos(event.scenePos()) for item in self.items( QtCore.QRectF(pos - QtCore.QPointF(DB, DB), QtCore.QSizeF(2 * DB, 2 * DB))): if isinstance(item, Block): self.actComp = item
def mouseReleased(self, obj, event): self.connFromNode = False items = self.scene.selectedItems() for item in items: if isBlock(item) or isPort(item) or isComment(item): item.setPos(gridPos(item.pos())) for thing in item.childItems(): if isPort(thing, 'block'): for conn in thing.connections: conn.update_path()
def moveMouse(self, obj, event): if self.connFromNode: return pos = gridPos(event.scenePos()) item = self.itemAt(pos) if self.conn: self.scene.mainw.view.setCursor(QtCore.Qt.ArrowCursor) if item and isInPort(item) or isNode(item): if len(item.connections) == 0: self.scene.mainw.view.setCursor(QtCore.Qt.CrossCursor) else: self.scene.mainw.view.setCursor(QtCore.Qt.ArrowCursor) elif item and isNode(item): if len(item.connections) == 0: self.scene.mainw.view.setCursor(QtCore.Qt.CrossCursor) else: self.scene.mainw.view.setCursor(QtCore.Qt.ArrowCursor) self.conn.update_path(pos) #return True elif item: if isBlock(item): items = self.scene.selectedItems() for item in items: if isBlock(item): for thing in item.childItems(): if isPort(thing, 'block'): for conn in thing.connections: conn.update_path() #elif isConnection(item): #self.scene.mainw.view.setCursor(QtCore.Qt.PointingHandCursor) elif isOutPort(item): self.scene.mainw.view.setCursor(QtCore.Qt.CrossCursor) elif isNode(item): if item in self.scene.selectedItems(): self.scene.mainw.view.setCursor( QtCore.Qt.PointingHandCursor) else: self.scene.mainw.view.setCursor(QtCore.Qt.CrossCursor) else: self.scene.mainw.view.setCursor(QtCore.Qt.ArrowCursor)
def contextMenuEvent(self, event): pos = gridPos(event.scenePos()) for item in self.items( QtCore.QRectF(pos - QtCore.QPointF(DB, DB), QtCore.QSizeF(2 * DB, 2 * DB))): if isinstance(item, Block): self.viewMenu.clear() self.addViewMenu() addViewAction = self.viewMenu.addAction("Add view") addViewAction.triggered.connect(self.addViewAction) self.menuBlk.exec_(event.screenPos()) break else: if self.parent.copiedBlock and self.parent.copiedBlockLibname: self.pasteBlockAction.setEnabled(True) else: self.pasteBlockAction.setEnabled(False) self.menuLibrary.exec_(event.screenPos())
def mouseDoubleClicked(self, obj, event): pos = gridPos(event.scenePos()) item = self.itemAt(pos, exclude=[isConnection]) if isBlock(item): if 'diagram' in item.getViews(): self.scene.mainw.descend(item) else: views = item.getViews() fname = None if len(views) == 1: viewtype, fname = views.items()[0] elif len(views) > 1: d = selectionDialog(views.keys(), title='Select view') ret = d.getRet() if ret: fname = views[ret] if fname: for tp, (editor, extension) in viewTypes.items(): if fname.endswith(extension): cmd = editor break if cmd: os.system(cmd + " " + fname) else: error( "{} is unkown type\nplease see viewTypes in menu Settings -> Edit settings" .format(source)) return elif isPort(item, tp='ipin opin iopin node'.split()): self.scene.item = item self.portEdit() if self.conn: self.conn.remove() self.conn = None self.scene.mainw.view.setCursor(QtCore.Qt.ArrowCursor) elif isTextItem(item): font, ok = QtWidgets.QFontDialog.getFont(item.font()) if ok: item.setFont(font)
def mouseLeftButtonPressed(self, obj, event): pos = gridPos(event.scenePos()) blocks, ports, nodes, connections, labels = self.sortedItemsAt(pos) if self.conn: # connection mode while ports: # try to find in-port port = ports.pop() if isInPort(port): self.connectionFinish(port) return while nodes: # else try to find node node = nodes.pop() self.connectionFinish(node) return # while connections: # conn = connections.pop() # if conn != self.conn: # node = self.connectionInsertNode(conn, pos) # self.connectionFinish(node) # return self.connectionNext(pos) else: # not in connection mode while ports: port = ports.pop() if isOutPort(port) and not port.connections: # Try to create new connection starting at selected output port self.connectionStart(port) return while nodes: node = nodes.pop() if node in self.scene.selectedItems(): node.setFlag(node.ItemIsMovable) else: #starting the connection self.connectionStart(node) self.connFromNode = True
def createNode(self, pos=None): if not isinstance(pos, (QtCore.QPoint, QtCore.QPointF)): pos = gridPos(self.event.scenePos()) newnode = Port(None, self.scene, porttype='node') newnode.setPos(pos) return newnode
def insertConnection(self, event): pos = gridPos(event.scenePos()) item = self.ConnectionAt(pos) if item and isConnection(item): self.connectionInsertNode(item, pos)