def __init__(self): self.fDialogButton = Button("Show Dialog", self) self.fPopupButton = Button("Show Popup", self) panel = VerticalPanel() panel.add(self.fPopupButton) panel.add(self.fDialogButton) list = ListBox() list.setVisibleItemCount(5) for i in range(10): list.addItem("list item " + i) panel.add(list) panel.setSpacing(8) self.initWidget(panel)
def __init__(self): Sink.__init__(self) self.sStrings = [["foo0", "bar0", "baz0", "toto0", "tintin0"], ["foo1", "bar1", "baz1", "toto1", "tintin1"], ["foo2", "bar2", "baz2", "toto2", "tintin2"], ["foo3", "bar3", "baz3", "toto3", "tintin3"], ["foo4", "bar4", "baz4", "toto4", "tintin4"]] self.combo = ListBox() self.list = ListBox() self.echo = Label() self.combo.setVisibleItemCount(1) self.combo.addChangeListener(self) self.list.setVisibleItemCount(10) self.list.setMultipleSelect(True) for i in range(len(self.sStrings)): self.combo.addItem("List %d" % i) self.combo.setSelectedIndex(0) self.fillList(0) self.list.addChangeListener(self) horz = HorizontalPanel() horz.setVerticalAlignment(HasAlignment.ALIGN_TOP) horz.setSpacing(8) horz.add(self.combo) horz.add(self.list) panel = VerticalPanel() panel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT) panel.add(horz) panel.add(self.echo) self.initWidget(panel) self.echoSelection()
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.methods = [self.METHOD_ECHO, self.METHOD_REVERSE, self.METHOD_UPPERCASE, self.METHOD_LOWERCASE] self.remote_php = EchoServicePHP() self.remote_py = EchoServicePython() self.status=Label() self.text_area = TextArea() self.text_area.setText(r"{'Test'} [\"String\"]") #self.text_area.setCharacterWidth(80) self.text_area.setVisibleLines(8) self.method_list = ListBox() #self.method_list.setMultipleSelect(True) 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 = r"<h2>JSON-RPC Example</h2><p>This example demonstrates the calling of server services with <a href=\"http://json-rpc.org/\">JSON-RPC</a>." info += "<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 __init__(self): self.sStrings=[["foo0", "bar0", "baz0", "toto0", "tintin0"], ["foo1", "bar1", "baz1", "toto1", "tintin1"], ["foo2", "bar2", "baz2", "toto2", "tintin2"], ["foo3", "bar3", "baz3", "toto3", "tintin3"], ["foo4", "bar4", "baz4", "toto4", "tintin4"]] self.combo=ListBox() self.list=ListBox() self.echo=Label() self.combo.setVisibleItemCount(1) self.combo.addChangeListener(self) self.list.setVisibleItemCount(10) self.list.setMultipleSelect(True) for i in range(len(self.sStrings)): self.combo.addItem("List " + i) self.combo.setSelectedIndex(0) self.fillList(0) self.list.addChangeListener(self) horz = HorizontalPanel() horz.setVerticalAlignment(HasAlignment.ALIGN_TOP) horz.setSpacing(8) horz.add(self.combo) horz.add(self.list) panel = VerticalPanel() panel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT) panel.add(horz) panel.add(self.echo) self.setWidget(panel) self.echoSelection()
def __init__(self): self.choicesPopup = PopupPanel(True) self.choices = ListBox() self.items = SimpleAutoCompletionItems() self.popupAdded = False self.visible = False TextBox.__init__(self) self.addKeyboardListener(self) self.choices.addChangeListener(self) self.setStyleName("AutoCompleteTextBox") self.choicesPopup.add(self.choices) self.choicesPopup.addStyleName("AutoCompleteChoices") self.choices.setStyleName("list")
def __init__(self): self.fDialogButton = Button("Show Dialog", self) self.fPopupButton = Button("Show Popup", self) panel = VerticalPanel() panel.add(self.fPopupButton) panel.add(self.fDialogButton) list = ListBox() list.setVisibleItemCount(5) for i in range(10): list.addItem("list item " + i) panel.add(list) panel.setSpacing(8) self.setWidget(panel)
def onModuleLoad(self): # Create a FormPanel and point it at a service. self.form = FormPanel() self.form.setAction("/chat-service/test/") # Because we're going to add a FileUpload widget, we'll need to set the # form to use the POST method, and multipart MIME encoding. self.form.setEncoding(FormPanel.ENCODING_MULTIPART) self.form.setMethod(FormPanel.METHOD_POST) # Create a panel to hold all of the form widgets. panel = VerticalPanel() self.form.setWidget(panel) # Create a TextBox, giving it a name so that it will be submitted. self.tb = TextBox() self.tb.setName("textBoxFormElement") panel.add(self.tb) # Create a ListBox, giving it a name and some values to be associated with # its options. lb = ListBox() lb.setName("listBoxFormElement") lb.addItem("foo", "fooValue") lb.addItem("bar", "barValue") lb.addItem("baz", "bazValue") panel.add(lb) # Create a FileUpload widget. upload = FileUpload() upload.setName("uploadFormElement") panel.add(upload) # Add a 'submit' button. panel.add(Button("Submit", self)) # Add an event handler to the form. self.form.addFormHandler(self) RootPanel().add(self.form)
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.methods = [self.METHOD_ECHO, self.METHOD_REVERSE, self.METHOD_UPPERCASE, self.METHOD_LOWERCASE] self.remote_php = EchoServicePHP() self.remote_py = EchoServicePython() self.status=Label() self.text_area = TextArea() self.text_area.setText(r"{'Test'} [\"String\"]") #self.text_area.setCharacterWidth(80) self.text_area.setVisibleLines(8) self.method_list = ListBox() #self.method_list.setMultipleSelect(True) 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 = r"<h2>JSON-RPC Example</h2><p>This example demonstrates the calling of server services with <a href=\"http://json-rpc.org/\">JSON-RPC</a>." info += "<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() print repr(text) # 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(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) 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)
class Lists(Sink): def __init__(self): Sink.__init__(self) self.sStrings = [["foo0", "bar0", "baz0", "toto0", "tintin0"], ["foo1", "bar1", "baz1", "toto1", "tintin1"], ["foo2", "bar2", "baz2", "toto2", "tintin2"], ["foo3", "bar3", "baz3", "toto3", "tintin3"], ["foo4", "bar4", "baz4", "toto4", "tintin4"]] self.combo = ListBox() self.list = ListBox() self.echo = Label() self.combo.setVisibleItemCount(1) self.combo.addChangeListener(self) self.list.setVisibleItemCount(10) self.list.setMultipleSelect(True) for i in range(len(self.sStrings)): self.combo.addItem("List %d" % i) self.combo.setSelectedIndex(0) self.fillList(0) self.list.addChangeListener(self) horz = HorizontalPanel() horz.setVerticalAlignment(HasAlignment.ALIGN_TOP) horz.setSpacing(8) horz.add(self.combo) horz.add(self.list) panel = VerticalPanel() panel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT) panel.add(horz) panel.add(self.echo) self.initWidget(panel) self.echoSelection() def onChange(self, sender): print sender, self.list, self.combo if sender is self.combo: print "fill list" self.fillList(self.combo.getSelectedIndex()) elif sender is self.list: print "echo " self.echoSelection() else: print "oops" def onShow(self): pass def fillList(self, idx): self.list.clear() strings = self.sStrings[idx] for i in range(len(strings)): self.list.addItem(strings[i]) self.echoSelection() def echoSelection(self): msg = "Selected items: " print msg, self.list.getItemCount() for i in range(self.list.getItemCount()): if self.list.isItemSelected(i): msg += "%d" % i + self.list.getItemText(i) + " " self.echo.setText(msg)
class AutoCompleteTextBox(TextBox): def __init__(self): self.choicesPopup = PopupPanel(True) self.choices = ListBox() self.items = SimpleAutoCompletionItems() self.popupAdded = False self.visible = False TextBox.__init__(self) self.addKeyboardListener(self) self.choices.addChangeListener(self) self.setStyleName("AutoCompleteTextBox") self.choicesPopup.add(self.choices) self.choicesPopup.addStyleName("AutoCompleteChoices") self.choices.setStyleName("list") def setCompletionItems(self, items): if not items.getCompletionItems: items = SimpleAutoCompletionItems(items) self.items = items def getCompletionItems(self): return self.items def onKeyDown(self, arg0, arg1, arg2): pass def onKeyPress(self, arg0, arg1, arg2): pass def onKeyUp(self, arg0, arg1, arg2): if arg1 == KeyboardListener.KEY_DOWN: selectedIndex = self.choices.getSelectedIndex() selectedIndex += 1 if selectedIndex > self.choices.getItemCount(): selectedIndex = 0 self.choices.setSelectedIndex(selectedIndex) return if arg1 == KeyboardListener.KEY_UP: selectedIndex = self.choices.getSelectedIndex() selectedIndex -= 1 if selectedIndex < 0: selectedIndex = self.choices.getItemCount() self.choices.setSelectedIndex(selectedIndex) return if arg1 == KeyboardListener.KEY_ENTER: if self.visible: self.complete() return if arg1 == KeyboardListener.KEY_ESCAPE: self.choices.clear() self.choicesPopup.hide() self.visible = False return text = self.getText() matches = [] if len(text) > 0: matches = self.items.getCompletionItems(text) if len(matches) > 0: self.choices.clear() for i in range(len(matches)): self.choices.addItem(matches[i]) if len(matches) == 1 and matches[0] == text: self.choicesPopup.hide() else: self.choices.setSelectedIndex(0) self.choices.setVisibleItemCount(len(matches) + 1) if not self.popupAdded: RootPanel().add(self.choicesPopup) self.popupAdded = True self.choicesPopup.show() self.visible = True self.choicesPopup.setPopupPosition(self.getAbsoluteLeft(), self.getAbsoluteTop() + self.getOffsetHeight()) self.choices.setWidth(self.getOffsetWidth() + "px") else: self.visible = False self.choicesPopup.hide() def onChange(self, arg0): self.complete() def onClick(self, arg0): self.complete() def complete(self): if self.choices.getItemCount() > 0: self.setText(self.choices.getItemText(self.choices.getSelectedIndex())) self.choices.clear() self.choicesPopup.hide() self.setFocus(True)
def __init__(self): ListBox.__init__(self) self.addCountries()
class Lists(Sink): def __init__(self): self.sStrings=[["foo0", "bar0", "baz0", "toto0", "tintin0"], ["foo1", "bar1", "baz1", "toto1", "tintin1"], ["foo2", "bar2", "baz2", "toto2", "tintin2"], ["foo3", "bar3", "baz3", "toto3", "tintin3"], ["foo4", "bar4", "baz4", "toto4", "tintin4"]] self.combo=ListBox() self.list=ListBox() self.echo=Label() self.combo.setVisibleItemCount(1) self.combo.addChangeListener(self) self.list.setVisibleItemCount(10) self.list.setMultipleSelect(True) for i in range(len(self.sStrings)): self.combo.addItem("List " + i) self.combo.setSelectedIndex(0) self.fillList(0) self.list.addChangeListener(self) horz = HorizontalPanel() horz.setVerticalAlignment(HasAlignment.ALIGN_TOP) horz.setSpacing(8) horz.add(self.combo) horz.add(self.list) panel = VerticalPanel() panel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT) panel.add(horz) panel.add(self.echo) self.setWidget(panel) self.echoSelection() def onChange(self, sender): if sender == self.combo: self.fillList(self.combo.getSelectedIndex()) elif sender == self.list: self.echoSelection() def onShow(self): pass def fillList(self, idx): self.list.clear() strings = self.sStrings[idx] for i in range(len(strings)): self.list.addItem(strings[i]) self.echoSelection() def echoSelection(self): msg = "Selected items: " for i in range(self.list.getItemCount()): if self.list.isItemSelected(i): msg += self.list.getItemText(i) + " " self.echo.setText(msg)