def onRemoteResponse(self, response, request_info): self.table = FlexTable() self.table.setText(0,0, "Problem"); self.table.setText(0,1, response['problem']); self.table.setText(1,0, "Code"); self.table.setText(1,1, self.trcode(response['code'])+ " ("+response['code']+")"); self.table.setText(2,0, "Message"); x = TextArea() x.setText(response['message']) x.setWidth(600); x.setHeight(300); pyjamas.DOM.setAttribute(x.getElement(), 'readOnly', 'readonly') pyjamas.DOM.setAttribute(x.getElement(), 'readonly', 'readonly') self.table.setWidget(2,1,x ); self.table.setText(3,0, "Source"); x = TextArea() x.setText(response['source']) x.setWidth(600); x.setHeight(300); pyjamas.DOM.setAttribute(x.getElement(), 'readOnly', 'readonly') pyjamas.DOM.setAttribute(x.getElement(), 'readonly', 'readonly') self.table.setWidget(3,1, x); self.add("Submission "+response['id'])
resdict = resgen_core.processconf(inputArea.getText()) hData = resgen_core.processhorz(resdict, hTemplate, footdict) outputArea.setText(hData) if __name__ == '__main__': b = Button("Convert", convert) p = HorizontalPanel() p.add(inputArea) p.add(outputArea) q = VerticalPanel() q.setStyleName("panel") q.add(b) q.add(p) q.setHeight("100%") q.setWidth("100%") p.setHeight("80%") p.setWidth("100%") inputArea.setHeight("100%") inputArea.setWidth("100%") outputArea.setHeight("100%") outputArea.setWidth("100%") inputArea.setText(confDefault) RootPanel().add(q)
class SongFrequency: def __init__(self): self.artist ='' self.start_date = '' self.end_date = '' self.period_search ='' self.search_option = 1 #declare the general interface widgets self.panel = DockPanel(StyleName = 'background') self.ret_area = TextArea() self.ret_area.setWidth("350px") self.ret_area.setHeight("90px") self.options = ListBox() self.search_button = Button("Search", getattr(self, "get_result"), StyleName = 'button') #set up the date search panel; it has different text boxes for #to and from search dates self.date_search_panel = VerticalPanel() self.date_search_start = TextBox() self.date_search_start.addInputListener(self) self.date_search_end = TextBox() self.date_search_end.addInputListener(self) self.date_search_panel.add(HTML("Enter as month/day/year", True, StyleName = 'text')) self.date_search_panel.add(HTML("From:", True, StyleName = 'text')) self.date_search_panel.add(self.date_search_start) self.date_search_panel.add(HTML("To:", True, StyleName = 'text')) self.date_search_panel.add(self.date_search_end) #set up the artist search panel self.artist_search = TextBox() self.artist_search.addInputListener(self) self.artist_search_panel = VerticalPanel() self.artist_search_panel.add(HTML("Enter artist's name:",True, StyleName = 'text')) self.artist_search_panel.add(self.artist_search) #Put together the list timespan search options self.period_search_panel = VerticalPanel() self.period_search_panel.add(HTML("Select a seach period:",True, StyleName = 'text')) self.period_search = ListBox() self.period_search.setVisibleItemCount(1) self.period_search.addItem("last week") self.period_search.addItem("last month") self.period_search.addItem("last year") self.period_search.addItem("all time") self.period_search_panel.add(self.period_search) #add the listeners to the appropriate widgets self.options.addChangeListener(self) self.period_search.addChangeListener(self) self.ret_area_scroll = ScrollPanel() self.search_panel = HorizontalPanel() self.options_panel = VerticalPanel() # A change listener for the boxes def onChange(self, sender): #switch the list box options if sender == self.options: self.search_panel.remove(self.period_search_panel) self.search_panel.remove(self.date_search_panel) self.search_panel.remove(self.artist_search_panel) index = self.options.getSelectedIndex() if index == 0: self.search_panel.add(self.artist_search_panel) self.search_option = 1 elif index == 1: self.search_panel.add(self.date_search_panel) self.search_option = 2 elif index == 2: self.search_panel.add(self.period_search_panel) self.search_option = 3 elif sender == self.period_search: index = self.period_search.getSelectedIndex() if index == 0: self.period_search = "last week" elif index == 1: self.period_search = "last month" elif index == 2: self.period_search = "last year" elif index == 3: self.period_search = "all time" #A listener for the text boxes def onInput(self, sender): if sender == self.artist_search: self.artist = sender.getText() elif sender == self.date_search_end: self.end_date = sender.getText() elif sender == self.date_search_start: self.start_date = sender.getText() #A listener for the buttons that, when the button is clicked, looks up the results and outputs them def get_result(self): return_str = " " if self.search_option == 1: return_str = self.artist elif self.search_option == 2: return_str = self.start_date elif self.search_option ==3: return_str = self.period_search else: return_str = "Find the most played artist, album, or song for a time period, or the number of songs played by a certain artist" self.ret_area.setText(return_str) def onModuleLoad(self): #Put together the list of options self.options.addItem("Artist") self.options.addItem("Date") self.options.addItem("Time Span") self.options.setVisibleItemCount(3) #put the text area together self.ret_area_scroll.add(self.ret_area) self.ret_area.setText("Find the most played artist, album, or song for a time period, or the number of songs played by a certain artist") #put the search items together self.search_panel.add(self.artist_search_panel) #Put together the options panel self.options_panel.add(HTML("Search By:", True, StyleName = 'text')) self.options_panel.add(self.options) #Add everything to the main panel self.panel.add(HTML("WQHS Song Search",True, StyleName = 'header'), DockPanel.NORTH) self.panel.add(self.options_panel, DockPanel.WEST) self.panel.add(self.ret_area_scroll, DockPanel.SOUTH) self.panel.setCellHeight(self.ret_area_scroll, "100px") self.panel.setCellWidth(self.ret_area_scroll, "300px") self.panel.add(self.search_button, DockPanel.EAST) self.panel.add(self.search_panel, DockPanel.CENTER) #Associate panel with the HTML host page RootPanel().add(self.panel)
class SubmitTab: def __init__(self,app): self.app=app self.form = FormPanel() self.form.setEncoding("multipart/form-data") self.form.setMethod("post") self.msg = HTML("<b>Uploading</b>") self.table = FlexTable() self.table.setText(0,0, "Problem") self.table.setText(1,0, "Language") self.table.setText(2,0, "Program File") self.table.setText(3,0, "Program source") self.problem = ListBox() self.problem.insertItem("Detect",-1,-1) self.problem.setName("problem") self.table.setWidget(0,1,self.problem) self.lang = ListBox() self.lang.insertItem("Detect","",-1) self.lang.insertItem("C/C++","cc",-1) self.lang.insertItem("Java","Java",-1) self.lang.insertItem("Python","Python",-1) self.lang.setName("lang") self.table.setWidget(1,1,self.lang) self.cookie = Hidden() self.cookie.setName("cookie") self.table.setWidget(5,0,self.cookie) self.file = FileUpload() self.file.setName("file"); self.table.setWidget(2,1,self.file) self.source = TextArea() self.source.setName("source") self.source.setWidth("600"); self.source.setHeight("400"); self.source.setText("""//$$problem: 1$$ //$$language: cc$$ #include <unistd.h> #include <stdio.h> int main() { int a,b; scanf("%d %d",&a,&b); printf("%d\\n",a+b); return 0; }""") self.source.addChangeListener(self.onChange) self.table.setWidget(3,1,self.source) self.button = Button("Submit",self) self.table.setWidget(4,1, self.button) self.table.setWidget(5,1, self.msg) self.msg.setVisible(False) self.form.setWidget(self.table) self.form.setAction("../upload.py/submit") self.form.addFormHandler(self) def onChange(self, src): if self.source.getText(): self.file = FileUpload() self.file.setName("file"); self.table.setWidget(2,1,self.file) def onSubmitComplete(self,event): self.msg.setVisible(False) def onSubmit(self,evt): self.msg.setVisible(True) def onClick(self,evt): if self.app.cookie == None: self.app.login() else: self.cookie.setValue(self.app.cookie) self.form.submit() def getRoot(self): return self.form