def __init__(self):
     HorizontalPanel.__init__(self, StyleName="type_block select_block")
     self.add(Label('Tipo:'))       
     
     fake = Element(Element=DOM.createDiv())
     
     self.booleanBlock = getattr(ArduinoBlocks, 'logicType')('logica', 'red', off=True)
     fake.append(self.booleanBlock)
     self.logicType = RadioButton("group1", fake.getElement().innerHTML, True)
     self.logicType.addClickListener(getattr(self, "onClickLogicType"))
     self.add(self.logicType)
     fake.removeAll()
     
     self.numberBlock = getattr(ArduinoBlocks, 'numericType')('numerica', 'red', off=True)
     fake.append(self.numberBlock)
     self.numericType = RadioButton("group1", fake.getElement().innerHTML, True)
     self.numericType.setChecked(True)
     self.numericType.addClickListener(getattr(self, "onClickNumericType"))
     self.add(self.numericType)
     fake.removeAll()
     
     self.stringBlock = getattr(ArduinoBlocks, 'alphaNumericType')('alfanumerica', 'red', off=True)
     fake.append(self.stringBlock)
     self.alphaNumericType = RadioButton("group1", fake.getElement().innerHTML, True)
     self.alphaNumericType.addClickListener(getattr(self, "onClickAlphanumericType"))
     self.add(self.alphaNumericType)
     
     self.onClickNumericType()
class OperationElement(Element, ClickHandler):
                     
    def __init__(self, text, group, groupLabel, block):
        Element.__init__(self, Element=DOM.createElement('code'), StyleName='group_operation')
        ClickHandler.__init__(self)
        self.addClickListener(self)
        self.text = text
        self.group = group
        self.groupLabel = groupLabel
        self.block = block
        self.draw()
        
    def changeTexts(self):
        if self.text != '':
            DOM.setInnerHTML(self.title.getElement(), _(self.text))

    def draw(self):
        self.title = Element(Element=DOM.createSpan(), StyleName='title')
        DOM.setInnerHTML(self.title.getElement(), self.text)
        self.add(self.title)
        self.tip = PopupPanel(Element=DOM.createElement('code'), autoHide=True, modal=False, rootpanel=self)
        div = Element(Element=DOM.createElement('div'), StyleName='joyride-tip-guide')
        div.add(Widget(Element=DOM.createSpan(), StyleName='joyride-nub left'))
        self.tipItens = Element(Element=DOM.createElement('div'), StyleName='tip-itens')
        div.add(self.tipItens)
        self.tip.add(div)
        
    def onClick(self, sender):
        if self.tip.showing: self.tip.hide()
        else:
            if self.groupLabel is None: self.addValues(self.group)
            else: self.addValues(self.groupLabel)         
            self.tip.show()
    
    def addValues(self, values):
        self.tipItens.removeAll()
        if len(values)==2: self.tip.getWidget().addStyleName('two_itens')
        else: self.tip.getWidget().removeStyleName('two_itens')
        if len(values)==3: self.tip.getWidget().addStyleName('tree_itens')
        else: self.tip.getWidget().removeStyleName('tree_itens')
        for value in values.keys():
            self.tipItens.append(MenuItenListener(self.itemClick, value, StyleName='tip-item'))
    
    def itemClick(self, value):
        if self.block.original: return
        oldValue = self.block.name
        if self.groupLabel is None:
            DOM.setInnerHTML(self.title.getElement(), _(value))
            self.block.name = self.group[value]
        else:
            DOM.setInnerHTML(self.title.getElement(), _(self.groupLabel[value]))
            self.block.name = self.group[self.groupLabel[value]]
        if oldValue != value:
            from edu.uca.util.Serializable import stateChange
            stateChange()
            
class Dropdown(Element, ClickHandler, MouseHandler):
    def __init__(self,
                 text,
                 menuClick,
                 itemClick,
                 classIcon="",
                 rootPanel=None,
                 **kw):
        Element.__init__(self, Element=DOM.createElement('li'), **kw)
        ClickHandler.__init__(self)
        MouseHandler.__init__(self)
        self.text = text
        self.itemClick = itemClick
        self.menuClick = menuClick
        self.addClickListener(self)
        self.classIcon = classIcon
        self.rootPanel = rootPanel
        self.draw()

    def onClick(self, sender):
        if self.popup.showing: self.popup.hide()
        else:
            if self.menuClick is not None:
                self.menuClick()
            self.popup.show()

    def draw(self):
        if self.classIcon != "":
            self.icon = Element(Element=DOM.createElement("i"),
                                StyleName=self.classIcon)
            self.add(self.icon)

        if self.rootPanel is None:
            self.popup = PopupPanel(autoHide=True,
                                    modal=False,
                                    rootpanel=self,
                                    StyleName='dropdown_btn')
            DOM.setStyleAttribute(self.popup.element, "position", "static")
        else:  #o poup nao esta fechando!
            self.popup = PopupPanel(autoHide=True,
                                    modal=False,
                                    rootpanel=self.rootPanel,
                                    StyleName='dropdown_btn')

        self.dropdown_arrow = Element(Element=DOM.createElement('div'),
                                      StyleName='dropdown_arrow')
        self.title = Element(Element=DOM.createSpan(), StyleName='title')
        DOM.setInnerHTML(self.title.getElement(), self.text)
        self.add(self.title)
        self.add(Widget(Element=DOM.createDiv(), StyleName='r'))
        self.add(Widget(Element=DOM.createDiv(), StyleName='coverup'))
        self.popup.add(self.dropdown_arrow)

    def changeIcon(self, classIcon):
        DOM.setAttribute(self.icon.getElement(), "className", classIcon)

    def setText(self):
        DOM.setInnerHTML(self.title.getElement(), self.text)

    def changeTexts(self):
        for iten in self.dropdown_arrow.children:
            iten.changeTexts()

    def ItenClick(self, value):
        self.itemClick(value)

    def getValues(self):
        return self.dropdown_arrow.children

    def addValues(self, values):
        self.removeValues()
        for value in values:
            self.addValue(value)

    def addValue(self, value, classIcon=''):
        if classIcon == '':
            self.dropdown_arrow.append(
                MenuItenListener(self.ItenClick,
                                 value,
                                 StyleName='dropdownItem'))
        else:
            self.dropdown_arrow.append(
                MenuItenListenerIcon(self.ItenClick,
                                     value,
                                     classIcon,
                                     StyleName='dropdownItem'))

    def removeValues(self):
        self.dropdown_arrow.removeAll()
Exemple #4
0
    def __init__(self, categoryChangeListener):
        HorizontalPanel.__init__(self,
                                 StyleName="category_block select_block",
                                 Width='100%')
        self.categoryChangeListener = categoryChangeListener

        self.add(Label('Categoria:'))
        verticalPanel = VerticalPanel(Width='100%')
        self.add(verticalPanel)
        horizontalPanel = HorizontalPanel(Width='100%')
        verticalPanel.add(horizontalPanel)

        fake = Element(Element=DOM.createDiv())

        self.control = getattr(ArduinoBlocks, 'alphaNumericType')('Controle',
                                                                  'orange',
                                                                  off=True)
        fake.append(self.control)
        self.controlType = RadioButton("groupCategory",
                                       fake.getElement().innerHTML, True)
        self.controlType.setChecked(True)
        self.controlType.addClickListener(getattr(self, "onClickControlType"))
        horizontalPanel.add(self.controlType)
        fake.removeAll()

        self.operators = getattr(ArduinoBlocks,
                                 'alphaNumericType')('Operadores',
                                                     'green',
                                                     off=True)
        fake.append(self.operators)
        self.operatorsType = RadioButton("groupCategory",
                                         fake.getElement().innerHTML, True)
        self.operatorsType.addClickListener(
            getattr(self, "onClickOperatorsType"))
        horizontalPanel.add(self.operatorsType)
        horizontalPanel = HorizontalPanel(Width='100%')
        verticalPanel.add(horizontalPanel)
        fake.removeAll()

        self.input = getattr(ArduinoBlocks, 'alphaNumericType')('Entrada',
                                                                'purple',
                                                                off=True)
        fake.append(self.input)
        self.inputType = RadioButton("groupCategory",
                                     fake.getElement().innerHTML, True)
        self.inputType.addClickListener(getattr(self, "onClickInputType"))
        horizontalPanel.add(self.inputType)
        fake.removeAll()

        self.output = getattr(ArduinoBlocks, 'alphaNumericType')('Saida',
                                                                 'blue',
                                                                 off=True)
        fake.append(self.output)
        self.outputType = RadioButton("groupCategory",
                                      fake.getElement().innerHTML, True)
        self.outputType.addClickListener(getattr(self, "onClickOutputType"))
        horizontalPanel.add(self.outputType)
        horizontalPanel = HorizontalPanel(Width='100%')
        verticalPanel.add(horizontalPanel)
        fake.removeAll()

        self.utilities = getattr(ArduinoBlocks,
                                 'alphaNumericType')('Utilitarios',
                                                     'darkblue',
                                                     off=True)
        fake.append(self.utilities)
        self.utilitiesType = RadioButton("groupCategory",
                                         fake.getElement().innerHTML, True)
        self.utilitiesType.addClickListener(
            getattr(self, "onClickUtilitiesType"))
        horizontalPanel.add(self.utilitiesType)
        fake.removeAll()

        self.variables = getattr(ArduinoBlocks,
                                 'alphaNumericType')('Variaveis',
                                                     'red',
                                                     off=True)
        fake.append(self.variables)
        self.variablesType = RadioButton("groupCategory",
                                         fake.getElement().innerHTML, True)
        self.variablesType.addClickListener(
            getattr(self, "onClickVariablesType"))
        horizontalPanel.add(self.variablesType)

        self.onClickControlType()