def __init__(self, id, dicDotAttrs={}, x=0.0, y=0.0): self.id = id self.x = x self.y = y self.neighbours = {} self.dotAttrs = {} dictAttrs = dicDotAttrs.copy() dictAttrs[NodeDotAttrs.pos.value] = NodeDotPosUtils.formatPos(x, y) self.edit(dictAttrs)
def checkNodeAttrsForm(self, dictNodeAttrs): '''Return None if an attribute of a node is not valid, else an error message. Argument(s): dictNodeAttrs (str): Dot attributes values of the nodes ''' for attr in dictNodeAttrs.keys(): # Case of pos attribute if (attr == NodeDotAttrs.pos.value and not NodeDotPosUtils.isPosValid(dictNodeAttrs[attr])): return self.formatErrorMessage(NodeDotAttrs.pos.value, dictNodeAttrs[attr]) # All attributes are valid return None
def onCreateNode(self, idNode, dicDotAttrs): '''Callback function when creating a node. Argument(s): idNode (str): ID of the node dicDotAttrs (Dictionary[]): Dot attributes of the node ''' self.checkAndCleanAttrs(dicDotAttrs) if NodeDotAttrs.pos.value in dicDotAttrs: if dicDotAttrs[NodeDotAttrs.pos.value]: # Get position coords = NodeDotPosUtils.getPos( dicDotAttrs[NodeDotAttrs.pos.value]) self.model.addNode(idNode, dicDotAttrs, coords[NodeArgs.x], coords[NodeArgs.y]) else: self.model.addNode(idNode, dicDotAttrs)
def edit(self, dicDotAttrs): '''Edit dot attributes of the node. Argument(s): dicDotAttrs (Dictionary[]): Dot attributes of the node ''' for attr, val in dicDotAttrs.items(): # Case of pos attribute: we need to update x and y if attr == NodeDotAttrs.pos.value: if val: pos = NodeDotPosUtils.getPos(val) if pos: self.x = pos[NodeArgs.x] self.y = pos[NodeArgs.y] else: self.x = 0.0 self.y = 0.0 else: self.x = 0.0 self.y = 0.0 self.dotAttrs[attr] = val
def onEditPos(self): """Callback function when editing the pos.""" self.graphicsGraphView.controller.onEditNode( self.id, {NodeDotAttrs.pos.value: NodeDotPosUtils.formatPos(self.x(), self.y())} )
def onEditPos(self): '''Callback function when editing the pos.''' self.graphicsGraphView.controller.onEditNode(self.id, { NodeDotAttrs.pos.value: NodeDotPosUtils.formatPos(self.x(), self.y()) })