def draw(self): Popup.draw(self) namePanel = HorizontalPanel() namePanel.add(Label(_('Name') + ':')) self.textBox = TextBox() self.textBox.setMaxLength(15) self.textBox.setStyleAttribute('marginLeft', 10) namePanel.add(self.textBox) self.center.add(namePanel) self.choose = ChooseTypeVarPanel() self.center.add(self.choose) self.textBox.addInputListener(self) self.message = Element(Element=DOM.createDiv()) self.message.add(Widget(Element=DOM.createDiv(), StyleName='not_image')) self.message.add( Label(text=_('Name already used'), wordWrap=False, StyleName='not_message')) self.onInput()
def draw(self): Popup.draw(self) namePanel = HorizontalPanel() #namePanel.add(Label('Crie um arquivo')) if self.title == 'Abrir': self.enableOkButton(False) namePanel.add(HTML("""<div class=""gwt-Label"" style=""white-space: normal;""> Abra o arquivo salvo, copie<br>e cole aqui o conteudo:</div>""")) self.field = FileUpload() self.field.setName('file') self.field.setID('files') self.center.add(self.field) element = self.field.getElement() JS("""function handleFileSelect(evt) {@{{self}}.enableOkButton(evt.target.files[0]!=null);} @{{element}}.addEventListener('change', handleFileSelect, false);""") #http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml else: namePanel.add(HTML("""<div class=""gwt-Label"" style=""white-space: normal;""> Crie um arquivo txt e copie<br>e cole o conteudo a seguir:</div>""")) self.textBox = TextBox() self.textBox.setStyleAttribute('marginLeft', 10) namePanel.add(self.textBox) self.center.add(namePanel) self.textBox.addInputListener(self) self.onInput()
def showInfo(self, sender): if sender.block.name in ['commandType', 'numericType', 'logicType', 'alphaNumericType']: createdBlocks[sender.block.varName].show() else: popup = Popup('<b>Ajuda</b>', None, None) popup.center.append(Widget(Element=DOM.createDiv(), StyleName=sender.classHelp)) popup.caption.setStyleAttribute('text-align', 'center') popup.show()
def myOkClick(self): if 'disabled' not in self.okButton.getStyleName(): Popup.myOkClick(self) if self.okClick is not None: if self.title == 'Abrir': files = getattr(self.field.getElement(), 'files') file = JS("@{{files}}[0]") if file: JS("""var reader = new FileReader(); reader.onload = function(e) {@{{self}}.okClick(e.target.result);} reader.readAsBinaryString(@{{file}});""") #self.okClick(str) else: self.okClick(self.textBox.getText())
def show(self): Popup.show(self) if self.title != 'Abrir': self.textBox.setFocus(True) else: pass
def myCancelClick(self): Popup.myCancelClick(self) if self.cancelClick is not None: self.cancelClick()
def __init__(self, okClick, cancelClick, title='Abrir', options=CONFIRM_CANCEL): Popup.__init__(self, title, okClick, cancelClick, options)
def show(self): Popup.show(self) self.textBox.setFocus(True)
def myOkClick(self): if 'disabled' not in self.okButton.getStyleName(): Popup.myOkClick(self) self.okClick(self.textBox.getText(), self.choose.selectedType)
def __init__(self, okClick, cancelClick): Popup.__init__(self, '<b>Nova Variável</b>', okClick, cancelClick, CONFIRM_CANCEL)
def __init__(self, okClick, cancelClick): Popup.__init__(self, '<b>' + _('New Block') + '</b>', okClick, cancelClick, CONFIRM_CANCEL)
def onClick(self, sender=None, automatic=False): #self.codePanel.setText("") JS('''$doc.defaultView.editor.getSession().setValue();'''); loopBlockSet = [] rootSetupBlock = None if getWorkspace().getMainBlock() is not None: rootSetupBlock = getWorkspace().getMainBlock().getFirstBlock() if rootSetupBlock == getWorkspace().getMainBlock(): rootSetupBlock = None #for block in rootBlocks: # if block.name == 'forever': # loopBlockSet.append(block) loopBlockSet.append(getWorkspace().getMainBlock()) if len(loopBlockSet) == 0 and not automatic: self.showBlocksList() popup = Popup('<b>Bloco sempre nao encontrado!</b>', None, None) center = VerticalPanel() center.append(getattr(ArduinoBlocks, 'forever')(off=True)) popup.center.append(center) popup.center.setCellHorizontalAlignment(center, HasHorizontalAlignment.ALIGN_CENTER) popup.show() return if len(loopBlockSet) > 1 and not automatic: # deprecated popup = Popup('<b>Multiplos blocos sempre encontrados!</b>', None, None) popup.show() return for block in loopBlockSet: try: code_ = Translator().translate(block, rootSetupBlock) #self.codePanel.setText(code_) JS('''$doc.defaultView.editor.getSession().setValue(@{{code_}});'''); except SocketNullException as e1: if automatic: return; self.showBlocksList() if e1.block.blockPad.popupEditorBlock: e1.block.blockPad.popupEditorBlock.show() fakeBlock = getattr(ArduinoBlocks, e1.block.name)(off=True) #fakeBlock.holderArguments[e1.index].argument.addStyleName('error') # estava confundindo fakeBlock.holderArguments[e1.index].argument.append(Widget(Element=DOM.createDiv(), StyleName='interro')) center = VerticalPanel() center.append(fakeBlock) #☹ popup = Popup('<b>Dado ausente no bloco abaixo:</b>', None, None) popup.center.append(center) popup.center.setCellHorizontalAlignment(center, HasHorizontalAlignment.ALIGN_CENTER) popup.show() except VariableNameNullException as e2: if automatic: return; self.showBlocksList() fakeBlock = getattr(ArduinoBlocks, e2.block.name)(off=True) #fakeBlock.dropDownVarName.addStyleName('error') #fakeBlock.dropDownVarName.append(Widget(Element=DOM.createDiv(), StyleName='interro')) center = VerticalPanel() center.append(fakeBlock) popup = Popup('<b>'+e2.getError()+' abaixo:</b>', None, None) popup.center.append(center) popup.center.setCellHorizontalAlignment(center, HasHorizontalAlignment.ALIGN_CENTER) popup.show() except ComponentPinNullException as e3: if automatic: return; self.showHardwaresList() fakeBlock = getattr(ArduinoHardwares, e3.block.componetHardware)(off=True) fakeBlock.setText(e3.block.varName) center = VerticalPanel() center.append(fakeBlock) popup = Popup('<b>'+e3.getError()+' abaixo:</b>', None, None) popup.center.append(center) popup.center.setCellHorizontalAlignment(center, HasHorizontalAlignment.ALIGN_CENTER) popup.show() except ComponentBlockNotFoundException as e4:#todo: exception quando nao encontra o custom block if automatic: return; self.showHardwaresList() fakeBlock = getattr(ArduinoHardwares, e4.block.componetHardware)(off=True) fakeBlock.setText(e4.block.varName) center = VerticalPanel() center.append(fakeBlock) popup = Popup('<b>'+e4.getError()+':</b>', None, None) popup.center.append(center) popup.center.setCellHorizontalAlignment(center, HasHorizontalAlignment.ALIGN_CENTER) popup.show()