class MenuItenListenerIcon(Element, ClickHandler): def __init__(self, feedBack, value, classIcon, **kw): Element.__init__(self, Element=DOM.createElement('li'), **kw) ClickHandler.__init__(self) self.classIcon = classIcon self.value = value self.icon = Element(Element=DOM.createElement("i"), StyleName=classIcon) self.add(self.icon) self.title = Element(Element=DOM.createSpan(), StyleName='title') DOM.setInnerHTML(self.title.getElement(), self.value) self.add(self.title) self.addClickListener(self) self.feedBack = feedBack def getClassIcon(self): return self.classIcon def setClassIcon(self, classIcon): self.classIcon = classIcon self.icon.setStyleName(self.classIcon) def changeTexts(self): DOM.setInnerHTML(self.title.getElement(), _(self.value)) def onClick(self, sender): #add selected self.feedBack(self.classIcon)
class Button(Element, ClickHandler, MouseHandler): def __init__(self, text, listener, classIcon=""): Element.__init__(self, Element=DOM.createElement('li'), StyleName='btn') ClickHandler.__init__(self) MouseHandler.__init__(self) self.text = text self.classIcon = classIcon self.draw() if listener is not None: self.addClickListener(listener) def draw(self): if self.classIcon != "": self.icon = Element(Element=DOM.createElement("i"), StyleName=self.classIcon) self.add(self.icon) 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')) def setText(self, text): self.text = text DOM.setInnerHTML(self.title.getElement(), self.text) def changeIcon(self, classIcon): self.classIcon = classIcon DOM.setAttribute(self.icon.getElement(), "className", classIcon)
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()
def addArgument(s, arg): mode = 'input' if s.mode == INPUT else 'output' row = Element(Element=DOM.createTR(), StyleName='simple_hardware_pin') td = Element(Element=DOM.createTD(), StyleName='simple_hardware_pin_left') row.append(td) td = Element(Element=DOM.createTD(), StyleName='simple_hardware_pin_label simple_' + mode + '_pin') DOM.setInnerText(td.getElement(), arg.label) row.append(td) td = Element(Element=DOM.createTD(), StyleName='dropdown_holder simple_' + mode + '_pin') td.add(arg) row.append(td) s.bodyArguments.append(row)
class SubCategoryPanel(VerticalPanel): def __init__(self, subCategoryName='', subCategoryClassName='', openList=True): self.list = VerticalPanel(StyleName='block_list') self.list.setStyleAttribute("display", "block") VerticalPanel.__init__(self, StyleName='SubCategoryPanel') self.subCategoryName = subCategoryName if subCategoryName != '': self.title = Element(Element=DOM.createElement('dt'), StyleName=subCategoryClassName) DOM.setInnerHTML(self.title.getElement(), self.subCategoryName) self.collapse = FocusWidget(Element=DOM.createDiv(), StyleName='collapse close_up') self.collapse.addClickListener(self.showHide) self.title.add(self.collapse) self.add(self.title) if openList: self.list.setStyleAttribute("display", "block") self.collapse.setStyleName('collapse close_up') else: self.list.setStyleAttribute("display", "none") self.collapse.setStyleName('collapse open_down') self.add(self.list) self.blocks = [] self.count = 0 def changeTexts(self): if self.subCategoryName != '': DOM.setInnerHTML(self.title.getElement(), _(self.subCategoryName)) self.title.add(self.collapse) for block in self.blocks: block.changeTexts() def addBlock(self, block, classHelp='help_default', beforeIndex=None): panel = HorizontalPanel() panel.add(block) info = Label('i', StyleName='info_btn') info.block = block info.classHelp = classHelp info.addClickListener(self.showInfo) panel.add(info) if beforeIndex is not None: self.list.insert(panel, self.list.getBody(), 0) #deprecated else: self.list.add(panel) self.list.setStyleName(self.list.getWidgetTd(panel), 'block_info') self.blocks.append(block) if block.name in [ 'commandType', 'numericType', 'logicType', 'alphaNumericType' ]: panel.add(self.getRemoveCustomBlock(block)) info.addMouseListener(TooltipListener("Editar")) else: info.addMouseListener(TooltipListener("Ajuda")) def getRemoveCustomBlock(self, block): remove = Label('x', StyleName='remove_btn') remove.addMouseListener(TooltipListener("Remover")) remove.block = block remove.addClickListener(self.RemoveCustomBlock) return remove def RemoveCustomBlock(self, sender): self.list.remove(sender.block.getParent()) self.blocks.remove(sender.block) if len(self.blocks) == 0: self.getParent().reload() del createdBlocks[sender.block.varName] stateChange() def removeBlock(self, block): self.list.remove(block.getParent()) self.blocks.remove(block) def removeAllBlocks(self): while len(self.blocks) > 0: self.removeBlock(self.blocks[0]) def addWidget(self, widget): self.list.add(widget) def showInfo(self, sender): if sender.block.name in [ 'commandType', 'numericType', 'logicType', 'alphaNumericType' ]: createdBlocks[sender.block.varName].show() else: popup = Popup('<b>' + _('Help') + '</b>', None, None) popup.center.append( Widget(Element=DOM.createDiv(), StyleName=sender.classHelp)) popup.caption.setStyleAttribute('text-align', 'center') popup.show() def showHide(self): if self.list.getStyleAttribute('display') == 'none': self.list.setStyleAttribute("display", "block") self.collapse.setStyleName('collapse close_up') else: self.list.setStyleAttribute("display", "none") self.collapse.setStyleName('collapse open_down') def changeTitle(self, count): # faz perder o collapse DOM.setInnerHTML(self.title.getElement(), _(self.subCategoryName) + ': #' + str(count)) self.title.add(self.collapse) self.count = count
def enableRadioButton(self, radio, block, enable): fake = Element(Element=DOM.createDiv()) if enable: block.removeStyleName('disabled') else: block.addStyleName('disabled') fake.append(block) radio.setHTML(fake.getElement().innerHTML)
def onLoad(self): self.add(self.header) self.setCellHeight(self.header, '38px') self.left.add(self.blockList) self.left.add(self.hardwareList) self.mainPanel = HorizontalPanel(Width='100%', Height='100%') self.mainPanel.add(self.left) self.mainPanel.setCellWidth(self.left, '250') self.middle.add(self.blocksPad) self.middle.add(self.hardwaresPad) self.center = VerticalPanel(Width='100%', Height='100%', StyleName="center_panel") self.center.add(self.middle) #--------------------------------------------------------------------------------------------------------- bottom = Element(Element=DOM.createDiv(), StyleName='drawer_bottom') self.showHideLeft = FocusWidget(Element=DOM.createDiv(), StyleName='control_bar close_left') self.showHideLeft.addClickListener(self.showHidePanelLeft) self.showHideLeft.setStyleAttribute('float', 'lef') bottom.add(self.showHideLeft) self.showHideRight = FocusWidget(Element=DOM.createDiv(), StyleName='control_bar') self.showHideRight.addClickListener(self.showHidePanelRight) bottom.add(self.showHideRight) self.showHideMonitor = FocusWidget(Element=DOM.createDiv(), StyleName='control_bar') self.showHideMonitor.addClickListener(self.showHidePanelMonitor) bottom.add(self.showHideMonitor) self.resizeMonitor = ResizeWidget(self.serialMonitor, 100, 400, invert=True, horizontal=False) DOM.setStyleAttribute(self.resizeMonitor.getElement(), "display", "none") bottom.add(self.resizeMonitor) self.center.add(bottom) self.center.setCellHeight(bottom, '20px') usbFlash = FocusWidget(Element=DOM.createDiv()) usbFlash.setID('cb_cf') DOM.setElemAttribute(usbFlash.getElement(), 'data-sections', 'usbflash serialmonitor') self.serialMonitor.add(usbFlash) progress = Element(Element=DOM.createDiv(), StyleName='progress progress-striped active') progress.setID('progress') DOM.setStyleAttribute(progress.getElement(), "display", "none") progress_val = Element(Element=DOM.createDiv(), StyleName='bar') progress_val.setID('progress_val') progress.add(progress_val) self.serialMonitor.add(progress) monitor = Element(Element=DOM.createDiv()) monitor.setID('monitor') self.serialMonitor.add(monitor) self.center.add(self.serialMonitor) self.center.setCellHeight(self.serialMonitor, '100') self.showHidePanelMonitor() #--------------------------------------------------------------------------------------------------------- self.mainPanel.add(self.center) #--------------------------------------------------------------------------------------------------------- self.cod = VerticalPanel(Width='100%', Height='100%', StyleName="right_panel") divCode = Element(Element=DOM.createDiv(), Width='100%', Height='100%', StyleName="download-button-container") divCode.add(self.codeTextArea) divButtonDownload = FocusWidget(Element=DOM.createDiv(), StyleName="download-button") #divButtonDownload.addClickListener(listener=lambda:exportWiringCode(self.codeTextArea.getText())) divButtonDownload.addClickListener(listener=lambda: exportWiringCode()) DOM.setInnerText(divButtonDownload.getElement(), 'download') divCode.add(divButtonDownload) self.cod.add(divCode) bot = Element(Element=DOM.createDiv(), StyleName='drawer_bottom') res = ResizeWidget(self.cod, 100, 500, invert=True) res.setStyleAttribute('float', 'left') bot.append(res) self.cod.add(bot) self.cod.setCellHeight(bot, '20px') self.mainPanel.add(self.cod) self.mainPanel.setCellWidth(self.cod, '200') self.showHidePanelRight() self.header.buttonBlocks.addClickListener(self.showBlocksList) self.header.buttonHarwares.addClickListener(self.showHardwaresList) self.header.buttonTranslate.addClickListener(self.showPanelRight) #self.header.buttonReload.addClickListener(self.hidePanelRight) #--------------------------------------------------------------------------------------------------------- self.add(self.mainPanel) stateChange() self.changeLanguage('pt_BR')
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()
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()