def focusOutEvent(self, event): '''Handle focus out event. Argument(s): event (QFocusEvent ): Focus event ''' QGraphicsTextItem.focusOutEvent(self, event) # Create a fake node to test if label is valid with pydot fakeNode = ("fake[" + NodeDotAttrs.label.value + "=" + self.toPlainText() + "]") pydotGraph = graph_from_dot_data("graph{" + fakeNode + "}") # Label is valid: we can do the update if pydotGraph: dicDotAttrs = { NodeDotAttrs.label.value: NodeDotLabelUtils.formatLabel(self.toPlainText()) } # Update text in other views node = self.parentItem() node.graphicsGraphView.controller.onEditNode(node.id, dicDotAttrs) # Disable edit text self.setTextInteractionFlags(Qt.NoTextInteraction) # Label is invalid: force user to write a correct label else: QMessageBox.warning(None, "Syntax error", "The label is invalid.") self.setFocus()
def editLabel(self, dictArgsNode): '''Edit the label. Argument(s): dictArgsNode (Dictionary[]): Dictionary of arguments of the node ''' # Get ID as default label label = self.id # Take value label if it exists if (NodeDotAttrs.label.value in dictArgsNode[NodeArgs.dotAttrs] and dictArgsNode[NodeArgs.dotAttrs][NodeDotAttrs.label.value]): label = NodeDotLabelUtils.getLabel( (dictArgsNode[NodeArgs.dotAttrs][NodeDotAttrs.label.value])) # Update the text if needed if label != self.graphicsTextNode.toPlainText(): self.graphicsTextNode.setPlainText(label)
def editLabel(self, dictArgsNode): """Edit the label. Argument(s): dictArgsNode (Dictionary[]): Dictionary of arguments of the node """ # Get ID as default label label = self.id # Take value label if it exists if ( NodeDotAttrs.label.value in dictArgsNode[NodeArgs.dotAttrs] and dictArgsNode[NodeArgs.dotAttrs][NodeDotAttrs.label.value] ): label = NodeDotLabelUtils.getLabel((dictArgsNode[NodeArgs.dotAttrs][NodeDotAttrs.label.value])) # Update the text if needed if label != self.graphicsTextNode.toPlainText(): self.graphicsTextNode.setPlainText(label)