コード例 #1
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
コード例 #2
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
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
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)
コード例 #7
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)
コード例 #8
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
コード例 #9
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;