class FormPanelDemo(SimplePanel): def __init__(self): SimplePanel.__init__(self) self.form = FormPanel(Action="http://google.com/search", Target="results") vPanel = VerticalPanel(Spacing=5) hPanel = HorizontalPanel(Spacing=5) hPanel.add(Label("Search for:")) hPanel.add(TextBox(Name="q")) hPanel.add(Button("Submit", self)) vPanel.add(hPanel) results = NamedFrame("results", Width="100%", Height="200px") vPanel.add(results) self.form.add(vPanel) self.add(self.form) def onClick(self, event): self.form.submit()
class FormPanelDemo(SimplePanel): def __init__(self): SimplePanel.__init__(self) self.form = FormPanel(Action="http://google.com/search", Target="results") vPanel = VerticalPanel(Spacing=5) hPanel = HorizontalPanel(Spacing=5) hPanel.add(Label("Search for:")) hPanel.add(TextBox(Name="q")) hPanel.add(Button("Submit", self)) vPanel.add(hPanel) results = NamedFrame("results", Width="100%", Height="200px") vPanel.add(results) self.form.add(vPanel) self.add(self.form) def onClick(self, event): self.form.submit()
class FileUploadDemo(SimplePanel): def __init__(self): SimplePanel.__init__(self) self.form = FormPanel() self.form.setEncoding(FormPanel.ENCODING_MULTIPART) self.form.setMethod(FormPanel.METHOD_POST) self.form.setAction("http://nonexistent.com") self.form.setTarget("results") vPanel = VerticalPanel() hPanel = HorizontalPanel() hPanel.setSpacing(5) hPanel.add(Label("Upload file:")) self.field = FileUpload() self.field.setName("file") hPanel.add(self.field) hPanel.add(Button("Submit", getattr(self, "onBtnClick"))) vPanel.add(hPanel) results = NamedFrame("results") vPanel.add(results) self.form.add(vPanel) self.add(self.form) def onBtnClick(self, event): self.form.submit()
class FileUploadDemo(SimplePanel): def __init__(self): SimplePanel.__init__(self) self.form = FormPanel() self.form.setEncoding(FormPanel.ENCODING_MULTIPART) self.form.setMethod(FormPanel.METHOD_POST) self.form.setAction("http://nonexistent.com") self.form.setTarget("results") vPanel = VerticalPanel() hPanel = HorizontalPanel() hPanel.setSpacing(5) hPanel.add(Label("Upload file:")) self.field = FileUpload() self.field.setName("file") hPanel.add(self.field) hPanel.add(Button("Submit", getattr(self, "onBtnClick"))) vPanel.add(hPanel) results = NamedFrame("results") vPanel.add(results) self.form.add(vPanel) self.add(self.form) def onBtnClick(self, event): self.form.submit()
def htmlElements(self, addList = None): if not self._htmlElements: h = HTML("<h1>Run data</h1>", StyleName='font-s07em') p = HTML('<p>Enter <em>weighed</em> data to get information, through the neural network...</p>') b=Button('addField', self, StyleName='link') b.setID(ADD_FIELD_BUTTON) f = FormPanel() _f = self.fieldPanel([self.getWidgetObj(),0,0]) f.add(_f) """ t = TextArea(StyleName='page-textarea') s=Button('submit', self, StyleName='link') s.setID('submitButton') """ self._htmlElements = [['h', h], ['p', p], ['b', b], ['f', f]] for i in range(len(self._htmlElements)): RootPanel().add(self._htmlElements[i][1]) if addList: self._htmlElements+=addList for i in range(len(self._htmlElements)): RootPanel().add(addList[i][1]) return self._htmlElements
class HiddenDemo(SimplePanel): def __init__(self): SimplePanel.__init__(self) self.form = FormPanel() self.form.setAction("http://google.com/search") self.form.setTarget("results") panel = VerticalPanel() panel.add(Hidden("q", "python pyjamas")) panel.add(Button("Search", getattr(self, "onBtnClick"))) results = NamedFrame("results") panel.add(results) self.form.add(panel) self.add(self.form) def onBtnClick(self, event): self.form.submit()
class MTurkOutput: """ This class encapsulated all that is germane to sending the results to MTurk thus enabling the separating of the logic from the gui """ def __init__(self,sandbox,assignmentId,hitId,workerId): self.mturk_form = FormPanel() # change this to sandbox url once ready for testing self.write_data = write_data if sandbox: self.mturk_form.setAction("https://workersandbox.mturk.com/mturk/externalSubmit") else: self.mturk_form.setAction("http://www.mturk.com/mturk/externalSubmit") self.mturk_form.setMethod(FormPanel.METHOD_POST) self.assignmentId = Hidden("assignmentId") self.hitId = Hidden("hitId") self.workerId = Hidden("workerId") self.assignmentId.setValue(assignmentId) self.hitId.setValue(hitId) self.workerId.setValue(workerId) self.vp = VerticalPanel() self.vp.add(self.assignmentId) self.vp.add(self.hitId) self.vp.add(self.workerId) self.mturk_form.add(self.vp) def add_data(self,data): """ Adds data -- takes as argument a list of pairs """ for k,v in data: tmp = Hidden(k) tmp.setValue(v) self.vp.add(tmp)
class HiddenDemo(SimplePanel): def __init__(self): SimplePanel.__init__(self) self.form = FormPanel() self.form.setAction("http://google.com/search") self.form.setTarget("results") panel = VerticalPanel() panel.add(Hidden("q", "python pyjamas")) panel.add(Button("Search", getattr(self, "onBtnClick"))) results = NamedFrame("results") panel.add(results) self.form.add(panel) self.add(self.form) def onBtnClick(self, event): self.form.submit()
class FileUploadPanel(SimplePanel): def __init__(self): SimplePanel.__init__(self) self.form = FormPanel() self.form.setEncoding(FormPanel.ENCODING_MULTIPART) self.form.setMethod(FormPanel.METHOD_POST) self.url = "http://localhost/pyjamas_upload_demo" self.form.setAction(self.url) self.form.setTarget("results") vPanel = VerticalPanel() hPanel = HorizontalPanel() hPanel.setSpacing(5) hPanel.add(Label("Upload file:")) self.field = FileUpload() self.field.setName("file") hPanel.add(self.field) hPanel.add(Button("Submit", getattr(self, "onBtnClick"))) vPanel.add(hPanel) self.simple = CheckBox("Simple mode? ") #self.simple.setChecked(True) vPanel.add(self.simple) self.progress = Label('0%') results = NamedFrame("results") vPanel.add(results) vPanel.add(self.progress) self.form.add(vPanel) self.add(self.form) def onBtnClick(self, event): self.progress.setText('0%') if self.simple.isChecked(): self.form.submit() else: if AsyncUpload.is_old_browser(): Window.alert("Hmmm, your browser doesn't support this.") else: el = self.field.getElement() files = getattr(el, 'files') #TODO implement loop for multiple file uploads file = JS("@{{files}}[0]") #otherwise pyjs thinks it's a string? AsyncUpload.asyncUpload(self.url, file, self) def onload(self, status): self.progress.setText('100%') def onerror(self, status): Window.alert("oh noes we got an " + str(status)) def onprogress(self, loaded, total): if self.progress.getText() == '100%': return progress = (loaded / total) p = int(progress * 100) self.progress.setText(str(p) + '%')
class FileUploadPanel(SimplePanel): def __init__(self): SimplePanel.__init__(self) self.form = FormPanel() self.form.setEncoding(FormPanel.ENCODING_MULTIPART) self.form.setMethod(FormPanel.METHOD_POST) self.url = "http://localhost/pyjamas_upload_demo" self.form.setAction(self.url) self.form.setTarget("results") vPanel = VerticalPanel() hPanel = HorizontalPanel() hPanel.setSpacing(5) hPanel.add(Label("Upload file:")) self.field = FileUpload() self.field.setName("file") hPanel.add(self.field) hPanel.add(Button("Submit", getattr(self, "onBtnClick"))) vPanel.add(hPanel) self.simple = CheckBox("Simple mode? ") #self.simple.setChecked(True) vPanel.add(self.simple) self.progress = Label('0%') results = NamedFrame("results") vPanel.add(results) vPanel.add(self.progress) self.form.add(vPanel) self.add(self.form) def onBtnClick(self, event): self.progress.setText('0%') if self.simple.isChecked(): self.form.submit() else: if AsyncUpload.is_old_browser(): Window.alert("Hmmm, your browser doesn't support this.") else: el = self.field.getElement() files = getattr(el, 'files') #TODO implement loop for multiple file uploads file = JS( "@{{files}}[0]") #otherwise pyjs thinks it's a string? AsyncUpload.asyncUpload(self.url, file, self) def onload(self, status): self.progress.setText('100%') def onerror(self, status): Window.alert("oh noes we got an " + str(status)) def onprogress(self, loaded, total): if self.progress.getText() == '100%': return progress = (loaded / total) p = int(progress * 100) self.progress.setText(str(p) + '%')