PageRenderTime 29ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/kitchensink/Lists.py

http://pyjamas.googlecode.com/
Python | 70 lines | 54 code | 16 blank | 0 comment | 6 complexity | 2f2e56a2a48be1301ca7c85263a8475d MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. from Sink import Sink, SinkInfo
  2. from ui import ListBox, HorizontalPanel, VerticalPanel, HasAlignment, Label, Widget
  3. class Lists(Sink):
  4. def __init__(self):
  5. self.sStrings=[["foo0", "bar0", "baz0", "toto0", "tintin0"],
  6. ["foo1", "bar1", "baz1", "toto1", "tintin1"],
  7. ["foo2", "bar2", "baz2", "toto2", "tintin2"],
  8. ["foo3", "bar3", "baz3", "toto3", "tintin3"],
  9. ["foo4", "bar4", "baz4", "toto4", "tintin4"]]
  10. self.combo=ListBox()
  11. self.list=ListBox()
  12. self.echo=Label()
  13. self.combo.setVisibleItemCount(1)
  14. self.combo.addChangeListener(self)
  15. self.list.setVisibleItemCount(10)
  16. self.list.setMultipleSelect(True)
  17. for i in range(len(self.sStrings)):
  18. self.combo.addItem("List " + i)
  19. self.combo.setSelectedIndex(0)
  20. self.fillList(0)
  21. self.list.addChangeListener(self)
  22. horz = HorizontalPanel()
  23. horz.setVerticalAlignment(HasAlignment.ALIGN_TOP)
  24. horz.setSpacing(8)
  25. horz.add(self.combo)
  26. horz.add(self.list)
  27. panel = VerticalPanel()
  28. panel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT)
  29. panel.add(horz)
  30. panel.add(self.echo)
  31. self.initWidget(panel)
  32. self.echoSelection()
  33. def onChange(self, sender):
  34. if sender == self.combo:
  35. self.fillList(self.combo.getSelectedIndex())
  36. elif sender == self.list:
  37. self.echoSelection()
  38. def onShow(self):
  39. pass
  40. def fillList(self, idx):
  41. self.list.clear()
  42. strings = self.sStrings[idx]
  43. for i in range(len(strings)):
  44. self.list.addItem(strings[i])
  45. self.echoSelection()
  46. def echoSelection(self):
  47. msg = "Selected items: "
  48. for i in range(self.list.getItemCount()):
  49. if self.list.isItemSelected(i):
  50. msg += self.list.getItemText(i) + " "
  51. self.echo.setText(msg)
  52. def init():
  53. text="Here is the ListBox widget in its two major forms."
  54. return SinkInfo("Lists", text, Lists)