def __init__(self, *a, **kw): self.outer = VerticalPanel() self.loader = Image(u"/loader.gif") self.eventInfo = None self.nameText = TextBox() self.categoryListBox = ListBox(False) self.subCategoriesListBox = ListBox(False) self.hostText = TextBox() self.locationText = TextBox() self.cityText = TextBox() self.createEventButton = Button(u"Create Event") self.apiClient = ApiFactory.getInstance()
def onSuccess(self, result): self.outer.remove(self.loader) dropBox = ListBox(False) for e in result: GWT.log(u"adding " + java.str(e.getName()), None) dropBox.addItem(e.getName(), e.getEidString()) self.outer.add(dropBox) self.outer.add(self.selectButton) class _anonymous(ClickHandler): @java.typed(ClickEvent) def onClick(self, event): self.selectHandler.onSelect(Long(dropBox.getValue(dropBox.getSelectedIndex()))) self.selectButton.addClickHandler(_anonymous())
def __init__(self): Sink.__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 %d" % i) panel.add(list) panel.setSpacing(8) self.initWidget(panel)
def onSuccess(self, result): self.outer.remove(self.loader) dropBox = ListBox(False) dropBox.getElement().setId(u"dropBox") for user in result: dropBox.addItem(user.getName(), user.getUidString()) self.outer.clear() self.outer.add(HTML(u"Choose Friend")) self.outer.add(dropBox) b = Button(u"Go") self.outer.add(b) class _anonymous(ClickHandler): @java.typed(ClickEvent) def onClick(self, event): self.friendSelection.onSelected(Long(dropBox.getValue(dropBox.getSelectedIndex()))) b.addClickHandler(_anonymous())
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." 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 body(self, frame): """ Creates the dialog body. Returns the widget that should have initial focus. """ title = Label( text = "Choose Font" ) frame.add( title ) # Font family list ---------------------------------------------------- family = ListBox() family.setMultipleSelect( False ) family.setStyleName( "color", "#ffffff" ) for family_name in families(master): family.addItem( item = family_name ) # Font size spinner --------------------------------------------------- size = TextBox() frame.add( size ) # Example text -------------------------------------------------------- example = TextArea() example.addText( "This is example text.\n" ) example.addText( "If you like this text, it can be your font." ) def on_select( event ): idx = familt.getSelectedIndex() example.setStyleName( "font", family.getValue(idx) ) example.setStyleName( "em", size.getText() ) family.addChangeListener( on_select ) return size # Given initial focus.
def __init__(self, ): self.__init__._super() self.outer = VerticalPanel() self.response = SimplePanel() inputWrapper = HorizontalPanel() inputWrapper.setSpacing(10) self.inputText = TextBox() self.createButton = Button(u"Create Album") self.visiList = ListBox(False) self.visiList.addItem(u"friends") self.visiList.addItem(u"friends_of_friends") self.visiList.addItem(u"networks") self.visiList.addItem(u"everyone") inputWrapper.add(self.inputText) inputWrapper.add(HTML(u" Visible ")) inputWrapper.add(self.visiList) inputWrapper.add(self.createButton) self.createButton.addClickHandler(self.CreateAlbumClickHandler()) self.outer.add(inputWrapper) self.outer.add(self.response) self.initWidget(self.outer) # outer.add ( createUploadPhotoUI () );
def onModuleLoad(self): # Create a FormPanel and point it at a service. self.form = FormPanel() self.form.setAction("http://127.0.0.1/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().get().add(self.form)
def __init__(self, *a, **kw): self.eventIcon = Image(u"/cal_icon.gif") self.outer = VerticalPanel() self.responsePanel = VerticalPanel() self.listBox = ListBox(False)
class Events_get(Showcase): """ Showcase for method <code>events.get</code> """ @java.init def __init__(self, *a, **kw): self.eventIcon = Image(u"/cal_icon.gif") self.outer = VerticalPanel() self.responsePanel = VerticalPanel() self.listBox = ListBox(False) # Get members @java.private @java.innerclass @java.implements(ClickHandler) class GetMembersClickHandler(Object): @java.init def __init__(self, *a, **kw): self.eid = None self.addToPanel = None @__init__.register @java.typed(Long, Panel) def __init__(self, eid, addToPanel): self.eid = eid self.addToPanel = addToPanel @java.typed(ClickEvent) def onClick(self, event): members = Events_getMembers(self.eid) self.addToPanel.clear() self.addToPanel.add(members) @java.private @java.innerclass @java.implements(ChangeHandler) class FilterHandler(Object): """ Let user filter events """ @java.init def __init__(self, *a, **kw): pass @java.typed(ChangeEvent) def onChange(self, event): idx = self.listBox.getSelectedIndex() value = self.listBox.getValue(idx) if u"All".equals(value): self.doEventsGet(None) else: self.doEventsGet(RsvpStatus.valueOf(value)) @java.private @java.innerclass @java.implements(AsyncCallbackList) class EventsGetCallback(Object): """ Handle events get """ @java.init def __init__(self, *a, **kw): pass @java.typed(Throwable) def onFailure(self, caught): self.handleFailure(caught) @java.typed(List) def onSuccess(self, result): GWT.log(u"Events get #" + java.str(result.size()), None) self.handleResponse(result) # removeLoader ( outer ); @__init__.register @java.typed() def __init__(self, ): self.__init__._super() """ Create new showcase """ self.outer.getElement().setId(u"Events_get") self.outer.addStyleName(u"gwittit-Events_get") self.outer.add(self.createEventFilter()) self.outer.add(self.responsePanel) self.doEventsGet(None) self.listBox.addChangeHandler(self.FilterHandler()) self.initWidget(self.outer) # Create ui for dropdown filter @java.private def createEventFilter(self): filter = HorizontalPanel() self.listBox.addItem(u"All") for rs in RsvpStatus.values(): self.listBox.addItem(java.str(rs)) filter.setSpacing(10) filter.add(HTML(u"Filter By: ")) filter.add(self.listBox) return filter # Handle response from call @java.private @java.typed(List) def handleResponse(self, events): self.removeLoader(self.responsePanel) header = HTML(java.str(u"<h3><img src=/cal_icon.gif> You have " + java.str(events.size())) + u" event invitations </h3><p/>") self.responsePanel.add(header) for eventInfo in events: self.responsePanel.add(self.createEventInfoUi(eventInfo)) Xfbml.parse(self.responsePanel) # Create somekind of ui. @java.private @java.typed(EventInfo) def createEventInfoUi(self, eventInfo): p = VerticalPanel() p.addStyleName(u"eventInfo") html = java.str(u"<h4>" + java.str(eventInfo.getName())) + u"</h4>" html += java.str(java.str(u"When: " + java.str(eventInfo.getStartTime())) + u", Where: " + eventInfo.getLocation()) + u"<br/>" self.responsePanel.add(HTML(html)) mPanel = SimplePanel() mLink = Anchor(u"See who's attending") mLink.addClickHandler(self.GetMembersClickHandler(eventInfo.getEid(), mPanel)) p.add(mLink) p.add(mPanel) return p # Render events based on rsvpstatus @java.private @java.typed(RsvpStatus) def doEventsGet(self, status): self.responsePanel.clear() self.addLoader(self.responsePanel) GWT.log(u"display events", None) eventFilter = EventInfo.createEventInfo(None, None, None, None, status) # Create a filter used in the query self.apiClient.eventsGet(eventFilter, self.EventsGetCallback())
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 "onChange", 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 EventEditor(Composite): """ Let user create a new Event. CSS Configuration <ul> <li>.gwittit-EventEditor </ul> """ @java.init def __init__(self, *a, **kw): self.outer = VerticalPanel() self.loader = Image(u"/loader.gif") self.eventInfo = None self.nameText = TextBox() self.categoryListBox = ListBox(False) self.subCategoriesListBox = ListBox(False) self.hostText = TextBox() self.locationText = TextBox() self.cityText = TextBox() self.createEventButton = Button(u"Create Event") self.apiClient = ApiFactory.getInstance() @__init__.register @java.typed() def __init__(self, ): self.__init__._super() self.outer.addStyleName(u"gwittit-EventEditor") self.outer.setSpacing(10) self.initFields() self.outer.add(self.createLabelAndInput(u"Name", self.nameText)) self.outer.add(self.createLabelAndInput(u"Category", self.categoryListBox)) self.outer.add(self.createLabelAndInput(u"SubCategory", self.subCategoriesListBox)) self.outer.add(self.createLabelAndInput(u"Host", self.hostText)) # outer.add ( createLabelAndInput ( "EventEnds" , endTimePicker ) ); self.outer.add(self.createLabelAndInput(u"Location", self.locationText)) self.outer.add(self.createLabelAndInput(u"City", self.cityText)) self.outer.add(self.createEventButton) class _anonymous(ClickHandler): @java.typed(ClickEvent) def onClick(self, event): self.saveOrUpdate() self.createEventButton.addClickHandler(_anonymous()) self.initWidget(self.outer) @java.private def saveOrUpdate(self): """ Save event to facebook """ jEvent = Json() jEvent.put(u"name", self.nameText.getValue()) jEvent.put(u"host", self.hostText.getValue()) jEvent.put(u"location", self.locationText.getValue()) jEvent.put(u"city", self.cityText.getValue()) selectedCategory = Integer(self.categoryListBox.getValue(self.categoryListBox.getSelectedIndex())) # Save Category selectedSubCategory = Integer(self.subCategoriesListBox.getValue(self.subCategoriesListBox.getSelectedIndex())) jEvent.put(u"category", EventInfo.Category.values()[(selectedCategory - 1)].toString()) jEvent.put(u"subcategory", EventInfo.SubCategory.values()[(selectedSubCategory - 1)].toString()) jEvent.put(u"start_time", Date().getTime() + Long(u"9999999999")) jEvent.put(u"end_time", Date().getTime() + Long(u"9999999999999")) eventInfo = EventInfo.fromJson(java.str(jEvent)) self.outer.add(self.loader) class _anonymous(AsyncCallback): @java.typed(Throwable) def onFailure(self, caught): self.outer.remove(self.loader) errorResponse = ErrorResponseUI(caught) errorResponse.center() errorResponse.show() @java.typed(JavaScriptObject) def onSuccess(self, result): self.outer.remove(self.loader) self.outer.add(HTML(u"Created event with ID " + java.str(result))) self.apiClient.eventsCreate(eventInfo, _anonymous()) # Create the event. @java.private def initFields(self): """ Create widgets, and set default values if any """ self.nameText.setValue(u"Birthday") self.hostText.setValue(u"host") self.locationText.setValue(u"location") self.cityText.setValue(u"Palo Alto, CA") for category in EventInfo.Category.values(): self.categoryListBox.addItem(java.str(category).replace(u"_", u" "), u"" + java.str(category.getId())) for subCategory in EventInfo.SubCategory.values(): self.subCategoriesListBox.addItem(java.str(subCategory).replace(u"_", u" "), u"" + java.str(subCategory.getId())) @java.private @java.typed(String, Widget) def createLabelAndInput(self, label, field): h = HorizontalPanel() l = HTML(java.str(u"<b>" + java.str(label)) + u": </b>") l.setWidth(u"150px") h.add(l) h.add(field) return h
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." 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, event): 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 " + str(code) + " - " + str(message))
class Photos_createAlbum(Showcase): """ Showcase for method call <code>photos.createAlbum</code> @author olamar72 """ @java.init def __init__(self, *a, **kw): self.sampleUpload = Image(u"/sample") self.outer = None self.inputText = None self.createButton = None self.visiList = None self.response = None # User clicks create album @java.private @java.innerclass @java.implements(ClickHandler) class CreateAlbumClickHandler(Object): @java.init def __init__(self, *a, **kw): pass @java.typed(ClickEvent) def onClick(self, event): self.createAlbum(self.inputText.getValue(), self.visiList.getItemText(self.visiList.getSelectedIndex())) # Create album callback @java.private @java.innerclass @java.implements(AsyncCallbackAlbum) class CreateAlbumCallback(Object): @java.init def __init__(self, *a, **kw): pass @java.typed(Throwable) def onFailure(self, caught): self.handleFailure(caught) @java.typed(Album) def onSuccess(self, album): self.response.setWidget(HTML(u"Album created with id " + java.str(album.getAid()))) @java.private @java.innerclass @java.implements(ClickHandler) class UploadPhotoClickHandler(Object): """ Upload photo """ @java.init def __init__(self, *a, **kw): pass @java.typed(ClickEvent) def onClick(self, event): self.apiClient.photosUpload(None, u"Testing", self.UploadPhotoCallback()) @java.private @java.innerclass @java.implements(AsyncCallbackPhoto) class UploadPhotoCallback(Object): """ Upload photo response """ @java.init def __init__(self, *a, **kw): pass @java.typed(Throwable) def onFailure(self, caught): self.handleFailure(caught) @java.typed(Photo) def onSuccess(self, result): Window.alert(u"Photo uploaded") @__init__.register @java.typed() def __init__(self, ): self.__init__._super() self.outer = VerticalPanel() self.response = SimplePanel() inputWrapper = HorizontalPanel() inputWrapper.setSpacing(10) self.inputText = TextBox() self.createButton = Button(u"Create Album") self.visiList = ListBox(False) self.visiList.addItem(u"friends") self.visiList.addItem(u"friends_of_friends") self.visiList.addItem(u"networks") self.visiList.addItem(u"everyone") inputWrapper.add(self.inputText) inputWrapper.add(HTML(u" Visible ")) inputWrapper.add(self.visiList) inputWrapper.add(self.createButton) self.createButton.addClickHandler(self.CreateAlbumClickHandler()) self.outer.add(inputWrapper) self.outer.add(self.response) self.initWidget(self.outer) # outer.add ( createUploadPhotoUI () ); @java.private def createUploadPhotoUI(self): v = VerticalPanel() b = Button(u"Upload Photo") b.addClickHandler(self.UploadPhotoClickHandler()) v.add(b) return v @java.private @java.typed(String, String) def createAlbum(self, name, visible): album = Album.createAlbum(name, None, None, Visibility.valueOf(visible)) self.apiClient.photosCreateAlbum(album, self.CreateAlbumCallback())