Exemplo n.º 1
0
 def onDragLeave(self, event):
     dt = event.dataTransfer
     dt.dropEffect = 'none'
     if hasattr(getWorkspace().getMovingBlock(), 'original'):
         if not getWorkspace().getMovingBlock().original:
             self.removeStyleName('dragover')
             self.trashCan.setStyleName('trashCanClose trashCanCloseFadeIn')
Exemplo n.º 2
0
def loadAllComponents(components):
    for iten in components:
        comp = loadComponent(iten)
        getWorkspace().getHardwaresPad().add(comp)
    # atualiza a subcategoria 'Components' das categorias 'Entrada' e 'Sa�da'
    getWorkspace().getBlockList().refreshComponentBlocks(
        getWorkspace().getHardwaresPad().children)
Exemplo n.º 3
0
def setDragStartPosition(event):  #, undo):
    dt = event.dataTransfer
    target = DOM.eventGetTarget(event)
    clientX, clientY = event.clientX, event.clientY
    absx, absy = clientX + Window.getScrollLeft(
    ), clientY + Window.getScrollTop()

    # para arrastar um component ou bloco entre abas
    from edu.uca.renderable.block.Block import Block
    from edu.uca.util.Serializable import saveStackBlock
    from edu.uca.Workspace import getWorkspace
    from edu.uca.renderable.hardware.ComponentBlock import ComponentBlock
    from edu.uca.util.Serializable import saveComponent
    if (isinstance(getWorkspace().getMovingBlock(), ComponentBlock)):
        package = json.dumps({
            "offsetX":
            absx - DOM.getAbsoluteLeft(target),  # armagenar a origem para undo
            "offsetY":
            absy - DOM.getAbsoluteTop(target),
            "componetHardware":
            saveComponent(getWorkspace().getMovingBlock())
        })
    elif (isinstance(getWorkspace().getMovingBlock(), Block)):
        package = json.dumps({
            "offsetX":
            absx - DOM.getAbsoluteLeft(target),  # armagenar a origem para undo
            "offsetY":
            absy - DOM.getAbsoluteTop(target),
            "stackBlock":
            saveStackBlock(getWorkspace().getMovingBlock())
        })

    dt.setData('text', package)
    dt.allowedEffects = 'copy'  # using "copy" here because Windows Chrome does not like "move"
Exemplo n.º 4
0
 def onDrop(self, event):
     #print "BlockHolder: onDrop"
     DOM.eventStopPropagation(
         event)  # nao deixar ir para o onDrop de BlocksPad
     if self.subBlock == getWorkspace().getMovingBlock():
         return  # retirou e colocou o mesmo bloco
     #---------------------------------------------------
     if getWorkspace().getMovingBlock().original:
         getWorkspace().setMovingBlock(getWorkspace().cloneBlock(
             getWorkspace().getMovingBlock()))
         #undo = (getWorkspace().getBlockList().removeBlocks, [getWorkspace().getMovingBlock()])
     #else: undo = getWorkspace().getUndo()
     #---------------------------------------------------
     if self.up:  #self.argument.statementArgumentType == UP_ARG
         #undo = (self.removeUpperBlock, [undo, self.block.getStyleAttribute('left'), self.block.getStyleAttribute('top'), getWorkspace().getMovingBlock().original])
         #do = (self.addUpperBlock, [getWorkspace().getMovingBlock(), getWorkspace().getMovingBlock().original, event])
         self.addUpperBlock(getWorkspace().getMovingBlock(),
                            getWorkspace().getMovingBlock().original,
                            event)  #
     else:
         #do = (self.addSubBlock, [getWorkspace().getMovingBlock(), getWorkspace().getMovingBlock().original])
         self.addSubBlock(getWorkspace().getMovingBlock(),
                          getWorkspace().getMovingBlock().original)  #
     #---------------------------------------------------
     #history.add(do, undo)
     from edu.uca.util.Serializable import stateChange
     stateChange()
Exemplo n.º 5
0
    def __init__(self, ws):

        VerticalPanel.__init__(self, Width='100%', Height='100%')

        self.codeTextArea = Element(Element=DOM.createDiv(),
                                    StyleName='codePanel')
        self.codeTextArea.setID('clip_text')
        #self.codeTextArea.setReadonly(True)
        #self.codeTextArea.addClickListener(listener=lambda:self.codeTextArea.selectAll())
        ws.setCodePanel(self.codeTextArea)

        self.header = Header(self.changeLanguage)
        getWorkspace().setHeaderPanel(self.header)

        self.blockList = BlockList()
        self.hardwareList = HardwareList()
        self.hardwareList.addStyleName('invisible')
        self.left = Element(Element=DOM.createDiv(),
                            Width='100%',
                            Height='100%')
        ws.setBlockList(self.blockList)
        ws.setHardwaresList(self.hardwareList)

        self.serialMonitor = Element(Element=DOM.createDiv(),
                                     StyleName='serialMonitor')

        self.blocksPad = BlocksPad()
        self.hardwaresPad = HardwaresPad()
        self.hardwaresPad.addStyleName('invisible')
        self.middle = Element(Element=DOM.createDiv(),
                              Width='100%',
                              Height='100%')
        ws.setBlocksPad(self.blocksPad)
        ws.setHardwaresPad(self.hardwaresPad)
 def __init__(self, statementArgumentType, index=None):
     Argument.__init__(self, [Block.STATEMENT_BLOCK], StyleName='highlight')
     if statementArgumentType == self.DOWN_ARG:
         self.accepts.append(Block.END_BLOCK)
     self.statementArgumentType = statementArgumentType
     self.index = index
     getWorkspace().getBlocksPad().addBlockDragListener(self)
     getWorkspace().getBlockList().addBlockDragListener(self)
Exemplo n.º 7
0
 def onDragLeave(self, event):
     #print "Left: onDragLeave"
     if getWorkspace().getMovingBlock() is None: return
     dt = event.dataTransfer
     dt.dropEffect = 'none'
     if not getWorkspace().getMovingBlock().original:
         self.removeStyleName('dragover')
         self.trashCan.setStyleName('trashCanClose trashCanCloseFadeIn')
Exemplo n.º 8
0
 def onDragOver(self, event):
     if getWorkspace().getMovingBlock() is None: return
     dt = event.dataTransfer
     dt.dropEffect = 'copy'
     if hasattr(getWorkspace().getMovingBlock(), 'original'):
         if not getWorkspace().getMovingBlock().original:
             self.addStyleName('dragover')
             self.trashCan.setStyleName('trashCanOpen')
     DOM.eventPreventDefault(event)
Exemplo n.º 9
0
 def onMouseEnter(self, sender):
     rootSetupBlock = None
     if getWorkspace().getMainBlock() is not None:
         rootSetupBlock = getWorkspace().getMainBlock().getFirstBlock()
     self.mainStack = []
     self.createMainStack(rootSetupBlock)
     allBlocks = getWorkspace().getBlocks()
     for block in allBlocks:
         if block not in self.mainStack:
             block.addStyleName('disabled')
Exemplo n.º 10
0
 def changeTexts(self):
     getWorkspace().getBlockList().changeTexts()
     #getWorkspace().getBlocksPad().changeTexts() nao pega os subblocks!
     for block in getWorkspace().getBlocks():
         block.changeTexts()
     getWorkspace().getHeaderPanel().changeTexts()
     getWorkspace().getHardwaresList().changeTexts()
     getWorkspace().getHardwaresPad().changeTexts()
Exemplo n.º 11
0
 def popupConfirmOpenState(s, change=True):
     getWorkspace().reload()
     dic = json.decode(s)
     loadAllVariables(dic['variables'])
     loadAllComponents(dic['components'])
     loadAllCustomBlocks(dic['customBlocks'])
     loadAllStackBlocks(dic['blocks'])
     if change: stateChange()
     #traduz todos os blocos
     for block in getWorkspace().getBlocks():
         block.changeTexts()
     getWorkspace().getHardwaresPad().changeTexts()
Exemplo n.º 12
0
    def onDragStart(self, event):
        setDragStartPosition(event)
        #print getWorkspace().getMovingBlock().original
        #getWorkspace().setUndo((self.addBlock, [getWorkspace().getMovingBlock(),
        #                                        getWorkspace().getMovingBlock().getStyleAttribute('left'),#convert int()?
        #                                        getWorkspace().getMovingBlock().getStyleAttribute('top'),
        #                                        getWorkspace().getMovingBlock().original]))#n�o funciona
        for listener in self._blockDragListeners:
            listener.onBlockDragStart(event, getWorkspace().getMovingBlock())

        getWorkspace().getBlockList().trashCan.addStyleName(
            'trashCanCloseFadeIn')
Exemplo n.º 13
0
 def onDragEnd(self, event):
     #print 'Bloco: ' +self.name +' onDragEnd'
     if getWorkspace().getMovingBlock() == self:
         self.removeStyleName('invisible')
         if isinstance(self.parent, BlockHolder):
             self.parent.argument.setStyleAttribute('display', 'none')
             self.parent.block.resize()
             # verificar se essas coisas envolta sao necessarias
     self.removeStyleName('ondrag')
     if getWorkspace().getMovingBlock() is not None:
         if getWorkspace().getMovingBlock().blockPad is not None:
             getWorkspace().getMovingBlock().blockPad.removeStyleName(
                 'dragover2')
Exemplo n.º 14
0
 def removeBlocks(
         self, root):  # remove o bloco e seus subblocos da lista de blocos
     if root is None: return
     getWorkspace().removeBlock(root)  # Tentando remover um bloco original
     for holder in root.holderArguments:
         self.removeBlocks(holder.subBlock)
     for holder in root.holderChildren:
         self.removeBlocks(holder.subBlock)
     if root.holderSiblingDown is not None:
         self.removeBlocks(root.holderSiblingDown.subBlock)
     if isinstance(root, MainBlock):
         self.showMainBlock()
         getWorkspace().setMainBlock(None)
     root.removeFromParent()
Exemplo n.º 15
0
    def onDrop(self, event):
        #print "Right: onDrop"

        if getWorkspace().getMovingBlock() is None:

            ####################################################################################
            import json
            from edu.uca.util.Serializable import loadStackBlock, stateChange
            stackBlock = loadStackBlock(
                json.loads(event.dataTransfer.getData('text'))['stackBlock'])
            stackBlock.changeTexts()
            self.addBlock(stackBlock, getDropPosition(self, event), True)
            stateChange()
            ####################################################################################

            return

        #soundOut.play()
        if getWorkspace().getMovingBlock().original:
            self.removeStyleName('dragover2')
            getWorkspace().setMovingBlock(getWorkspace().cloneBlock(
                getWorkspace().getMovingBlock()))
            #undo = (getWorkspace().getBlockList().removeBlocks, [getWorkspace().getMovingBlock()])
        #else: undo = getWorkspace().getUndo()
        left, top = getDropPosition(self, event)
        #history.add((self.addBlock, [getWorkspace().getMovingBlock(), left, top, getWorkspace().getMovingBlock().original]), undo)
        self.addBlock(getWorkspace().getMovingBlock(), left, top,
                      getWorkspace().getMovingBlock().original)
        #for action in history._actions:
        #    print action._do
        #    print action._undo

        from edu.uca.util.Serializable import stateChange
        stateChange()
Exemplo n.º 16
0
def stateChange():
    if stateIndex < len(states) - 1:
        del states[stateIndex + 1:]

    if len(states) < stateMax: stateIndex += 1
    else:
        for i in range(len(states) - 1):
            states[i] = states[i + 1]
        states.pop()

    states.insert(stateIndex, saveState(returnState=True))
    refreshUndoRedoButtons()
    #tradu��o autom�tica aqui.
    if getWorkspace().getHeaderPanel().isAutomatic:
        getWorkspace().getHeaderPanel().codeGenerator.onClick(automatic=True)
Exemplo n.º 17
0
 def onDragStart(self, event):
     #print "Left: onDragStart"
     setDragStartPosition(
         event
     )  #verificar se realmente � necess�rio REMOVI (talvez tenha que colocar para undo)
     for listener in self._blockDragListeners:
         listener.onBlockDragStart(event, getWorkspace().getMovingBlock())
Exemplo n.º 18
0
 def popupConfirmOpenState(s):
     dic = json.decode(s)
     loadAllCustomBlocks(dic['customBlocks'])
     stateChange()
     #traduz todos os blocos
     for block in getWorkspace().getBlocks():
         block.changeTexts()
Exemplo n.º 19
0
def refreshUndoRedoButtons():
    hearder = getWorkspace().getHeaderPanel()
    if stateIndex > 0: hearder.buttonUndo.removeStyleName('disabled')
    else: hearder.buttonUndo.addStyleName('disabled')
    if stateIndex < len(states) - 1:
        hearder.buttonRedo.removeStyleName('disabled')
    else:
        hearder.buttonRedo.addStyleName('disabled')
Exemplo n.º 20
0
 def onBrowserEvent(self, event):
     if DOM.eventGetType(event) in DROP_EVENTS and not self.block.original:
         mb = getWorkspace().getMovingBlock()
         if not DOM.isOrHasChild(
                 mb.getElement(),
                 self.getElement()) and mb.blockType in self.accepts:
             DropHandler.onBrowserEvent(self, event)
     elif DOM.eventGetType(event) in KEYBOARD_EVENTS:
         KeyboardHandler.onBrowserEvent(self, event)
Exemplo n.º 21
0
    def onDragOver(self, event):
        if getWorkspace().getMovingBlock() is None:

            ####################################################################################
            import json
            if json.loads(event.dataTransfer.getData(
                    'text'))['stackBlock'] is not None:
                event.dataTransfer.dropEffect = 'copy'
                DOM.eventPreventDefault(event)
            ####################################################################################

            return

        dt = event.dataTransfer
        dt.dropEffect = 'copy'
        if getWorkspace().getMovingBlock().original:
            self.addStyleName('dragover2')
        DOM.eventPreventDefault(event)
Exemplo n.º 22
0
    def onDragEnd(self, event):
        #print 'Right: '+getWorkspace().getMovingBlock().name+' onDragEnd'
        #dt = event.dataTransfer
        #if dt.dropEffect == 'none':
        #def ontimer(timer):
        #    self.ws.getMovingBlock().removeStyleName('invisible')
        #Timer(500, notify=ontimer)

        for listener in self._blockDragListeners:
            listener.onBlockDragEnd(event, getWorkspace().getMovingBlock())

        #getWorkspace().getMovingBlock().removeStyleName('invisible')
        #print getWorkspace().getMovingBlock().parentBlock
        #if getWorkspace().getMovingBlock().parentBlock is not None:
        #    getWorkspace().getMovingBlock().parentBlock.resize()
        getWorkspace().setMovingBlock(None)

        getWorkspace().getBlockList().trashCan.removeStyleName(
            'trashCanCloseFadeIn')
Exemplo n.º 23
0
    def onDrag(self, event):
        #print 'Bloco: onDrag'
        if getWorkspace().getMovingBlock() == self:
            if not self.original:
                self.addStyleName('invisible')

            if self.isStartingDrag:
                self.isStartingDrag = False
                self.addStyleName('ondrag')
                if isinstance(self.parent, BlockHolder):
                    self.parent.argument.setStyleAttribute('display', 'block')
                    self.parent.block.resize()
Exemplo n.º 24
0
 def addSubBlock(self, newSubBlock, original):
     if self.subBlock == newSubBlock: return
     #---------------------------------------------------------------------------------
     if self.subBlock is not None:
         removed = self.subBlock
         self.remove(self.subBlock)
         if newSubBlock is not None:
             removed.parentBlock = newSubBlock.getLastBlock()
             newSubBlock.removeFromParent()
             newSubBlock.getLastBlock().holderSiblingDown.addSubBlock(
                 removed, removed.original)
     #---------------------------------------------------------------------------------
     self.subBlock = newSubBlock
     #---------------------------------------------------------------------------------
     if self.subBlock is not None:
         #-----------------------------------------------------------------------------
         if original:
             self.subBlock.original = False
             getWorkspace().addBlock(self.subBlock)
             from edu.uca.renderable.block.MainBlock import MainBlock
             if isinstance(self.subBlock, MainBlock):
                 getWorkspace().setMainBlock(self.subBlock)
                 getWorkspace().getBlockList().hideMainBlock()
         #-----------------------------------------------------------------------------
         self.subBlock.parentBlock = self.block
         self.subBlock.blockPad = self.block.blockPad
         self.subBlock.setStyleAttribute({'top': 0, 'left': 0})
         self.add(self.subBlock)  #bug! self.subBlock.parentBlock fica nulo
         self.subBlock.parentBlock = self.block  #because self.add(self.subBlock) is bug!
         if self.subBlock.holderSiblingUp:
             self.subBlock.holderSiblingUp.argument.enable = False
     #---------------------------------------------------------------------------------
     self.block.resize()
     self.argument.setStyleAttribute('display', 'none')
Exemplo n.º 25
0
    def onDrop(self, event):
        if getWorkspace().getMovingBlock() is None: return
        self.removeStyleName('dragover')
        if hasattr(getWorkspace().getMovingBlock(), 'original'):
            if not getWorkspace().getMovingBlock().original:
                getWorkspace().getMovingBlock().removeFromParent()
                del hardwares[getWorkspace().getMovingBlock().getCompleteText(
                )]  # remove da lista de componentes
                getWorkspace().setMovingBlock(None)

                from edu.uca.util.Serializable import stateChange
                stateChange()

                self.trashCan.setStyleName("trashCanClose")

        DOM.eventPreventDefault(event)
Exemplo n.º 26
0
def loadAllVariables(varList):
    varCategory = getWorkspace().getBlockList(
    ).variables  # obtem a categoria das vari�veis
    for textVar in varList['logicVars']:
        varCategory.popupConfirmNewVar(textVar,
                                       Block.BOOLEAN_BLOCK,
                                       saveChange=False)  # add vars l�gicas
    for textVar in varList['numericVars']:
        varCategory.popupConfirmNewVar(textVar,
                                       Block.NUMBER_BLOCK,
                                       saveChange=False)  # add vars num�ricas
    for textVar in varList['alphaNumericVars']:
        varCategory.popupConfirmNewVar(
            textVar, Block.STRING_BLOCK,
            saveChange=False)  # add var alfanum�ricas
Exemplo n.º 27
0
    def onDrop(self, event):
        #print "Left: onDrop"
        if getWorkspace().getMovingBlock() is None: return
        self.removeStyleName('dragover')
        if not getWorkspace().getMovingBlock().original:

            #do = (self.removeBlocks, [getWorkspace().getMovingBlock()])
            self.removeBlocks(getWorkspace().getMovingBlock())  #
            #history.add(do, getWorkspace().getUndo()) # � preciso saber de onde vem

            for listener in self._blockDragListeners:
                listener.onBlockDragEnd(event, getWorkspace().getMovingBlock())
            getWorkspace().getMovingBlock().onDragEnd()  #finaliza - para undo
            getWorkspace().setMovingBlock(None)

            from edu.uca.util.Serializable import stateChange
            stateChange()

            self.trashCan.setStyleName("trashCanClose")
Exemplo n.º 28
0
 def addBlock(self, block, left, top, original):
     if original:
         block.original = False
         getWorkspace().addBlock(block)
         if isinstance(block, MainBlock):
             getWorkspace().setMainBlock(block)
             getWorkspace().getBlockList().hideMainBlock(
             )  # passar para dentro do setMainBlock
     else:
         block.removeFromParent()
     block.setStyleAttribute({'left': left, 'top': top})
     block.blockPad = self
     Element.add(self, block)
Exemplo n.º 29
0
def popupConfirmNewBlock(nameBlock, categoryBlock, typeBlock, showPopup=True):
    if categoryBlock == ChooseCategoryBlockPanel.CONTROL: color = 'orange'
    elif categoryBlock == ChooseCategoryBlockPanel.OPERATORS: color = 'green'
    elif categoryBlock == ChooseCategoryBlockPanel.INPUT: color = 'purple'
    elif categoryBlock == ChooseCategoryBlockPanel.OUTPUT: color = 'blue'
    elif categoryBlock == ChooseCategoryBlockPanel.UTILITIES:
        color = 'darkblue'
    elif categoryBlock == ChooseCategoryBlockPanel.VARIBLES:
        color = 'red'

    if typeBlock == Block.STATEMENT_BLOCK: attribute = 'commandType'
    elif typeBlock == Block.NUMBER_BLOCK: attribute = 'numericType'
    elif typeBlock == Block.BOOLEAN_BLOCK: attribute = 'logicType'
    elif typeBlock == Block.STRING_BLOCK: attribute = 'alphaNumericType'

    block = getattr(ArduinoBlocks, attribute)(nameBlock, color)
    getattr(getWorkspace().getBlockList(), categoryBlock).addSubCategory(block)

    popup = PopupBlockEditor(block, categoryBlock, True)
    createdBlocks[nameBlock] = popup

    if showPopup:
        from edu.uca.util.Serializable import stateChange
        stateChange()
Exemplo n.º 30
0
def loadStackBlock(root):
    if not root['custom']:
        block = getattr(ArduinoBlocks, root['name'])()  # cria um bloco padr�o
    else:
        block = getattr(ArduinoBlocks, root['name'])(
            root['varName'], root['color'])  # cria um bloco customizado
    block.setStyleAttribute({
        'left': root['left'],
        'top': root['top']
    })  # configura a posi��o x e y do bloco
    block.original = False  # configura o atributo original
    getWorkspace().addBlock(block)  # adiciona o bloco na lista de blocos

    if root['type'] == Block.END_BLOCK:  # se bloco principal
        getWorkspace().setMainBlock(block)  # adiciona na vari�ve global
        getWorkspace().getBlockList().hideMainBlock(
        )  # oculta da lista de blocos

    arguments = root['arguments']  # adiciona recursivamente os argumentos
    for index, arg in enumerate(
            arguments):  # verifica se o argumento � um bloco ou um texto
        if arg['type'] == 'argument':
            block.holderArguments[index].setArgumentValue(arg['value'])
        else:
            block.holderArguments[index].addSubBlock(loadStackBlock(arg))

    children = root['children']  # adiciona recursivamente os blocos filhos
    for index, child in enumerate(children):
        block.holderChildren[index].addSubBlock(loadStackBlock(child))

    if root['siblingDown'] is not None:  # adiciona recursivamentes os blocos subsequentes
        block.holderSiblingDown.addSubBlock(loadStackBlock(
            root['siblingDown']))

    if root['varName'] is not '' and not root[
            'custom']:  # adiciona o valor da dropDownVarName
        block.dropDownVarName.setValue(root['varName'])

    return block