本文整理汇总了Python中pyjamas.ui.ListBox.ListBox.addClickListener方法的典型用法代码示例。如果您正苦于以下问题:Python ListBox.addClickListener方法的具体用法?Python ListBox.addClickListener怎么用?Python ListBox.addClickListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.ui.ListBox.ListBox
的用法示例。
在下文中一共展示了ListBox.addClickListener方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RecipeViewer
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import addClickListener [as 别名]
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
示例2: graybox
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import addClickListener [as 别名]
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)
示例3: onModuleLoad
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import addClickListener [as 别名]
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:
#.........这里部分代码省略.........
示例4: AutoCompleteTextBox
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import addClickListener [as 别名]
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):
#.........这里部分代码省略.........
示例5: RolePanel
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import addClickListener [as 别名]
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
示例6: onModuleLoad
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import addClickListener [as 别名]
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))
示例7: WebPageEdit
# 需要导入模块: from pyjamas.ui.ListBox import ListBox [as 别名]
# 或者: from pyjamas.ui.ListBox.ListBox import addClickListener [as 别名]
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)
#.........这里部分代码省略.........