class RecipeViewer(Sink): recipeDict = None def __init__(self, parent=None): Sink.__init__(self, parent) self.RVDock = HorizontalPanel(Spacing=5) self.RList = ListBox() self.RList.addClickListener(getattr(self, "onRecipeSelected")) self.RView = HTML() HTTPRequest().asyncGet("recipes.xml", RecipeListLoader(self)) self.RVDock.add(self.RList) self.RVDock.add(self.RView) self.initWidget(self.RVDock) def onRecipeSelected(self, item): recipe = self.RList.getItemText(self.RList.getSelectedIndex()) HTTPRequest().asyncGet("/recipecontent?recipe=%s" % recipe, RecipeViewLoader(self)) def onShow(self): pass
class graybox(): def onModuleLoad(self): self.remote = DataService() panel = VerticalPanel() self.graybox = TextBox() self.graybox.addKeyboardListener(self) self.grayList = ListBox() self.grayList.setVisibleItemCount(20) self.grayList.setWidth("200px") self.grayList.addClickListener(self) self.Status = Label("Status Label") panel.add(Label("Add New Task:")) panel.add(self.graybox) panel.add(Label("Click to Remove:")) panel.add(self.grayList) panel.add(self.Status) self.remote.getTasks(self) RootPanel().add(panel)
class SoftChordApp: def onModuleLoad(self): """ Gets run when the page is first loaded. Creates the widgets. """ self.remote = DataService() main_layout = VerticalPanel() h_layout = HorizontalPanel() h_layout.setPadding(10) songlist_layout = VerticalPanel() songlist_layout.add(Label("Add New Song:")) self.newSongTextBox = TextBox() self.newSongTextBox.addKeyboardListener(self) songlist_layout.add(self.newSongTextBox) self.addSongButton = Button("Add Song") self.addSongButton.addClickListener(self) songlist_layout.add(self.addSongButton) #songlist_layout.add(Label("Click to Remove:")) self.songListBox = ListBox() self.songListBox.setVisibleItemCount(7) self.songListBox.setWidth("300px") self.songListBox.setHeight("400px") self.songListBox.addClickListener(self) songlist_layout.add(self.songListBox) self.deleteSongButton = Button("Delete") self.deleteSongButton.addClickListener(self) songlist_layout.add(self.deleteSongButton) h_layout.add(songlist_layout) #self.textArea = TextArea() #self.textArea.setCharacterWidth(30) #self.textArea.setVisibleLines(50) #h_layout.add(self.textArea) #self.scrollPanel = ScrollPanel(Size=("400px", "500px")) self.songHtml = HTML("<b>Please select a song in the left table</b>") #self.scrollPanel.add(self.songHtml) #h_layout.add(self.scrollPanel) h_layout.add(self.songHtml) main_layout.add(h_layout) self.status = Label() main_layout.add(self.status) RootPanel().add(main_layout) # Populate the song table: self.remote.getAllSongs(self) def onKeyUp(self, sender, keyCode, modifiers): pass def onKeyDown(self, sender, keyCode, modifiers): pass def onKeyPress(self, sender, keyCode, modifiers): """ This functon handles the onKeyPress event """ if keyCode == KeyboardListener.KEY_ENTER and sender == self.newSongTextBox: id = self.remote.addSong(self.newSongTextBox.getText(), self) self.newSongTextBox.setText("") if id<0: self.status.setText("Server Error or Invalid Response") def onClick(self, sender): """ Gets called when a user clicked in the <sender> widget. Currently deletes the song on which the user clicked. """ if sender == self.songListBox: song_id = self.songListBox.getValue(self.songListBox.getSelectedIndex()) self.status.setText("selected song_id: %s" % song_id) id = self.remote.getSong(song_id, self) if id<0: self.status.setText("Server Error or Invalid Response") elif sender == self.addSongButton: id = self.remote.addSong(self.newSongTextBox.getText(), self) self.newSongTextBox.setText("") if id<0: self.status.setText("Server Error or Invalid Response") elif sender == self.deleteSongButton: # Figure out what song is selected in the table: song_id = self.songListBox.getValue(self.songListBox.getSelectedIndex()) self.status.setText("delete song_id: %s" % song_id) id = self.remote.deleteSong(song_id, self) if id<0: self.status.setText("Server Error or Invalid Response") def onRemoteResponse(self, response, request_info): """ Gets called when the backend (django) sends a packet to us. Populates the song table with all songs in the database. """ self.status.setText("response received") if request_info.method == 'getAllSongs' or request_info.method == 'addSong' or request_info.method == 'deleteSong': self.status.setText(self.status.getText() + " - song list received") self.songListBox.clear() for item in response: song_id, song_num, song_title = item if song_num: song_title = "%i %s" % (song_num, song_title) self.songListBox.addItem(song_title) self.songListBox.setValue(self.songListBox.getItemCount()-1, song_id) elif request_info.method == 'getSong': self.status.setText(self.status.getText() + " - song received") song_obj = songs.Song(response) self.status.setText(self.status.getText() + "; id: %i; num-chords: %i" % (song_obj.id, len(song_obj.chords) ) ) self.songHtml.setHTML(song_obj.getHtml()) #self.textArea.setText(song_obj.text) else: # Unknown response received form the server self.status.setText(self.status.getText() + "none!") def onRemoteError(self, code, errobj, request_info): message = errobj['message'] self.status.setText("Server Error or Invalid Response: ERROR %s - %s" % (code, message))
class AutoCompleteTextBox(TextBox): def __init__(self, **kwargs): self.choicesPopup = PopupPanel(True, False) self.choices = ListBox() self.items = SimpleAutoCompletionItems() self.popupAdded = False self.visible = False self.choices.addClickListener(self) self.choices.addChangeListener(self) self.choicesPopup.add(self.choices) self.choicesPopup.addStyleName("AutoCompleteChoices") self.choices.setStyleName("list") if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-AutoCompleteTextBox" TextBox.__init__(self, **kwargs) self.addKeyboardListener(self) def setCompletionItems(self, items): if not hasattr(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() - 1 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("%dpx" % self.getOffsetWidth()) 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) self.visible = False
class RolePanel(AbsolutePanel): user = None selectedRole = None roleList = None roleCombo = None addBtn = None removeBtn = None def __init__(self,parent): AbsolutePanel.__init__(self) self.roleList = ListBox() self.roleList.setWidth('300px') self.roleList.setVisibleItemCount(6) self.roleList.addClickListener(self.onListClick) self.roleList.addKeyboardListener(self) self.roleCombo = ListBox() self.roleCombo.addClickListener(self.onComboClick) self.roleCombo.addKeyboardListener(self) self.addBtn = Button("Add", self) self.addBtn.addClickListener(self.onAdd) self.addBtn.setEnabled(False) self.removeBtn = Button("Remove", self) self.removeBtn.addClickListener(self.onRemove) self.removeBtn.setEnabled(False) vpanel = VerticalPanel() vpanel.add(self.roleList) hpanel = HorizontalPanel() hpanel.add(self.roleCombo) hpanel.add(self.addBtn) hpanel.add(self.removeBtn) vpanel.add(hpanel) self.add(vpanel) return def updateRoleList(self,items): self.roleList.clear() for item in items: self.roleList.addItem(item) #self.roleList.addItem(' ') #self.roleList.addItem('- - - - - - - -') def updateRoleCombo(self,choices, default_): self.roleCombo.clear() for choice in choices: self.roleCombo.addItem(choice) self.roleCombo.selectValue(default_) def onComboClick(self, sender, keyCode=None, modifiers=None): selected = self.roleCombo.getSelectedItemText() if not selected or not self.user: self.addBtn.setEnabled(False) self.selectedRole=None else: self.addBtn.setEnabled(True) self.selectedRole=selected[0] self.removeBtn.setEnabled(False) self.roleList.setItemTextSelection(None) def onListClick(self, sender): selected = self.roleList.getSelectedItemText() if selected: self.removeBtn.setEnabled(True) self.selectedRole=selected[0] else: self.removeBtn.setEnabled(False) self.selectedRole=None self.addBtn.setEnabled(False) self.roleCombo.setItemTextSelection(None) def onAdd(self, evt): self.mediator.sendNotification(EmployeeAdmin.AppFacade.ADD_ROLE,self.selectedRole) def onRemove(self,evt): self.mediator.sendNotification(EmployeeAdmin.AppFacade.REMOVE_ROLE,self.selectedRole) def onClick(self, sender): pass def onKeyUp(self, sender, keyCode, modifiers): if sender == self.roleCombo: self.onComboClick(sender) elif sender == self.roleList: self.onListClick(sender) def onKeyDown(self, sender, keyCode, modifiers): pass def onKeyPress(self, sender, keyCode, modifiers): pass
class AutoCompleteTextBox(TextBox): def __init__(self, **kwargs): self.choicesPopup = PopupPanel(True, False) self.choices = ListBox() self.items = SimpleAutoCompletionItems() self.popupAdded = False self.visible = False self.choices.addClickListener(self) self.choices.addChangeListener(self) self.choicesPopup.add(self.choices) self.choicesPopup.addStyleName("AutoCompleteChoices") self.choices.setStyleName("list") if not kwargs.has_key('StyleName'): kwargs['StyleName'] = "gwt-AutoCompleteTextBox" TextBox.__init__(self, **kwargs) self.addKeyboardListener(self) def setCompletionItems(self, items): if not hasattr(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() - 1 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("%dpx" % self.getOffsetWidth()) 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) self.visible = False
class TodoApp: def onModuleLoad(self): self.remote = DataService() panel = VerticalPanel() self.todoTextBox = TextBox() self.todoTextBox.addKeyboardListener(self) self.todoList = ListBox() self.todoList.setVisibleItemCount(7) self.todoList.setWidth("200px") self.todoList.addClickListener(self) panel.add(Label("Add New Todo:")) panel.add(self.todoTextBox) panel.add(Label("Click to Remove:")) panel.add(self.todoList) self.status = Label() panel.add(self.status) RootPanel().add(panel) def onKeyUp(self, sender, keyCode, modifiers): pass def onKeyDown(self, sender, keyCode, modifiers): pass def onKeyPress(self, sender, keyCode, modifiers): """ This functon handles the onKeyPress event, and will add the item in the text box to the list when the user presses the enter key. In the future, this method will also handle the auto complete feature. """ if keyCode == KeyboardListener.KEY_ENTER and sender == self.todoTextBox: id = self.remote.addTask(sender.getText(),self) sender.setText("") if id<0: self.status.setText("Server Error or Invalid Response") def onClick(self, sender): id = self.remote.deleteTask(sender.getValue(sender.getSelectedIndex()),self) if id<0: self.status.setText("Server Error or Invalid Response") def onRemoteResponse(self, response, request_info): self.status.setText("response received") if request_info.method == 'getTasks' or request_info.method == 'addTask' or request_info.method == 'deleteTask': self.status.setText(self.status.getText() + "HERE!") self.todoList.clear() for task in response: self.todoList.addItem(task[0]) self.todoList.setValue(self.todoList.getItemCount()-1,task[1]) else: self.status.setText(self.status.getText() + "none!") def onRemoteError(self, code, errobj, request_info): message = errobj['message'] self.status.setText("Server Error or Invalid Response: ERROR %s - %s" % (code, message))
class WebPageEdit(Composite): def __init__(self, sink): Composite.__init__(self) self.remote = sink.remote panel = VerticalPanel(Width="100%", Spacing=8) self.view = Button("View", self) self.newpage = Button("New", self) self.todoId = None self.todoTextName = TextBox() self.todoTextName.addKeyboardListener(self) self.todoTextArea = RichTextEditor(basePath="/fckeditor/") self.todoTextArea.setWidth("100%") self.todoTextArea.addSaveListener(self) self.todoList = ListBox() self.todoList.setVisibleItemCount(7) self.todoList.setWidth("200px") self.todoList.addClickListener(self) self.fDialogButton = Button("Upload Files", self) self.status = HTML() panel.add(HTML("Status:")) panel.add(self.status) panel.add(self.fDialogButton) panel.add(Label("Create New Page (doesn't save current one!):")) panel.add(self.newpage) panel.add(Label("Add/Edit New Page:")) panel.add(self.todoTextName) panel.add(Label("Click to Load and Edit (doesn't save current one!):")) panel.add(self.todoList) panel.add(self.view) panel.add(Label("New Page HTML. Click 'save' icon to save. (pagename is editable as well)")) panel.add(self.todoTextArea) self.setWidget(panel) self.remote.getPages(self) def onKeyUp(self, sender, keyCode, modifiers): pass def onKeyDown(self, sender, keyCode, modifiers): pass def onKeyPress(self, sender, keyCode, modifiers): """ This functon handles the onKeyPress event, and will add the item in the text box to the list when the user presses the enter key. In the future, this method will also handle the auto complete feature. """ pass def onSave(self, editor): self.status.setText("") name = self.todoTextName.getText() if not name: self.status.setText("Please enter a name for the page") return item = {"name": name, "text": self.todoTextArea.getHTML()} if self.todoId is None: rid = self.remote.addPage(item, self) else: item["id"] = self.todoId rid = self.remote.updatePage(item, self) if rid < 0: self.status.setHTML("Server Error or Invalid Response") return def onClick(self, sender): if sender == self.newpage: self.todoId = None self.todoTextName.setText("") self.todoTextArea.setHTML("") return elif sender == self.view: name = self.todoTextName.getText() html = self.todoTextArea.getHTML() if not html: return p = HTMLDialog(name, html) p.setPopupPosition(10, 10) p.setWidth(Window.getClientWidth() - 40) p.setHeight(Window.getClientHeight() - 40) p.show() return elif sender == self.fDialogButton: Window.open(fileedit_url, "fileupload", "width=800,height=600") return dlg = FileDialog(fileedit_url) left = self.fDialogButton.getAbsoluteLeft() + 10 top = self.fDialogButton.getAbsoluteTop() + 10 dlg.setPopupPosition(left, top) dlg.show() id = self.remote.getPage(sender.getValue(sender.getSelectedIndex()), self) if id < 0: self.status.setHTML("Server Error or Invalid Response") def onRemoteResponse(self, response, request_info): self.status.setHTML("response received") if request_info.method == "getPage": self.status.setHTML(self.status.getText() + "HERE!") item = response[0] self.todoId = item["pk"] self.todoTextName.setText(item["fields"]["name"]) self.todoTextArea.setHTML(item["fields"]["text"]) elif ( request_info.method == "getPages" or request_info.method == "addPage" or request_info.method == "deletePage" ): self.status.setHTML(self.status.getText() + "HERE!") self.todoList.clear() for task in response: self.todoList.addItem(task["fields"]["name"]) self.todoList.setValue(self.todoList.getItemCount() - 1, str(task["pk"])) else: self.status.setHTML(self.status.getText() + "none!") def onRemoteError(self, code, message, request_info): self.status.setHTML("Server Error or Invalid Response: ERROR " + str(code) + " - " + str(message))
class WebPageEdit(Composite): def __init__(self, sink): Composite.__init__(self) self.remote = sink.remote panel = VerticalPanel(Width="100%", Spacing=8) self.view = Button("View", self) self.newpage = Button("New", self) self.todoId = None self.todoTextName = TextBox() self.todoTextName.addKeyboardListener(self) self.todoTextArea = RichTextEditor(basePath="/fckeditor/") self.todoTextArea.setWidth("100%") self.todoTextArea.addSaveListener(self) self.todoList = ListBox() self.todoList.setVisibleItemCount(7) self.todoList.setWidth("200px") self.todoList.addClickListener(self) self.fDialogButton = Button("Upload Files", self) self.status = HTML() panel.add(HTML("Status:")) panel.add(self.status) panel.add(self.fDialogButton) panel.add(Label("Create New Page (doesn't save current one!):")) panel.add(self.newpage) panel.add(Label("Add/Edit New Page:")) panel.add(self.todoTextName) panel.add(Label("Click to Load and Edit (doesn't save current one!):")) panel.add(self.todoList) panel.add(self.view) panel.add(Label("New Page HTML. Click 'save' icon to save. (pagename is editable as well)")) panel.add(self.todoTextArea) self.setWidget(panel) self.remote.getPages(self) def onKeyUp(self, sender, keyCode, modifiers): pass def onKeyDown(self, sender, keyCode, modifiers): pass def onKeyPress(self, sender, keyCode, modifiers): """ This functon handles the onKeyPress event, and will add the item in the text box to the list when the user presses the enter key. In the future, this method will also handle the auto complete feature. """ pass def onSave(self, editor): self.status.setText("") name = self.todoTextName.getText() if not name: self.status.setText("Please enter a name for the page") return item = { 'name': name, 'text': self.todoTextArea.getHTML() } if self.todoId is None: rid = self.remote.addPage(item, self) else: item['id'] = self.todoId rid = self.remote.updatePage(item, self) if rid<0: self.status.setHTML("Server Error or Invalid Response") return def onClick(self, sender): if sender == self.newpage: self.todoId = None self.todoTextName.setText('') self.todoTextArea.setHTML('') return elif sender == self.view: name = self.todoTextName.getText() html = self.todoTextArea.getHTML() if not html: return p = HTMLDialog(name, html) p.setPopupPosition(10, 10) p.setWidth(Window.getClientWidth()-40) p.setHeight(Window.getClientHeight()-40) p.show() return elif sender == self.fDialogButton: Window.open(fileedit_url, "fileupload", "width=800,height=600") return dlg = FileDialog(fileedit_url) left = self.fDialogButton.getAbsoluteLeft() + 10 top = self.fDialogButton.getAbsoluteTop() + 10 dlg.setPopupPosition(left, top) dlg.show() id = self.remote.getPage(sender.getValue(sender.getSelectedIndex()),self) if id<0: self.status.setHTML("Server Error or Invalid Response") def onRemoteResponse(self, response, request_info): self.status.setHTML("response received") if request_info.method == 'getPage': self.status.setHTML(self.status.getText() + "HERE!") item = response[0] self.todoId = item['pk'] self.todoTextName.setText(item['fields']['name']) self.todoTextArea.setHTML(item['fields']['text']) elif (request_info.method == 'getPages' or request_info.method == 'addPage' or request_info.method == 'deletePage'): self.status.setHTML(self.status.getText() + "HERE!") self.todoList.clear() for task in response: self.todoList.addItem(task['fields']['name']) self.todoList.setValue(self.todoList.getItemCount()-1, str(task['pk'])) else: self.status.setHTML(self.status.getText() + "none!") def onRemoteError(self, code, message, request_info): self.status.setHTML("Server Error or Invalid Response: ERROR " + str(code) + " - " + str(message))
class TodoApp: def onModuleLoad(self): self.remote = DataService() panel = VerticalPanel() self.todoTextBox = TextBox() self.todoTextBox.addKeyboardListener(self) self.todoList = ListBox() self.todoList.setVisibleItemCount(7) self.todoList.setWidth("200px") self.todoList.addClickListener(self) panel.add(Label("Add New Todo:")) panel.add(self.todoTextBox) panel.add(Label("Click to Remove:")) panel.add(self.todoList) self.status = Label() panel.add(self.status) RootPanel().add(panel) def onKeyUp(self, sender, keyCode, modifiers): pass def onKeyDown(self, sender, keyCode, modifiers): pass def onKeyPress(self, sender, keyCode, modifiers): """ This functon handles the onKeyPress event, and will add the item in the text box to the list when the user presses the enter key. In the future, this method will also handle the auto complete feature. """ if keyCode == KeyboardListener.KEY_ENTER and sender == self.todoTextBox: id = self.remote.addTask(sender.getText(), self) sender.setText("") if id < 0: self.status.setText("Server Error or Invalid Response") def onClick(self, sender): id = self.remote.deleteTask(sender.getValue(sender.getSelectedIndex()), self) if id < 0: self.status.setText("Server Error or Invalid Response") def onRemoteResponse(self, response, request_info): self.status.setText("response received") if request_info.method == 'getTasks' or request_info.method == 'addTask' or request_info.method == 'deleteTask': self.status.setText(self.status.getText() + "HERE!") self.todoList.clear() for task in response: self.todoList.addItem(task[0]) self.todoList.setValue(self.todoList.getItemCount() - 1, task[1]) else: self.status.setText(self.status.getText() + "none!") def onRemoteError(self, code, errobj, request_info): message = errobj['message'] self.status.setText("Server Error or Invalid Response: ERROR %s - %s" % (code, message))
class RolePanel(AbsolutePanel): user = None selectedRole = None roleList = None roleCombo = None addBtn = None removeBtn = None def __init__(self,parent): AbsolutePanel.__init__(self) self.roleList = ListBox() self.roleList.setWidth('300px') self.roleList.setVisibleItemCount(6) self.roleList.addClickListener(self.onListClick) self.roleList.addKeyboardListener(self) self.roleCombo = ListBox() self.roleCombo.addClickListener(self.onComboClick) self.roleCombo.addKeyboardListener(self) self.addBtn = Button("Add") self.addBtn.setEnabled(False) self.removeBtn = Button("Remove") self.removeBtn.setEnabled(False) vpanel = VerticalPanel() vpanel.add(self.roleList) hpanel = HorizontalPanel() hpanel.add(self.roleCombo) hpanel.add(self.addBtn) hpanel.add(self.removeBtn) vpanel.add(hpanel) self.add(vpanel) return def updateRoleList(self,items): self.roleList.clear() for item in items: self.roleList.addItem(item) #self.roleList.addItem(' ') #self.roleList.addItem('- - - - - - - -') def updateRoleCombo(self,choices, default_): self.roleCombo.clear() for choice in choices: self.roleCombo.addItem(choice) self.roleCombo.selectValue(default_) def onComboClick(self, sender, keyCode=None, modifiers=None): selected = self.roleCombo.getSelectedItemText() if not selected \ or selected[0] == ApplicationConstants.ROLE_NONE_SELECTED \ or not self.user: self.addBtn.setEnabled(False) self.selectedRole=None else: self.addBtn.setEnabled(True) self.selectedRole=selected[0] self.removeBtn.setEnabled(False) self.roleList.setItemTextSelection(None) def onListClick(self, sender): selected = self.roleList.getSelectedItemText() if selected: self.removeBtn.setEnabled(True) self.selectedRole=selected[0] else: self.removeBtn.setEnabled(False) self.selectedRole=None self.addBtn.setEnabled(False) self.roleCombo.setItemTextSelection(None) def onClick(self, sender): pass def onKeyUp(self, sender, keyCode, modifiers): if sender == self.roleCombo: self.onComboClick(sender) elif sender == self.roleList: self.onListClick(sender) def onKeyDown(self, sender, keyCode, modifiers): pass def onKeyPress(self, sender, keyCode, modifiers): pass