def __init__(self): SimplePanel.__init__(self) field = TextArea() field.setCharacterWidth(20) field.setVisibleLines(4) self.add(field)
class Email(Composite): def __init__(self, **kwargs): element = None if kwargs.has_key('Element'): element = kwargs.pop('Element') panel = VerticalPanel(Element=element) Composite.__init__(self, panel, **kwargs) self.TEXT_WAITING = "Please wait..." self.TEXT_ERROR = "Server Error" self.remote_py = EchoServicePython() self.status = Label() self.subject = TextBox() self.subject.setVisibleLength(60) self.sender = TextBox() self.sender.setVisibleLength(40) self.message = TextArea() self.message.setCharacterWidth(60) self.message.setVisibleLines(15) self.button_py = Button("Send", self) buttons = HorizontalPanel() buttons.add(self.button_py) buttons.setSpacing(8) panel.add(HTML("Subject:")) panel.add(self.subject) panel.add(HTML("From:")) panel.add(self.sender) panel.add( HTML("Your Message - please keep it to under 1,000 characters")) panel.add(self.message) panel.add(buttons) panel.add(self.status) def onClick(self, sender): self.status.setText(self.TEXT_WAITING) text = self.message.getText() msg_sender = self.sender.getText() msg_subject = self.subject.getText() # demonstrate proxy & callMethod() if sender == self.button_py: id = self.remote_py.send(msg_sender, msg_subject, text, self) if id < 0: self.status.setText(self.TEXT_ERROR) def onRemoteResponse(self, response, request_info): self.status.setText(response) def onRemoteError(self, code, message, request_info): self.status.setText("Server Error or Invalid Response: ERROR " + \ str(code) + " - " + str(message))
class Email(Composite): def __init__(self, **kwargs): element = None if kwargs.has_key('Element'): element = kwargs.pop('Element') panel = VerticalPanel(Element=element) Composite.__init__(self, panel, **kwargs) self.TEXT_WAITING = "Please wait..." self.TEXT_ERROR = "Server Error" self.remote_py = EchoServicePython() self.status=Label() self.subject = TextBox() self.subject.setVisibleLength(60) self.sender = TextBox() self.sender.setVisibleLength(40) self.message = TextArea() self.message.setCharacterWidth(60) self.message.setVisibleLines(15) self.button_py = Button("Send", self) buttons = HorizontalPanel() buttons.add(self.button_py) buttons.setSpacing(8) panel.add(HTML("Subject:")) panel.add(self.subject) panel.add(HTML("From:")) panel.add(self.sender) panel.add(HTML("Your Message - please keep it to under 1,000 characters")) panel.add(self.message) panel.add(buttons) panel.add(self.status) def onClick(self, sender): self.status.setText(self.TEXT_WAITING) text = self.message.getText() msg_sender = self.sender.getText() msg_subject = self.subject.getText() # demonstrate proxy & callMethod() if sender == self.button_py: id = self.remote_py.send(msg_sender, msg_subject, text, self) if id<0: self.status.setText(self.TEXT_ERROR) def onRemoteResponse(self, response, request_info): self.status.setText(response) def onRemoteError(self, code, message, request_info): self.status.setText("Server Error or Invalid Response: ERROR " + \ str(code) + " - " + str(message))
def __init__(self): VerticalPanel.__init__(self) self.setSpacing("10px") field = TextArea() field.setCharacterWidth(20) field.setVisibleLines(4) self.add(field) self.add(AutoTextArea(self))
class Editor: def __init__(self, db_url, parent_panel): self.db_url = db_url self.doc_id = None self.parent_panel = parent_panel def loadDocument(self, doc_id): # Load document into editor HTTPRequest().asyncGet(None, None, url=self.db_url+doc_id, handler=DocLoader(self)) def reloadDocument(self): if self.doc_id is None: Window.Alert('Trying to reload blank doc') else: self.loadDocument(self.doc_id) def updateDoc(self, json): doc_obj = JSONParser().decode(json) self.doc_id = doc_obj['_id'] self.id_label.setText('ID : %s'%doc_obj['_id']) self.rev_label.setText('REV: %s'%doc_obj['_rev']) self.save_button.setEnabled(True) self.doc_area.setText(json) self.doc_area.setEnabled(True) self.doc_area.setFocus(True) def saveDocument(self): self.doc_area.setEnabled(False) self.save_button.setEnabled(False) HTTPRequest().asyncPut(None, None, url=self.db_url+self.doc_id, postData=self.doc_area.getText(), handler=DocSaver(self)) def onModuleLoad(self): # Editor self.editor_panel = VerticalPanel() self.id_label = Label('ID: ') self.editor_panel.add(self.id_label) self.rev_label = Label('REV: ') self.editor_panel.add(self.rev_label) self.doc_area = TextArea() self.doc_area.setCharacterWidth(80) self.doc_area.setVisibleLines(24) self.doc_area.setEnabled(False) self.editor_panel.add(self.doc_area) self.parent_panel.add(self.editor_panel) # Buttons self.button_panel = HorizontalPanel() self.save_button = Button("Save", self.saveDocument) self.save_button.setEnabled(False) self.button_panel.add(self.save_button) self.parent_panel.add(self.button_panel)
class CookieExample: COOKIE_NAME = "myCookie" def onModuleLoad(self): try: setCookie(COOKIE_NAME, "setme", 100000) except: pass self.status = Label() self.text_area = TextArea() self.text_area.setText(r"Me eat cookie!") self.text_area.setCharacterWidth(80) self.text_area.setVisibleLines(8) self.button_py_set = Button("Set Cookie", self) self.button_py_read = Button("Read Cookie ", self) buttons = HorizontalPanel() buttons.add(self.button_py_set) buttons.add(self.button_py_read) buttons.setSpacing(8) info = r"This demonstrates setting and reading information using cookies." panel = VerticalPanel() panel.add(HTML(info)) panel.add(self.text_area) panel.add(buttons) panel.add(self.status) RootPanel().add(panel) def onClick(self, sender): """ Run when any button is clicked """ if sender.getText() == "Set Cookie": # clicked the set cookie button text = self.text_area.getText() # print goes to console.log print "setting cookie to:", text # Note: this sets the cookie on the top level setCookie(COOKIE_NAME, text, 10000, path="/") else: cookie_text = getCookie(COOKIE_NAME) if cookie_text is None: print "No Cookie" else: print "myCookie", cookie_text self.status.setText(cookie_text)
class CookieExample: COOKIE_NAME = "myCookie" def onModuleLoad(self): try: setCookie(COOKIE_NAME, "setme", 100000) except: pass self.status = Label() self.text_area = TextArea() self.text_area.setText(r"Me eat cookie!") self.text_area.setCharacterWidth(80) self.text_area.setVisibleLines(8) self.button_py_set = Button("Set Cookie", self) self.button_py_read = Button("Read Cookie ", self) buttons = HorizontalPanel() buttons.add(self.button_py_set) buttons.add(self.button_py_read) buttons.setSpacing(8) info = r'This demonstrates setting and reading information using cookies.' panel = VerticalPanel() panel.add(HTML(info)) panel.add(self.text_area) panel.add(buttons) panel.add(self.status) RootPanel().add(panel) def onClick(self, sender): """ Run when any button is clicked """ if sender.getText() == "Set Cookie": #clicked the set cookie button text = self.text_area.getText() #print goes to console.log print "setting cookie to:", text #Note: this sets the cookie on the top level setCookie(COOKIE_NAME, text, 10000, path='/') else: cookie_text = getCookie(COOKIE_NAME) if cookie_text is None: print "No Cookie" else: print "myCookie", cookie_text self.status.setText(cookie_text)
class JSONRPCExample: def onModuleLoad(self): self.TEXT_WAITING = "Waiting for response..." self.TEXT_ERROR = "Server Error" self.METHOD_ECHO = "Echo" self.METHOD_REVERSE = "Reverse" self.METHOD_UPPERCASE = "UPPERCASE" self.METHOD_LOWERCASE = "lowercase" self.METHOD_NONEXISTANT = "Non existant" self.methods = [ self.METHOD_ECHO, self.METHOD_REVERSE, self.METHOD_UPPERCASE, self.METHOD_LOWERCASE, self.METHOD_NONEXISTANT ] self.remote_php = EchoServicePHP() self.remote_py = EchoServicePython() self.status = Label() self.text_area = TextArea() self.text_area.setText("""{'Test'} [\"String\"] \tTest Tab Test Newline\n after newline """ + r"""Literal String: {'Test'} [\"String\"] """) self.text_area.setCharacterWidth(80) self.text_area.setVisibleLines(8) self.method_list = ListBox() self.method_list.setName("hello") self.method_list.setVisibleItemCount(1) for method in self.methods: self.method_list.addItem(method) self.method_list.setSelectedIndex(0) method_panel = HorizontalPanel() method_panel.add(HTML("Remote string method to call: ")) method_panel.add(self.method_list) method_panel.setSpacing(8) self.button_php = Button("Send to PHP Service", self) self.button_py = Button("Send to Python Service", self) buttons = HorizontalPanel() buttons.add(self.button_php) buttons.add(self.button_py) buttons.setSpacing(8) info = """<h2>JSON-RPC Example</h2> <p>This example demonstrates the calling of server services with <a href="http://json-rpc.org/">JSON-RPC</a>. </p> <p>Enter some text below, and press a button to send the text to an Echo service on your server. An echo service simply sends the exact same text back that it receives. </p>""" panel = VerticalPanel() panel.add(HTML(info)) panel.add(self.text_area) panel.add(method_panel) panel.add(buttons) panel.add(self.status) RootPanel().add(panel) def onClick(self, sender): self.status.setText(self.TEXT_WAITING) method = self.methods[self.method_list.getSelectedIndex()] text = self.text_area.getText() # demonstrate proxy & callMethod() if sender == self.button_php: if method == self.METHOD_ECHO: id = self.remote_php.echo(text, self) elif method == self.METHOD_REVERSE: id = self.remote_php.callMethod("reverse", [text], self) elif method == self.METHOD_UPPERCASE: id = self.remote_php.uppercase(text, self) elif method == self.METHOD_LOWERCASE: id = self.remote_php.lowercase(self, msg=text) elif method == self.METHOD_NONEXISTANT: id = self.remote_php.nonexistant(text, self) else: if method == self.METHOD_ECHO: id = self.remote_py.echo(text, self) elif method == self.METHOD_REVERSE: id = self.remote_py.reverse(text, self) elif method == self.METHOD_UPPERCASE: id = self.remote_py.uppercase(text, self) elif method == self.METHOD_LOWERCASE: id = self.remote_py.lowercase(text, self) elif method == self.METHOD_NONEXISTANT: id = self.remote_py.nonexistant(text, self) def onRemoteResponse(self, response, request_info): self.status.setText(response) def onRemoteError(self, code, errobj, request_info): # onRemoteError gets the HTTP error code or 0 and # errobj is an jsonrpc 2.0 error dict: # { # 'code': jsonrpc-error-code (integer) , # 'message': jsonrpc-error-message (string) , # 'data' : extra-error-data # } message = errobj['message'] if code != 0: self.status.setText("HTTP error %d: %s" % (code, message)) else: code = errobj['code'] self.status.setText("JSONRPC Error %s: %s" % (code, message))
class JSONRPCExample: def onModuleLoad(self): self.TEXT_WAITING = "Waiting for response..." self.TEXT_ERROR = "Server Error" self.METHOD_ECHO = "Echo" self.METHOD_REVERSE = "Reverse" self.METHOD_UPPERCASE = "UPPERCASE" self.METHOD_LOWERCASE = "lowercase" self.METHOD_NONEXISTANT = "Non existant" self.methods = [self.METHOD_ECHO, self.METHOD_REVERSE, self.METHOD_UPPERCASE, self.METHOD_LOWERCASE, self.METHOD_NONEXISTANT] self.remote_php = EchoServicePHP() self.remote_py = EchoServicePython() self.status=Label() self.text_area = TextArea() self.text_area.setText("""{'Test'} [\"String\"] \tTest Tab Test Newline\n after newline """ + r"""Literal String: {'Test'} [\"String\"] """) self.text_area.setCharacterWidth(80) self.text_area.setVisibleLines(8) self.method_list = ListBox() self.method_list.setName("hello") self.method_list.setVisibleItemCount(1) for method in self.methods: self.method_list.addItem(method) self.method_list.setSelectedIndex(0) method_panel = HorizontalPanel() method_panel.add(HTML("Remote string method to call: ")) method_panel.add(self.method_list) method_panel.setSpacing(8) self.button_php = Button("Send to PHP Service", self) self.button_py = Button("Send to Python Service", self) buttons = HorizontalPanel() buttons.add(self.button_php) buttons.add(self.button_py) buttons.setSpacing(8) info = """<h2>JSON-RPC Example</h2> <p>This example demonstrates the calling of server services with <a href="http://json-rpc.org/">JSON-RPC</a>. </p> <p>Enter some text below, and press a button to send the text to an Echo service on your server. An echo service simply sends the exact same text back that it receives. </p>""" panel = VerticalPanel() panel.add(HTML(info)) panel.add(self.text_area) panel.add(method_panel) panel.add(buttons) panel.add(self.status) RootPanel().add(panel) def onClick(self, sender): self.status.setText(self.TEXT_WAITING) method = self.methods[self.method_list.getSelectedIndex()] text = self.text_area.getText() # demonstrate proxy & callMethod() if sender == self.button_php: if method == self.METHOD_ECHO: id = self.remote_php.echo(text, self) elif method == self.METHOD_REVERSE: id = self.remote_php.callMethod("reverse", [text], self) elif method == self.METHOD_UPPERCASE: id = self.remote_php.uppercase(text, self) elif method == self.METHOD_LOWERCASE: id = self.remote_php.lowercase(self, msg=text) elif method == self.METHOD_NONEXISTANT: id = self.remote_php.nonexistant(text, self) else: if method == self.METHOD_ECHO: id = self.remote_py.echo(text, self) elif method == self.METHOD_REVERSE: id = self.remote_py.reverse(text, self) elif method == self.METHOD_UPPERCASE: id = self.remote_py.uppercase(text, self) elif method == self.METHOD_LOWERCASE: id = self.remote_py.lowercase(text, self) elif method == self.METHOD_NONEXISTANT: id = self.remote_py.nonexistant(text, self) def onRemoteResponse(self, response, request_info): self.status.setText(response) def onRemoteError(self, code, errobj, request_info): # onRemoteError gets the HTTP error code or 0 and # errobj is an jsonrpc 2.0 error dict: # { # 'code': jsonrpc-error-code (integer) , # 'message': jsonrpc-error-message (string) , # 'data' : extra-error-data # } message = errobj['message'] if code != 0: self.status.setText("HTTP error %d: %s" % (code, message)) else: code = errobj['code'] self.status.setText("JSONRPC Error %s: %s" % (code, message))
def onRemoteResponse(self, response, request_info): mname = request_info.method if mname == "customize_message": showCustomizationResult(self, response, request_info) return if mname == "get_messagesdata_for_cust": locations_data = response["locations"] selectionbox = VerticalPanel(Padding=3) locations = ListBox() for (loc_name, loc_id) in locations_data: locations.addItem(loc_id, loc_name) messages = ListBox() messages.setName("locations") messages.addItem(location_select_label) for (name, d) in response["messages"].items(): messages.addItem(d['label'], name) locations.addChangeListener(self) messages.addChangeListener(self) self.locations = locations self.messages = messages locationbox = HorizontalPanel() locationbox.add(Label("Location: ", StyleName="text", Width=80)) locationbox.add(locations) msgnamebox = HorizontalPanel() msgnamebox.add(Label("Message: ", StyleName="text", Width=80)) msgnamebox.add(messages) selectionbox.add(locationbox) selectionbox.add(msgnamebox) mainpanel = VerticalPanel(StyleName="dataBoxContent") mainpanel.add(selectionbox) self.mainpanel = mainpanel root = RootPanel() root.add(mainpanel) if mname == "get_messagecustdata": self.messages_data = response buttonspanel = FlowPanel(Spacing=1, Padding=1, Width=600) #buttonspanel.add(Label("Macros:", StyleName="text")) for macro_d in self.messages_data['macros']: macrobutton = Button(macro_d['label'], self, StyleName="buttonlikelink")#"nicebutton small") macrobutton.name = macro_d['name'] buttonspanel.add(macrobutton) msgpanel = VerticalPanel(Padding=1, Spacing=1) messagebox = TextArea() messagebox.setCharacterWidth(70) height = len(self.messages_data["text"].split('\n')) + 1 messagebox.setVisibleLines(height) messagebox.setText(self.messages_data["text"]) messagebox.setName("textBoxFormElement") self.messagebox = messagebox msgpanel.add(messagebox) self.statusbar = Label(StyleName="errorMessage") msgpanel.add(self.statusbar) actionbuttons = HorizontalPanel(Spacing=2) updatebutton = Button("Update", self, StyleName="nicebutton small yellow") updatebutton.name = "update" actionbuttons.add(updatebutton) #actionbuttons.add(Button("Send me a preview mail")) msgpanel.add(actionbuttons) editorbox = VerticalPanel(Padding=1) editorbox.add(buttonspanel) editorbox.add(msgpanel) editorpanel = CaptionPanel("Message editor", editorbox, Padding=1, StyleName="text") editorpanel.name = "editorpanel" self.editorpanel = editorpanel self.mainpanel.add(editorpanel)
def __init__(self, name, help): widget = TextArea() widget.setCharacterWidth(72) widget.setStyleName('form-control') widget.setVisibleLines(5) Form_Row.__init__(self, name, widget, help=help)
class AccessionRawSQL(Composite): def __init__(self): self.TEXT_WAITING = "Waiting for response..." self.TEXT_ERROR = "Server Error" self.METHOD_ECHO = "Echo" self.METHOD_REVERSE = "Reverse" self.METHOD_UPPERCASE = "UPPERCASE" self.METHOD_LOWERCASE = "lowercase" self.methods = [self.METHOD_ECHO, self.METHOD_REVERSE, self.METHOD_UPPERCASE, self.METHOD_LOWERCASE] self.remote_py = EchoServicePython() self.status=Label() self.text_area = TextArea() self.text_area.setText("""{'Test'} [\"String\"] \tTest Tab Test Newline\n after newline """ + r"""Literal String: {'Test'} [\"String\"] """) self.text_area.setCharacterWidth(80) self.text_area.setVisibleLines(8) self.method_list = ListBox() self.method_list.setName("hello") self.method_list.setVisibleItemCount(1) for method in self.methods: self.method_list.addItem(method) self.method_list.setSelectedIndex(0) method_panel = HorizontalPanel() method_panel.add(HTML("Remote string method to call: ")) method_panel.add(self.method_list) method_panel.setSpacing(8) self.button_py = Button("Send to Python Service", self) buttons = HorizontalPanel() buttons.add(self.button_py) buttons.setSpacing(8) info = """<h2>JSON-RPC Example</h2> <p>This example demonstrates the calling of server services with <a href="http://json-rpc.org/">JSON-RPC</a>. </p> <p>Enter some text below, and press a button to send the text to an Echo service on your server. An echo service simply sends the exact same text back that it receives. </p>""" panel = VerticalPanel() panel.add(HTML(info)) panel.add(self.text_area) panel.add(method_panel) panel.add(buttons) panel.add(self.status) self.setWidget(panel) def onClick(self, sender): self.status.setText(self.TEXT_WAITING) method = self.methods[self.method_list.getSelectedIndex()] text = self.text_area.getText() # demonstrate proxy & callMethod() if sender == self.button_py: if method == self.METHOD_ECHO: id = self.remote_py.echo(text, self) elif method == self.METHOD_REVERSE: id = self.remote_py.reverse(text, self) elif method == self.METHOD_UPPERCASE: id = self.remote_py.uppercase(text, self) elif method == self.METHOD_LOWERCASE: id = self.remote_py.lowercase(text, self) if id<0: self.status.setText(self.TEXT_ERROR) def onRemoteResponse(self, response, request_info): self.status.setText(response) def onRemoteError(self, code, message, request_info): self.status.setText("Server Error or Invalid Response: ERROR " + code + " - " + message)