def parentNameChanged(oldParentName, newParentName, parentID): ''' * Updates BlockStub hashmaps and the BlockStubs of the parent of its new name * @param oldParentName * @param newParentName * @param parentID ''' oldKey = oldParentName + Block.getBlock(parentID).getGenusName(); newKey = newParentName + Block.getBlock(parentID).getGenusName(); # only update if parents name really did "change" meaning the new parent name is # different from the old parent name if(oldKey !=newKey): BlockStub.parentNameToParentBlock[newKey] = parentID; # update the parent name of each stub stubs = BlockStub.parentNameToBlockStubs[oldKey]; for stub in stubs: blockStub = Block.getBlock(stub); blockStub.parentName = newParentName; # update block label of each blockStub.setBlockLabel(newParentName); blockStub.notifyRenderable(); # check if any stubs already exist for new key existingStubs = parentNameToBlockStubs[newKey] if existingStubs != None: stubs += existingStubs parentNameToBlockStubs[newKey] = stubs # remove old parent name from hash maps parentNameToParentBlock.remove(oldKey); parentNameToBlockStubs.remove(oldKey);
def parentNameChanged(oldParentName, newParentName, parentID): ''' * Updates BlockStub hashmaps and the BlockStubs of the parent of its new name * @param oldParentName * @param newParentName * @param parentID ''' oldKey = oldParentName + Block.getBlock(parentID).getGenusName() newKey = newParentName + Block.getBlock(parentID).getGenusName() # only update if parents name really did "change" meaning the new parent name is # different from the old parent name if (oldKey != newKey): BlockStub.parentNameToParentBlock[newKey] = parentID # update the parent name of each stub stubs = BlockStub.parentNameToBlockStubs[oldKey] for stub in stubs: blockStub = Block.getBlock(stub) blockStub.parentName = newParentName # update block label of each blockStub.setBlockLabel(newParentName) blockStub.notifyRenderable() # check if any stubs already exist for new key existingStubs = parentNameToBlockStubs[newKey] if existingStubs != None: stubs += existingStubs parentNameToBlockStubs[newKey] = stubs # remove old parent name from hash maps parentNameToParentBlock.remove(oldKey) parentNameToBlockStubs.remove(oldKey)
def parentConnectorsChanged( parentID): key = Block.getBlock(parentID).getBlockLabel() + Block.getBlock(parentID).getGenusName(); # update each stub only if stub is a caller (as callers are the only type of stubs that # can change its connectors after being created) stubs = BlockStub.parentNameToBlockStubs[key] for stub in stubs: blockStub = Block.getBlock(stub) if(blockStub.stubGenus.startsWith(CALLER_STUB)): blockStub.updateConnectors(); # System.out.println("updated connectors of: "+blockStub); blockStub.notifyRenderable();
def parentConnectorsChanged(parentID): key = Block.getBlock(parentID).getBlockLabel() + Block.getBlock( parentID).getGenusName() # update each stub only if stub is a caller (as callers are the only type of stubs that # can change its connectors after being created) stubs = BlockStub.parentNameToBlockStubs[key] for stub in stubs: blockStub = Block.getBlock(stub) if (blockStub.stubGenus.startsWith(CALLER_STUB)): blockStub.updateConnectors() # System.out.println("updated connectors of: "+blockStub); blockStub.notifyRenderable()
def getLink(rblock1, otherBlocks): from blocks.BlockLink import BlockLink block1 = Block.getBlock(rblock1.blockID); closestSocket1 = None; closestSocket2 = None; closestBlock2 = None; closestDistance = BlockLinkChecker.MAX_LINK_DISTANCE; #currentDistance; for rblock2 in otherBlocks: currentPlug = BlockLinkChecker.getPlugEquivalent(block1); block2 = Block.getBlock(rblock2.blockID); if (block1 == block2 or not rblock1.isVisible() or not rblock2.isVisible() or rblock1.isCollapsed() or rblock2.isCollapsed()): continue; currentPlugPoint = None; currentSocketPoint = None; if (currentPlug != None): currentPlugPoint = BlockLinkChecker.getAbsoluteSocketPoint(rblock1, currentPlug); for currentSocket in BlockLinkChecker.getSocketEquivalents(block2): currentSocketPoint = BlockLinkChecker.getAbsoluteSocketPoint(rblock2, currentSocket); currentDistance = BlockLinkChecker.distance(currentPlugPoint,currentSocketPoint); if ((currentDistance < closestDistance) and BlockLinkChecker.checkRules(block1, block2, currentPlug, currentSocket)): closestBlock2 = block2; closestSocket1 = currentPlug; closestSocket2 = currentSocket; closestDistance = currentDistance; currentPlug = BlockLinkChecker.getPlugEquivalent(block2); if (currentPlug != None) : currentPlugPoint = BlockLinkChecker.getAbsoluteSocketPoint(rblock2, currentPlug); for currentSocket in BlockLinkChecker.getSocketEquivalents(block1): currentSocketPoint = BlockLinkChecker.getAbsoluteSocketPoint(rblock1, currentSocket); currentDistance = BlockLinkChecker.distance(currentPlugPoint,currentSocketPoint); if ((currentDistance < closestDistance) and BlockLinkChecker.checkRules(block1, block2, currentSocket, currentPlug)): closestBlock2 = block2; closestSocket1 = currentSocket; closestSocket2 = currentPlug; closestDistance = currentDistance; if (closestSocket1 == None): return None; return BlockLink.getBlockLink(block1, closestBlock2, closestSocket1, closestSocket2);
def appendRightSidePath(self, painterPath, connectedBlock, connectedBlockShape): ''' * Appends the right side path of the stack of blocks connected to the specified connectedBlock. If there are * some empty sockets, this method will append empty placeholders. * @param painterPath the GeneralPath to append the new path to * @param connectedBlock the Block instance whose right side of its stack of connected blocks will be appened to the * specified painterPath * @param connectedBlockShape the BlockShape of the specified connectedBlock ''' from blocks.RenderableBlock import RenderableBlock # int lastBottomPathWidth; # append top side of connected block BlockShapeUtil.appendPath(painterPath, connectedBlockShape.getTopSide(), False) startX = painterPath.currentPosition().x() for socket in connectedBlock.getSockets(): # Sets the current x-coordinate to the start x-coordinate # Makes it so path movements created by previous blocks don't affect # the subsequent blocks. painterPath.lineTo(startX, painterPath.currentPosition().y()) if (socket.blockID == Block.NULL): # just draw an empty socket placeholder # if its the first socket, draw a top side painterPath.lineTo( painterPath.currentPosition().x() + BlockShape.BOTTOM_SOCKET_SIDE_SPACER, painterPath.currentPosition().y()) # now draw the empty right socket side # draw first socket - down right side BlockShape.BCS.addDataSocket(painterPath, socket.getKind(), False) # TODO:lastBottomPathWidth = (int)BOTTOM_SOCKET_SIDE_SPACER; else: # a block is connected to this socket, check if that block has sockets # OR if the block is an infix block - if it is infix, then just wrap around the infix block block = Block.getBlock(socket.blockID) shape = RenderableBlock.getRenderableBlock( socket.blockID).getBlockShape() if (block.getNumSockets() == 0 or block.isInfix()): # append this block's top and right side # TODO instead of just appending the right side...draw line to BlockShapeUtil.appendPath(painterPath, shape.getTopSide(), False) BlockShapeUtil.appendPath(painterPath, shape.getRightSide(), False) else: self.appendRightSidePath(painterPath, block, shape) # Updates the maximum X-coordinate and sets the current point to self.maxX if (self.maxX < painterPath.currentPosition().x()): self.maxX = painterPath.currentPosition().x() painterPath.lineTo(self.maxX, painterPath.currentPosition().y())
def from_blockID(cls, workspaceWidget, blockID, isLoading=False, back_color=QtGui.QColor(225, 225, 225, 255)): return FactoryRenderableBlock.from_block(workspaceWidget, Block.getBlock(blockID), False, back_color)
def __init__(self, parent, initLabelText, prefix, suffix, labelType, isEditable, blockID, hasComboPopup, tooltipBackground): from blocks.RenderableBlock import RenderableBlock from blocks.FactoryRenderableBlock import FactoryRenderableBlock self.widget = LabelWidget(parent, blockID, initLabelText, prefix, suffix, Block.getBlock(blockID).getColor().darker(), tooltipBackground) self.parent = parent self.zoom = 1.0 self.initLabelText = initLabelText self.labelType = labelType self.blockID = blockID self.hasComboPopup = hasComboPopup # Only editable if the isEditable parameter was true, the label is either a Block's name or # socket label, the block can edit labels, and the block is not in the factory. self.widget.setEditable( isEditable and (labelType == BlockLabel.Type.NAME_LABEL or labelType == BlockLabel.Type.PORT_LABEL) and Block.getBlock(blockID).isLabelEditable() and not isinstance(RenderableBlock.getRenderableBlock(blockID), FactoryRenderableBlock)) if (labelType == None or labelType == (BlockLabel.Type.NAME_LABEL)): self.widget.setFont(BlockLabel.blockFontLarge_Bold) elif (labelType == (BlockLabel.Type.PAGE_LABEL)): self.widget.setFont(BlockLabel.blockFontMedium_Bold) elif (labelType == (BlockLabel.Type.PORT_LABEL)): self.widget.setFont(BlockLabel.blockFontMedium_Bold) elif (labelType == (BlockLabel.Type.DATA_LABEL)): self.widget.setFont(BlockLabel.blockFontMedium_Bold) # set initial text self.widget.updateLabelText(initLabelText) # add and show the textLabel initially self.widget.setEditingState(False) #famList = {} #if (Block.getBlock(blockID).hasSiblings()) : # famList = Block.getBlock(blockID).getSiblingsList(); #self.widget.setMenu(); self.widget.fireTextChanged = self.textChanged self.widget.fireGenusChanged = self.labelChanged self.widget.fireMenuChanged = self.onRenameVariable
def labelChanged(self, label): from blocks.RenderableBlock import RenderableBlock if(self.widget.hasMenu): oldBlock = Block.getBlock(self.blockID); oldBlock.changeLabelTo(label); rb = RenderableBlock.getRenderableBlock(self.blockID); rb.repaintBlock();
def labelChanged(self, label): from blocks.RenderableBlock import RenderableBlock if (self.widget.hasMenu): oldBlock = Block.getBlock(self.blockID) oldBlock.changeLabelTo(label) rb = RenderableBlock.getRenderableBlock(self.blockID) rb.repaintBlock()
def textChanged(self, text): from blocks.RenderableBlock import RenderableBlock from blocks.BlockStub import BlockStub if (self.labelType == BlockLabel.Type.NAME_LABEL or self.labelType == BlockLabel.Type.PORT_LABEL) and (Block.getBlock( self.blockID).isLabelEditable()): if (self.labelType == (BlockLabel.Type.NAME_LABEL)): Block.getBlock(self.blockID).setBlockLabel(text) plug = Block.getBlock(self.blockID).getPlug() # Check if we're connected to a block. If we are and the the block we're connected to # has stubs, update them. if (plug != None and plug.blockID != Block.NULL): if (Block.getBlock(plug.blockID) != None): if (Block.getBlock(plug.blockID).isProcedureDeclBlock() and Block.getBlock(plug.blockID).hasStubs()): # Blocks already store their socket names when saved so it is not necessary # nor desired to call the connectors changed event again. if (Block.getRenderableBlock( plug.blockID).isLoading()): BlockStub.parentConnectorsChanged( self.workspace, plug.blockID) rb = RenderableBlock.getRenderableBlock(self.blockID) if (rb != None and not rb.isLoading): rb.reformBlockShape() rb.updateBuffImg() #rb.repaint() pass
def textChanged(self, text): from blocks.RenderableBlock import RenderableBlock from blocks.BlockStub import BlockStub if (self.labelType == BlockLabel.Type.NAME_LABEL or self.labelType == BlockLabel.Type.PORT_LABEL) and (Block.getBlock(self.blockID).isLabelEditable()): if (self.labelType == (BlockLabel.Type.NAME_LABEL)): Block.getBlock(self.blockID).setBlockLabel(text); plug = Block.getBlock(self.blockID).getPlug(); # Check if we're connected to a block. If we are and the the block we're connected to # has stubs, update them. if (plug != None and plug.blockID != Block.NULL): if (Block.getBlock(plug.blockID) != None): if(Block.getBlock(plug.blockID).isProcedureDeclBlock() and Block.getBlock(plug.blockID).hasStubs()): # Blocks already store their socket names when saved so it is not necessary # nor desired to call the connectors changed event again. if (Block.getRenderableBlock(plug.blockID).isLoading()): BlockStub.parentConnectorsChanged(self.workspace, plug.blockID); rb = RenderableBlock.getRenderableBlock(self.blockID); if(rb != None and not rb.isLoading): rb.reformBlockShape() rb.updateBuffImg() #rb.repaint() pass
def __init__(self,parent, initLabelText, prefix, suffix, labelType, isEditable, blockID, hasComboPopup, tooltipBackground): from blocks.RenderableBlock import RenderableBlock from blocks.FactoryRenderableBlock import FactoryRenderableBlock self.widget= LabelWidget(parent, blockID, initLabelText, prefix, suffix, Block.getBlock(blockID).getColor().darker(), tooltipBackground) self.parent = parent self.zoom = 1.0 self.initLabelText = initLabelText self.labelType = labelType self.blockID = blockID self.hasComboPopup = hasComboPopup # Only editable if the isEditable parameter was true, the label is either a Block's name or # socket label, the block can edit labels, and the block is not in the factory. self.widget.setEditable( isEditable and (labelType == BlockLabel.Type.NAME_LABEL or labelType == BlockLabel.Type.PORT_LABEL) and Block.getBlock(blockID).isLabelEditable() and not isinstance(RenderableBlock.getRenderableBlock(blockID),FactoryRenderableBlock)); if(labelType == None or labelType == (BlockLabel.Type.NAME_LABEL)): self.widget.setFont(BlockLabel.blockFontLarge_Bold); elif(labelType == (BlockLabel.Type.PAGE_LABEL)): self.widget.setFont(BlockLabel.blockFontMedium_Bold); elif(labelType ==(BlockLabel.Type.PORT_LABEL)): self.widget.setFont(BlockLabel.blockFontMedium_Bold); elif(labelType == (BlockLabel.Type.DATA_LABEL)): self.widget.setFont(BlockLabel.blockFontMedium_Bold); # set initial text self.widget.updateLabelText(initLabelText); # add and show the textLabel initially self.widget.setEditingState(False); #famList = {} #if (Block.getBlock(blockID).hasSiblings()) : # famList = Block.getBlock(blockID).getSiblingsList(); #self.widget.setMenu(); self.widget.fireTextChanged = self.textChanged self.widget.fireGenusChanged = self.labelChanged self.widget.fireMenuChanged = self.onRenameVariable
def __init__(self, rb): if (rb != None): self.rb = rb self.blockID = rb.blockID self.block = Block.getBlock(self.blockID) else: print("Cannot create shape of null RenderableBlock.") #initialize gernal path segements around the block shape #self.painterPath = None self.setupProperties()
def onRenameVariable(self, old_name, new_name): from blocks.RenderableBlock import RenderableBlock from blocks.FactoryRenderableBlock import FactoryRenderableBlock from blocks.BlockGenus import BlockGenus rb = RenderableBlock.getRenderableBlock(self.blockID); block = Block.getBlock(self.blockID) familyMap = block.getCustomerFamily(); findVar = False for key in familyMap: if(familyMap[key] == old_name): familyMap[key] = new_name findVar = True if(not findVar): familyMap[new_name] = new_name #self.labelChanged(new_name) #return #factoryBlock = rb.factoryRB #for rb in factoryBlock.child_list: # blockLabel = rb.blockLabel # #blockLabel.widget.setMenu(); # if(blockLabel.getText() == old_name): # blockLabel.labelChanged(new_name) #factoryBlock.blockLabel.widget.setMenu() #if(factoryBlock.blockLabel.getText() == old_name): # factoryBlock.blockLabel.labelChanged(new_name) #print(block.getGenus().familyName) #print(BlockGenus.familyBlocks) if(block.getGenus().familyName in BlockGenus.familyBlocks): for genus in BlockGenus.familyBlocks[block.getGenus().familyName]: genusName = genus.genusName if genusName not in FactoryRenderableBlock.factoryRBs: continue factoryBlock = FactoryRenderableBlock.factoryRBs[genusName] for rb in factoryBlock.child_list: blockLabel = rb.blockLabel #blockLabel.widget.setMenu(); if(blockLabel.getText() == old_name): blockLabel.labelChanged(new_name) #factoryBlock.blockLabel.widget.setMenu(); if(factoryBlock.blockLabel.getText() == old_name): #print(factoryBlock) factoryBlock.blockLabel.labelChanged(new_name)
def onRenameVariable(self, old_name, new_name): from blocks.RenderableBlock import RenderableBlock from blocks.FactoryRenderableBlock import FactoryRenderableBlock from blocks.BlockGenus import BlockGenus rb = RenderableBlock.getRenderableBlock(self.blockID) block = Block.getBlock(self.blockID) familyMap = block.getCustomerFamily() findVar = False for key in familyMap: if (familyMap[key] == old_name): familyMap[key] = new_name findVar = True if (not findVar): familyMap[new_name] = new_name #self.labelChanged(new_name) #return #factoryBlock = rb.factoryRB #for rb in factoryBlock.child_list: # blockLabel = rb.blockLabel # #blockLabel.widget.setMenu(); # if(blockLabel.getText() == old_name): # blockLabel.labelChanged(new_name) #factoryBlock.blockLabel.widget.setMenu() #if(factoryBlock.blockLabel.getText() == old_name): # factoryBlock.blockLabel.labelChanged(new_name) #print(block.getGenus().familyName) #print(BlockGenus.familyBlocks) if (block.getGenus().familyName in BlockGenus.familyBlocks): for genus in BlockGenus.familyBlocks[block.getGenus().familyName]: genusName = genus.genusName if genusName not in FactoryRenderableBlock.factoryRBs: continue factoryBlock = FactoryRenderableBlock.factoryRBs[genusName] for rb in factoryBlock.child_list: blockLabel = rb.blockLabel #blockLabel.widget.setMenu(); if (blockLabel.getText() == old_name): blockLabel.labelChanged(new_name) #factoryBlock.blockLabel.widget.setMenu(); if (factoryBlock.blockLabel.getText() == old_name): #print(factoryBlock) factoryBlock.blockLabel.labelChanged(new_name)
def determineBlockWidth(self): ''' * Overrided from BlockShape. * Determines the width of the sum of the bottom sockets and uses it if it is * greater than the width determined by the determineBlockWidth in BlockShape. * Else, it returns the sum of these two values. ''' # System.out.println("determining block width"); width = BlockShape.determineBlockWidth(self) # if the sum of bottom sockets is greater than the calculated width, then use it bottomSocketWidth = 0 for socket in self.block.getSockets(): if (socket.getPositionType() == BlockConnector.PositionType.BOTTOM ): if (socket.blockID == Block.NULL): # 3 socket spacers = left of socket, between connectors, right of socket bottomSocketWidth += BlockShape.BOTTOM_SOCKET_SIDE_SPACER else: # a block is connected to socket # TODO get their assigned width from rb if (self.rb.getSocketSpaceDimension(socket) != None): bottomSocketWidth += self.rb.getSocketSpaceDimension( socket).width() bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH # if it's a mirror plug, subtract for the other side, too. if (Block.getBlock( socket.blockID).getPlug().getPositionType() == BlockConnector.PositionType.MIRROR): bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH bottomSocketWidth += 2 * BlockShape.BOTTOM_SOCKET_MIDDLE_SPACER # TODO need to decide for a size of the middle spacer and how to place them bottomSocketWidth += 2 * BlockShape.BOTTOM_SOCKET_SIDE_SPACER if (bottomSocketWidth > width): return (bottomSocketWidth + self.rb.accomodateLabelsWidth()) width += bottomSocketWidth # make sure its even if (width % 2 == 1): width += 1 return width
def scrub_(self, block, code): ''' * Common tasks for generating Python from blocks. * Handles comments for the specified block and any connected value blocks. * Calls any statements following this block. * @param {!Blockly.Block} block The current block. * @param {string} code The Python code created for this block. * @return {string} Python code with comments and subsequent blocks added. * @private ''' from blocks.Block import Block commentCode = ''; nextCode = '' #return code ''' # Only collect comments for blocks that aren't inline. if (not block.outputConnection or not block.outputConnection.targetConnection): # Collect comment for this block. comment = block.getCommentText(); if (comment): commentCode += Blockly.Python.prefixLines(comment, '# ') + '\n'; # Collect comments for all value arguments. # Don't collect comments for nested statements. for x in range(0, len(block.inputList)): if (block.inputList[x].type == Blockly.INPUT_VALUE): childBlock = block.inputList[x].connection.targetBlock(); if (childBlock): comment = Blockly.Python.allNestedComments(childBlock); if (comment): commentCode += Blockly.Python.prefixLines(comment, '# '); ''' nextBlockID = block.getAfterBlockID() if(nextBlockID != None and nextBlockID != -1): nextBlock = Block.getBlock(nextBlockID) #nextBlock = block.nextConnection and block.nextConnection.targetBlock(); nextCode = self.blockToCode(nextBlock); #nextCode = nextCode.ljust(len(code) - len(code.lstrip())) #print(code) #nextCode = self.prefixLines(nextCode, self.INDENT); return commentCode + code + nextCode;
def scrub_(self, block, code): ''' * Common tasks for generating Python from blocks. * Handles comments for the specified block and any connected value blocks. * Calls any statements following this block. * @param {!Blockly.Block} block The current block. * @param {string} code The Python code created for this block. * @return {string} Python code with comments and subsequent blocks added. * @private ''' from blocks.Block import Block commentCode = '' nextCode = '' #return code ''' # Only collect comments for blocks that aren't inline. if (not block.outputConnection or not block.outputConnection.targetConnection): # Collect comment for this block. comment = block.getCommentText(); if (comment): commentCode += Blockly.Python.prefixLines(comment, '# ') + '\n'; # Collect comments for all value arguments. # Don't collect comments for nested statements. for x in range(0, len(block.inputList)): if (block.inputList[x].type == Blockly.INPUT_VALUE): childBlock = block.inputList[x].connection.targetBlock(); if (childBlock): comment = Blockly.Python.allNestedComments(childBlock); if (comment): commentCode += Blockly.Python.prefixLines(comment, '# '); ''' nextBlockID = block.getAfterBlockID() if (nextBlockID != None and nextBlockID != -1): nextBlock = Block.getBlock(nextBlockID) #nextBlock = block.nextConnection and block.nextConnection.targetBlock(); nextCode = self.blockToCode(nextBlock) #nextCode = nextCode.ljust(len(code) - len(code.lstrip())) #print(code) #nextCode = self.prefixLines(nextCode, self.INDENT); return commentCode + code + nextCode
def getBlock(self): return Block.getBlock(self.blockID)
def menuEnabled(self): return self.hasComboPopup and Block.getBlock( self.blockID).hasSiblings()
def connect(self): from blocks.RenderableBlock import RenderableBlock from blocks.BlockLinkChecker import BlockLinkChecker from blocks.BlockConnectorShape import BlockConnectorShape # Make sure to disconnect any connections that are going to be overwritten # by this new connection. For example, if inserting a block between two # others, make sure to break that original link.*/ if (self.socket.hasBlock()): # save the ID of the block previously attached to (in) this # socket. This is used by insertion rules to re-link the replaced # block to the newly-inserted block. self.lastPlugBlockID = self.socket.blockID # break the link between the socket block and the block in that socket plugBlock = Block.getBlock(self.lastPlugBlockID) plugBlockPlug = BlockLinkChecker.getPlugEquivalent(plugBlock) if (plugBlockPlug != None and plugBlockPlug.hasBlock()): socketBlock = Block.getBlock(plugBlockPlug.blockID) link = BlockLink.getBlockLink(plugBlock, socketBlock, plugBlockPlug, self.socket) link.disconnect() # don't tell the block about the disconnect like we would normally do, because # we don't actually want it to have a chance to remove any expandable sockets # since the inserted block will be filling whatever socket was vacated by this # broken link. #NOTIFY WORKSPACE LISTENERS OF DISCONNECTION (not sure if this is great because the connection is immediately replaced) #Workspace.getInstance().notifyListeners(new WorkspaceEvent(RenderableBlock.getRenderableBlock(socketBlock.blockID).getParentWidget(), link, WorkspaceEvent.BLOCKS_DISCONNECTED)); if (self.plug.hasBlock()): # in the case of insertion, breaking the link above will mean that # the plug shouldn't be connected by the time we reach here. This # exception will only be thrown if the plug is connected even # after any insertion-esq links were broken above #throw new RuntimeException("trying to link a plug that's already connected somewhere."); return # actually form the connection self.plug.setConnectorBlockID(self.socketBlockID) self.socket.setConnectorBlockID(self.plugBlockID) # notify renderable block of connection so it can redraw with stretching socketRB = RenderableBlock.getRenderableBlock(self.socketBlockID) socketRB.blockConnected(self.socket, self.plugBlockID) if (self.getLastBlockID() != None and self.getLastBlockID() != Block.NULL and BlockConnectorShape.isCommandConnector(self.getPlug()) and BlockConnectorShape.isCommandConnector(self.getSocket())): top = Block.getBlock(self.getPlugBlockID()) while (top.hasAfterConnector() and top.getAfterConnector().hasBlock()): top = Block.getBlock(top.getAfterBlockID()) bottom = Block.getBlock(self.getLastBlockID()) # For safety: if either the top stack is terminated, or # the bottom stack is not a starter, don't try to force a link if (top == None or bottom == None or not top.hasAfterConnector() or not bottom.hasBeforeConnector()): return link = BlockLink.getBlockLink(top, bottom, top.getAfterConnector(), bottom.getBeforeConnector()) link.connect() if (self.clickSound != None): # System.out.println("playing click sound"); pass
def makeBottomSide(self): ''' * Overrided from BlockShape. * Takes into account the need to resize the dimensions of an infix block for various cases. ''' from blocks.RenderableBlock import RenderableBlock from blocks.BlockShapeUtil import BlockShapeUtil # Reset the maximum X-coordinate so the infix block can resize if you remove blocks within it self.maxX = 0 # start bottom-right self.setEndPoint(self.gpBottom, self.botLeftCorner, self.topLeftCorner, True) #curve down and right BlockShapeUtil.cornerTo(self.gpBottom, self.botLeftCorner, self.botRightCorner, self.blockCornerRadius) # BOTTOM SOCKETS # for each socket in the iterator socketCounter = 0 #need to use this to determine which socket we're on for curSocket in self.block.getSockets(): #if bottom socket if (curSocket.getPositionType() == BlockConnector.PositionType.BOTTOM): # move away from bottom left corner if (socketCounter > 0): self.gpBottom.lineTo( self.gpBottom.currentPosition().x() + BlockShape.BOTTOM_SOCKET_MIDDLE_SPACER, self.gpBottom.currentPosition().y()) else: self.gpBottom.lineTo( self.gpBottom.currentPosition().x() + BlockShape.BOTTOM_SOCKET_SIDE_SPACER, self.gpBottom.currentPosition().y()) # move down so bevel doesn't screw up from connecting infinitely sharp corner # as occurs from a curved port BlockShapeUtil.lineToRelative(self.gpBottom, 0, -0.1) #////////////////////// #//begin drawing socket #////////////////////// if (curSocket.blockID == Block.NULL): # draw first socket - up left side leftSocket = BlockShape.BCS.addDataSocketUp( self.gpBottom, curSocket.type, True) self.rb.updateSocketPoint(curSocket, leftSocket) # System.out.println("socket poitn: "+rb.getSocketPoint(curSocket)); # System.out.println("socket poitn leftsocket: "+leftSocket); # draw left standard empty socket space - top side self.gpBottom.lineTo( self.gpBottom.currentPosition().x() + BlockShape.BOTTOM_SOCKET_SIDE_SPACER, self.gpBottom.currentPosition().y()) #draw first socket - down right side BlockShape.BCS.addDataSocket(self.gpBottom, curSocket.type, False) #rb.updateSocketPoint(curSocket, rightSocket); else: # there is a connected block connectedBlock = Block.getBlock(curSocket.blockID) connectedRBlock = RenderableBlock.getRenderableBlock( curSocket.blockID) if (connectedBlock == None or connectedRBlock == None): continue # calculate and update the new socket point # update the socket point of this cursocket which should now adopt the plug socket point of its # connected block since we're also adopting the left side of its shape # Use coordinates when the zoom level is 1.0 to calculate socket point unzoomX = connectedRBlock.getSocketPixelPoint( connectedBlock.getPlug()).x( ) / connectedRBlock.getZoom() unzoomY = connectedRBlock.getSocketPixelPoint( connectedBlock.getPlug()).y( ) / connectedRBlock.getZoom() connectedBlockSocketPoint = QtCore.QPoint( unzoomX, unzoomY) currentPoint = self.gpBottom.currentPosition() newX = connectedBlockSocketPoint.x() + abs( connectedBlockSocketPoint.x() - currentPoint.x()) newY = connectedBlockSocketPoint.y() + abs( connectedRBlock.getBlockHeight() / connectedRBlock.getZoom() - currentPoint.y()) self.rb.updateSocketPoint(curSocket, QtCore.QPoint(newX, newY)) self.gpBottom.currentPosition().x() connectedBlockShape = RenderableBlock.getRenderableBlock( curSocket.blockID).getBlockShape() #append left side of connected block connectedBlockShape.reformArea() BlockShapeUtil.appendPath( self.gpBottom, connectedBlockShape.getLeftSide(), False) connectedBlockShape.getLeftSide().currentPosition() self.gpBottom.currentPosition().x() # append right side of connected block (more complicated) if (connectedBlock.getNumSockets() == 0 or connectedBlock.isInfix()): # append top side of connected block BlockShapeUtil.appendPath( self.gpBottom, connectedBlockShape.getTopSide(), False) BlockShapeUtil.appendPath( self.gpBottom, connectedBlockShape.getRightSide(), False) else: # iterate through the sockets of the connected block, checking if # it has blocks connected to them self.appendRightSidePath(self.gpBottom, connectedBlock, connectedBlockShape) # Updates the maximum X-coordinate and sets the current point to self.maxX if (self.maxX < self.gpBottom.currentPosition().x()): self.maxX = self.gpBottom.currentPosition().x() self.gpBottom.lineTo(self.maxX, self.gpBottom.currentPosition().y()) # bump down so bevel doesn't screw up BlockShapeUtil.lineToRelative(self.gpBottom, 0, 0.1) # System.out.println("gpbottom starting point: "+gpBottom.currentPosition()); # draw RIGHT to create divider //// if (socketCounter < self.block.getNumSockets() - 1): self.gpBottom.lineTo( #need to add the width of the block label. warning: this assumes that there is only one block label self.gpBottom.currentPosition().x() + BlockShape.BOTTOM_SOCKET_MIDDLE_SPACER + self.rb.accomodateLabelsWidth(), self.gpBottom.currentPosition().y()) else: self.gpBottom.lineTo( self.gpBottom.currentPosition().x() + BlockShape.BOTTOM_SOCKET_SIDE_SPACER, self.gpBottom.currentPosition().y()) socketCounter += 1 #curve right and up BlockShapeUtil.cornerTo(self.gpBottom, self.botRightCorner, self.topRightCorner, self.blockCornerRadius) #end bottom self.setEndPoint(self.gpBottom, self.botRightCorner, self.topRightCorner, False)
def createNewInstance(self): rb = BlockUtilities.cloneBlock(Block.getBlock(self.blockID), self.workspace.getActiveCanvas()) self.child_list.append(rb) rb.factoryRB = self return rb
def createNewInstance(self): rb = BlockUtilities.cloneBlock(Block.getBlock(self.blockID), self.workspace.getActiveCanvas() ) self.child_list.append(rb) rb.factoryRB = self return rb
def menuEnabled(self): return self.hasComboPopup and Block.getBlock(self.blockID).hasSiblings()
def connect(self): from blocks.RenderableBlock import RenderableBlock from blocks.BlockLinkChecker import BlockLinkChecker from blocks.BlockConnectorShape import BlockConnectorShape # Make sure to disconnect any connections that are going to be overwritten # by this new connection. For example, if inserting a block between two # others, make sure to break that original link.*/ if (self.socket.hasBlock()): # save the ID of the block previously attached to (in) this # socket. This is used by insertion rules to re-link the replaced # block to the newly-inserted block. self.lastPlugBlockID = self.socket.blockID; # break the link between the socket block and the block in that socket plugBlock = Block.getBlock(self.lastPlugBlockID); plugBlockPlug = BlockLinkChecker.getPlugEquivalent(plugBlock); if (plugBlockPlug != None and plugBlockPlug.hasBlock()): socketBlock = Block.getBlock(plugBlockPlug.blockID); link = BlockLink.getBlockLink(plugBlock, socketBlock, plugBlockPlug, self.socket); link.disconnect(); # don't tell the block about the disconnect like we would normally do, because # we don't actually want it to have a chance to remove any expandable sockets # since the inserted block will be filling whatever socket was vacated by this # broken link. #NOTIFY WORKSPACE LISTENERS OF DISCONNECTION (not sure if this is great because the connection is immediately replaced) #Workspace.getInstance().notifyListeners(new WorkspaceEvent(RenderableBlock.getRenderableBlock(socketBlock.blockID).getParentWidget(), link, WorkspaceEvent.BLOCKS_DISCONNECTED)); if (self.plug.hasBlock()): # in the case of insertion, breaking the link above will mean that # the plug shouldn't be connected by the time we reach here. This # exception will only be thrown if the plug is connected even # after any insertion-esq links were broken above #throw new RuntimeException("trying to link a plug that's already connected somewhere."); return # actually form the connection self.plug.setConnectorBlockID(self.socketBlockID); self.socket.setConnectorBlockID(self.plugBlockID); # notify renderable block of connection so it can redraw with stretching socketRB = RenderableBlock.getRenderableBlock(self.socketBlockID); socketRB.blockConnected(self.socket, self.plugBlockID); if (self.getLastBlockID() != None and self.getLastBlockID() != Block.NULL and BlockConnectorShape.isCommandConnector(self.getPlug()) and BlockConnectorShape.isCommandConnector(self.getSocket())): top = Block.getBlock(self.getPlugBlockID()); while (top.hasAfterConnector() and top.getAfterConnector().hasBlock()): top = Block.getBlock(top.getAfterBlockID()); bottom = Block.getBlock(self.getLastBlockID()); # For safety: if either the top stack is terminated, or # the bottom stack is not a starter, don't try to force a link if (top == None or bottom == None or not top.hasAfterConnector() or not bottom.hasBeforeConnector()): return; link = BlockLink.getBlockLink(top, bottom, top.getAfterConnector(), bottom.getBeforeConnector()); link.connect(); if(self.clickSound != None): # System.out.println("playing click sound"); pass
def from_blockID(cls, workspaceWidget, blockID, isLoading=False,back_color=QtGui.QColor(225,225,225,255)): return FactoryRenderableBlock.from_block(workspaceWidget,Block.getBlock(blockID),False, back_color)