コード例 #1
0
ファイル: BlockStub.py プロジェクト: go2net/PythonBlocks
  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);
コード例 #2
0
    def __init__(self, typeId, size, data):
        Block.__init__(self, typeId, size, data)

        self.magic = str(data[0:4])
        self.gameId = read32(data, 4)

        versionData = read16(data, 8)
        self.versionMajor = versionData >> 12  # First 4 bits
        self.versionMinor = (versionData >> 5) & 0x7F  # Middle 7 bits
        self.versionIncrement = versionData & 0x1F  # Last 5 bits

        self.turn = read16(data, 10)
        self.year = 2400 + self.turn

        playerData = read16(data, 12)
        self.salt = playerData >> 5  # First 11 bits
        self.playerIndex = playerData & 0x1F  # Last 5 bits

        flags = data[15]

        self.turnSubmitted = (flags & (1 << 0)) == 1
        self.hostUsing = (flags & (1 << 1)) == 1
        self.multipleTurns = (flags & (1 << 2)) == 1
        self.gameOver = (flags & (1 << 3)) == 1
        self.shareware = (flags & (1 << 4)) == 1

        pass
コード例 #3
0
    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)
コード例 #4
0
ファイル: FileHeaderBlock.py プロジェクト: runholen/stars
 def __init__(self, typeId, size, data):
     Block.__init__(self, typeId, size, data)
     
     self.magic = str(data[0:4])
     self.gameId = read32(data, 4)
     
     versionData = read16(data, 8)
     self.versionMajor = versionData >> 12          # First 4 bits
     self.versionMinor = (versionData >> 5) & 0x7F  # Middle 7 bits
     self.versionIncrement = versionData & 0x1F     # Last 5 bits
     
     self.turn = read16(data, 10)
     self.year = 2400 + self.turn
     
     playerData = read16(data, 12)
     self.salt = playerData >> 5           # First 11 bits
     self.playerIndex = playerData & 0x1F  # Last 5 bits
     
     flags = data[15]
     
     self.turnSubmitted = (flags & (1 << 0)) == 1
     self.hostUsing =     (flags & (1 << 1)) == 1
     self.multipleTurns = (flags & (1 << 2)) == 1
     self.gameOver =      (flags & (1 << 3)) == 1
     self.shareware =     (flags & (1 << 4)) == 1
     
     pass
コード例 #5
0
ファイル: BlockStub.py プロジェクト: go2net/PythonBlocks
  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();
コード例 #6
0
    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()
コード例 #7
0
    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
コード例 #8
0
   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);
コード例 #9
0
ファイル: BlockLabel.py プロジェクト: go2net/PythonBlocks
  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
コード例 #10
0
    def loadBlockDrawerSets(block_drawersets, manager):
        import json
        if (block_drawersets == ''): return
        f = open(block_drawersets)
        data = json.load(f)

        if 'block_drawer_sets' in data:
            block_drawer_sets = data['block_drawer_sets']
            for drawerElement in block_drawer_sets:
                if 'drawer' in drawerElement and 'genus-list' in drawerElement:
                    drawerName = drawerElement['drawer']
                    canvas = manager.addStaticDrawerNoPos(
                        drawerName, QtGui.QColor(100, 100, 100, 0))
                    drawerRBs = []
                    member = drawerElement['genus-list']
                    for genusName in member:
                        newBlock = Block.createBlock(canvas, genusName, False)
                        if (newBlock == None): continue

                        rb = FactoryRenderableBlock.from_block(
                            canvas, newBlock, False,
                            QtGui.QColor(225, 225, 225, 100))
                        drawerRBs.append(rb)
                        FactoryRenderableBlock.factoryRBs[genusName] = rb
                    manager.addStaticBlocks(drawerRBs, drawerName)
        return
コード例 #11
0
    def loadBlockDrawerSets(self, root):
        from blocks.Block import Block
        from blocks.FactoryRenderableBlock import FactoryRenderableBlock

        drawerSetNodes = root.findall("BlockDrawerSets/BlockDrawerSet")

        for drawerSetNode in drawerSetNodes:
            drawerNodes = drawerSetNode.getchildren()

            # retreive drawer information of this bar
            for drawerNode in drawerNodes:
                if (drawerNode.tag == "BlockDrawer"):
                    if ("name" in drawerNode.attrib):
                        drawerName = drawerNode.attrib["name"]
                        node = FactoryTreeNode(self.rootNode, drawerName)
                        self.rootNode.children.append(node)

                        #manager.addStaticDrawerNoPos(drawerName, QtGui.QColor(100,100,100,0));

                        drawerBlocks = drawerNode.getchildren()
                        blockNode = None
                        for blockNode in drawerBlocks:
                            if (blockNode.tag == "BlockGenusMember"):
                                genusName = blockNode.text
                                newBlock = Block.createBlock(
                                    None, genusName, False)
                                rb = FactoryRenderableBlock.from_blockID(
                                    None, newBlock.blockID, False,
                                    QtGui.QColor(225, 225, 225, 100))
                                sub_node = FactoryTreeNode(node, rb)
                                node.children.append(sub_node)

                #manager.addStaticBlocks(drawerRBs, drawerName);
        return self.rootNode
コード例 #12
0
    def showBlock(self, genus):
        from blocks.Block import Block
        from blocks.FactoryRenderableBlock import FactoryRenderableBlock
        from PyQt4.QtCore import Qt 
        
        if(genus == None): return

        block = Block.createBlockFromID(None, genus.genusName)
        
        preview_wnd_layout  = self.mainWnd.wndPreview.layout()

        #for i in reversed(range(preview_wnd_layout.count())):
        #    preview_wnd_layout.itemAt(i).widget().setParent(None)
        
        for i in reversed(range(preview_wnd_layout.count())):
            widget = preview_wnd_layout.itemAt(i).widget()
            widget.setParent(None)
            widget.deleteLater()
            
        self.factoryRB = FactoryRenderableBlock.from_block(None, block)
        self.factoryRB.updateBuffImg()
        #factoryRB.setParent(self.mainWnd.wndPreview)
        #print('%d:%d'%(factoryRB.getBlockWidth(), factoryRB.getBlockHeight()))
        self.factoryRB.setFixedSize(self.factoryRB.width(), self.factoryRB.height())
        preview_wnd_layout.addWidget(self.factoryRB, Qt.AlignCenter); 
    
        pass 
コード例 #13
0
    def loadBlockDrawerSets(self, root):
        from blocks.Block import Block
        from blocks.FactoryRenderableBlock import FactoryRenderableBlock

        drawerSetNodes = root.findall("BlockDrawerSets/BlockDrawerSet")

        for drawerSetNode in drawerSetNodes:
            drawerNodes=drawerSetNode.getchildren()

            # retreive drawer information of this bar
            for drawerNode in drawerNodes:
                if(drawerNode.tag == "BlockDrawer"):
                    if("name" in drawerNode.attrib):
                        drawerName = drawerNode.attrib["name"]
                        node = FactoryTreeNode(self.rootNode, drawerName)
                        self.rootNode.children.append(node)

                        #manager.addStaticDrawerNoPos(drawerName, QtGui.QColor(100,100,100,0));

                        drawerBlocks = drawerNode.getchildren()
                        blockNode = None
                        for blockNode in drawerBlocks:
                            if(blockNode.tag == "BlockGenusMember"):
                                genusName = blockNode.text
                                newBlock = Block.createBlock(None, genusName, False)
                                rb = FactoryRenderableBlock.from_blockID(None, newBlock.blockID,False, QtGui.QColor(225,225,225,100))
                                sub_node = FactoryTreeNode(node, rb)
                                node.children.append(sub_node)
                                

                #manager.addStaticBlocks(drawerRBs, drawerName);
        return self.rootNode
コード例 #14
0
    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())
コード例 #15
0
ファイル: BlockLabel.py プロジェクト: go2net/PythonBlocks
  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();
コード例 #16
0
 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)
コード例 #17
0
    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()
コード例 #18
0
    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
コード例 #19
0
    def mouseMoveEvent(self, e):
        from blocks.Block import Block
        from blocks.FactoryRenderableBlock import FactoryRenderableBlock
        from components.PyMimeData import PyMimeData
        from components.DrawerSetsTreeView import DrawerSetsTreeNode

        if e.buttons() != Qt.LeftButton:
            return

        genusName = self.currentItem().text()
        newBlock = Block.createBlock(None, genusName, False)
        rb = FactoryRenderableBlock.from_blockID(None, newBlock.blockID, False,
                                                 QColor(225, 225, 225, 100))
        sub_node = DrawerSetsTreeNode(None, rb)
        mimeData = PyMimeData(sub_node)

        # write the relative cursor position to mime data
        #mimeData = QMimeData()

        #item = self.currentItem()
        #mimeData.setText(item.text())

        #block = Block.createBlockFromID(None, genusName)
        #factoryRB = FactoryRenderableBlock.from_block(None, block)

        #print(self.mainWnd.genusTreeModel.factoryRB)
        # let's make it fancy. we'll show a "ghost" of the button as we drag
        # grab the button to a pixmap
        pixmap = QPixmap.grabWidget(rb)
        mimeData.setImageData(pixmap)

        # below makes the pixmap half transparent
        painter = QPainter(pixmap)
        painter.setCompositionMode(painter.CompositionMode_DestinationIn)
        painter.fillRect(pixmap.rect(), QColor(0, 0, 0, 127))
        painter.end()

        # make a QDrag
        drag = QDrag(self)
        # put our MimeData
        drag.setMimeData(mimeData)
        # set its Pixmap
        drag.setPixmap(pixmap)
        # shift the Pixmap so that it coincides with the cursor position
        drag.setHotSpot(QPoint(0, 0))

        # start the drag operation
        # exec_ will return the accepted action from dropEvent
        if drag.exec_(Qt.CopyAction | Qt.MoveAction) == Qt.MoveAction:
            #print ('moved')
            pass
        else:
            #print ('copied')
            pass
コード例 #20
0
ファイル: BlockLabel.py プロジェクト: go2net/PythonBlocks
  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
コード例 #21
0
    def mouseMoveEvent(self, e):
        from blocks.Block import Block
        from blocks.FactoryRenderableBlock import FactoryRenderableBlock
        from components.PyMimeData import PyMimeData
        from components.DrawerSetsTreeView import DrawerSetsTreeNode        

        if e.buttons() != Qt.LeftButton:
            return
        
        genusName =  self.currentItem().text()
        newBlock = Block.createBlock(None, genusName, False)
        rb = FactoryRenderableBlock.from_blockID(None, newBlock.blockID,False, QColor(225,225,225,100))
        sub_node = DrawerSetsTreeNode(None, rb)        
        mimeData = PyMimeData(sub_node) 
        
        # write the relative cursor position to mime data
        #mimeData = QMimeData()
        
        #item = self.currentItem()
        #mimeData.setText(item.text())
        
        #block = Block.createBlockFromID(None, genusName)
        #factoryRB = FactoryRenderableBlock.from_block(None, block)
        
        #print(self.mainWnd.genusTreeModel.factoryRB)
        # let's make it fancy. we'll show a "ghost" of the button as we drag
        # grab the button to a pixmap
        pixmap = QPixmap.grabWidget(rb)
        mimeData.setImageData(pixmap)
        
        # below makes the pixmap half transparent
        painter = QPainter(pixmap)
        painter.setCompositionMode(painter.CompositionMode_DestinationIn)
        painter.fillRect(pixmap.rect(), QColor(0, 0, 0, 127))
        painter.end()        

        # make a QDrag
        drag = QDrag(self)
        # put our MimeData
        drag.setMimeData(mimeData)
        # set its Pixmap
        drag.setPixmap(pixmap)
        # shift the Pixmap so that it coincides with the cursor position
        drag.setHotSpot(QPoint (0, 0))

        # start the drag operation
        # exec_ will return the accepted action from dropEvent
        if drag.exec_(Qt.CopyAction | Qt.MoveAction) == Qt.MoveAction:
            #print ('moved')
            pass
        else:
            #print ('copied')
            pass
コード例 #22
0
ファイル: BlockShape.py プロジェクト: shyamal388/PythonBlocks
    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()
コード例 #23
0
ファイル: BlockLabel.py プロジェクト: go2net/PythonBlocks
  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)
コード例 #24
0
    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)
コード例 #25
0
ファイル: PlanetsBlock.py プロジェクト: runholen/stars
    def __init__(self, typeId, size, data):
        Block.__init__(self, typeId, size, data)
        
        # TODO bytes 0-3 
        
        self.universeSize = read16(data, 4) # Uses all 16 bits?
        self.density = read16(data, 6)      # Uses all 16 bits?
        self.playerCount = read16(data, 8)  # Uses all 16 bits?
        self.planetCount = read16(data, 10)
        self.startingDistance = read32(data, 12)

        # 16 bits?
        self.gameSettings = read16(data, 16)  
        """
        Determined bits of game settings:
        
        Max Minerals       - 0000000000000001
        Slow tech advances - 0000000000000010
        Accel. BBS play    - 0000000000100000
        No random events   - 0000000010000000
        Computer Alliances - 0000000000010000
        Public scores      - 0000000001000000
        Galaxy Clumping    - 0000000100000000
        Single player (?)  - 0000000000000100
        
        What is bit 4?       0000000000001000
        """
                
        # TODO bytes 18-31
        
        self.gameName = str(data[32:64])
        
        # This is a list of planets with their nameId, x, and y coordinates
        self.planets = []
        
        pass
コード例 #26
0
 def buildNodes(self, data):
     from blocks.Block import Block
     from blocks.FactoryRenderableBlock import FactoryRenderableBlock        
     if 'block_drawer_sets' in data:
         block_drawer_sets = data['block_drawer_sets']
         for drawerElement in block_drawer_sets:
             if 'drawer' in drawerElement and 'genus-list' in drawerElement:
                 drawerName = drawerElement['drawer']
                 node = DrawerSetsTreeNode(self.rootNode, drawerName, False)
                 self.rootNode.children.append(node)                
                 member = drawerElement['genus-list']
                 for genusName in member:
                     newBlock = Block.createBlock(None, genusName, False)
                     if(newBlock == None): continue
                     
                     rb = FactoryRenderableBlock.from_blockID(None, newBlock.blockID,False, QtGui.QColor(255,255,255,0))
                     sub_node = DrawerSetsTreeNode(node, rb)
                     node.children.append(sub_node)
コード例 #27
0
ファイル: PythonGen.py プロジェクト: go2net/PythonBlocks
    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;
コード例 #28
0
    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
コード例 #29
0
ファイル: __init__.py プロジェクト: tupelo-schneck/stars
def createBlock(typeId, size, data):
    '''
    This method will create a block from the typeId
    '''
    className = BLOCKS[typeId]
    path = "blocks." + className + "." + className
    block = None

    try:
        clazz = import_class(path)
        block = clazz(typeId, size, data)
    except:
        print "Block type not implemented. typeId: %s; Class: %s" % (
            str(typeId), className)

        # Return generic block for now
        block = Block(typeId, size, data)

    return block
コード例 #30
0
    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
コード例 #31
0
    def buildNodes(self, data):
        from blocks.Block import Block
        from blocks.FactoryRenderableBlock import FactoryRenderableBlock
        if 'block_drawer_sets' in data:
            block_drawer_sets = data['block_drawer_sets']
            for drawerElement in block_drawer_sets:
                if 'drawer' in drawerElement and 'genus-list' in drawerElement:
                    drawerName = drawerElement['drawer']
                    node = DrawerSetsTreeNode(self.rootNode, drawerName, False)
                    self.rootNode.children.append(node)
                    member = drawerElement['genus-list']
                    for genusName in member:
                        newBlock = Block.createBlock(None, genusName, False)
                        if (newBlock == None): continue

                        rb = FactoryRenderableBlock.from_blockID(
                            None, newBlock.blockID, False,
                            QtGui.QColor(255, 255, 255, 0))
                        sub_node = DrawerSetsTreeNode(node, rb)
                        node.children.append(sub_node)
コード例 #32
0
ファイル: MainWnd.py プロジェクト: go2net/PythonBlocks
 def showBlock(self, genus):
     #from blocks.BlockGenus import BlockGenus
     from blocks.Block import Block
     from blocks.FactoryRenderableBlock import FactoryRenderableBlock
 
     if(genus == None): return   
 
     block = Block.createBlockFromID(None, genus.genusName)
         
     child_list = self.wndPreview.findChildren(FactoryRenderableBlock)
     for i in reversed(range(len(child_list))): 
         child_list[i].deleteLater()
 
     factoryRB = FactoryRenderableBlock.from_block(None, block)
         
     factoryRB.setParent(self.wndPreview)
     factoryRB.show()  
         
     factoryRB.move((self.wndPreview.width() - factoryRB.width())/2, (self.wndPreview.height() - factoryRB.height())/2)
 
     pass
コード例 #33
0
    def showBlock(self, genus):
        #from blocks.BlockGenus import BlockGenus
        from blocks.Block import Block
        from blocks.FactoryRenderableBlock import FactoryRenderableBlock

        if (genus == None): return

        block = Block.createBlockFromID(None, genus.genusName)

        child_list = self.wndPreview.findChildren(FactoryRenderableBlock)
        for i in reversed(range(len(child_list))):
            child_list[i].deleteLater()

        factoryRB = FactoryRenderableBlock.from_block(None, block)

        factoryRB.setParent(self.wndPreview)
        factoryRB.show()

        factoryRB.move((self.wndPreview.width() - factoryRB.width()) / 2,
                       (self.wndPreview.height() - factoryRB.height()) / 2)

        pass
コード例 #34
0
   def loadBlockDrawerSets(block_drawersets, manager):
        import json
        if(block_drawersets == ''): return
        f=open(block_drawersets)
        data=json.load(f)

        if 'block_drawer_sets' in data:
            block_drawer_sets = data['block_drawer_sets']
            for drawerElement in block_drawer_sets:
                if 'drawer' in drawerElement and 'genus-list' in drawerElement:
                    drawerName = drawerElement['drawer']
                    canvas = manager.addStaticDrawerNoPos(drawerName, QtGui.QColor(100,100,100,0));  
                    drawerRBs = []
                    member = drawerElement['genus-list']
                    for genusName in member:
                        newBlock = Block.createBlock(canvas, genusName, False)
                        if(newBlock == None): continue
                        
                        rb = FactoryRenderableBlock.from_block(canvas, newBlock,False, QtGui.QColor(225,225,225,100))
                        drawerRBs.append(rb);
                        FactoryRenderableBlock.factoryRBs[genusName] = rb
                    manager.addStaticBlocks(drawerRBs, drawerName) 
        return
コード例 #35
0
 def menuEnabled(self):
     return self.hasComboPopup and Block.getBlock(
         self.blockID).hasSiblings()
コード例 #36
0
   def cloneBlock(myblock, canvas):
      mygenusname = myblock.getGenusName();
      label = myblock.getBlockLabel();

      # sometimes the factory block will have an assigned label different
      # from its genus label.
      if(myblock.getInitialLabel() != (myblock.getBlockLabel())):
         # acquire prefix and suffix length from myblock label
         prefixLength = len(myblock.getLabelPrefix());
         suffixLength = len(myblock.getLabelSuffix());
         # we need to set the block label without the prefix and suffix attached because those
         # values are automatically concatenated to the string specified in setBlockLabel.  I know its
         # weird, but its the way block labels were designed.
         if(prefixLength > 0 or suffixLength > 0):  # TODO we could do this outside of this method, even in constructor
            label = myblock.getBlockLabel()


      # check genus instance counter and if label unique - change label accordingly
      # also check if label already has a value at the end, if so update counter to have the max value
      # TODO ria need to make this smarter
      # some issues to think about:
      #  - what if they throw out an instance, such as setup2? should the next time they take out
      #    a setup block, should it have setup2 on it?  but wouldn't that be confusing?
      #  - when we load up a new project with some instances with numbered labels, how do we keep
      #    track of new instances relative to these old ones?
      #  - the old implementation just iterated through all the instances of a particular genus in the
      #    workspace and compared a possible label to the current labels of that genus.  if there wasn't
      #    any current label that matched the possible label, it returned that label.  do we want to do this?
      #   is there something more efficient?

      labelWithIndex = label;  # labelWithIndex will have the instance value

      # initialize value that will be appended to the end of the label
      if(mygenusname in BlockUtilities.instanceCounter):
         value = BlockUtilities.instanceCounter[mygenusname];
      else:
         value = 0;
      # begin check for validation of label
      # iterate until label is valid
      while(not BlockUtilities.isLabelValid(myblock, labelWithIndex, canvas)):
         value +=1;
         labelWithIndex = labelWithIndex + value;


      # set valid label and save current instance number
      BlockUtilities.instanceCounter[mygenusname] = value
      if(labelWithIndex != (label)): # only set it if the label actually changed...
         label = labelWithIndex;

      if(isinstance(myblock,BlockStub)):
         parent = myblock.getParent();
         block = BlockStub(parent.blockID, parent.getGenusName(), parent.getBlockLabel(), myblock.getGenusName());
      else:
         block = Block.createBlock(canvas, myblock.getGenusName(), True, label);

      # TODO - djwendel - create a copy of the RB properties too, using an RB copy constructor.  Don't just use the genus.
      # RenderableBlock renderable = new RenderableBlock(this.getParentWidget(), block.blockID);

      renderable = RenderableBlock.from_blockID(canvas, block.blockID);
      #renderable.initFinished = False
      #renderable.setZoomLevel(BlockUtilities.zoom);
      #renderable.redrawFromTop();
      #renderable.repaint();
      return renderable;
コード例 #37
0
ファイル: BlockLabel.py プロジェクト: go2net/PythonBlocks
 def menuEnabled(self):
     return self.hasComboPopup and Block.getBlock(self.blockID).hasSiblings()
コード例 #38
0
 def createNewInstance(self):
     rb = BlockUtilities.cloneBlock(Block.getBlock(self.blockID), self.workspace.getActiveCanvas() )
     self.child_list.append(rb)
     rb.factoryRB = self
     return rb
コード例 #39
0
    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
コード例 #40
0
    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)
コード例 #41
0
 def getBlock(self):
     return Block.getBlock(self.blockID)
コード例 #42
0
 def createNewInstance(self):
     rb = BlockUtilities.cloneBlock(Block.getBlock(self.blockID),
                                    self.workspace.getActiveCanvas())
     self.child_list.append(rb)
     rb.factoryRB = self
     return rb
コード例 #43
0
ファイル: LabelWidget.py プロジェクト: go2net/PythonBlocks
 def getBlock(self):
     return Block.getBlock(self.blockID)
コード例 #44
0
ファイル: BlockLink.py プロジェクト: go2net/PythonBlocks
    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
コード例 #45
0
 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)