PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/kitchensink/Trees.py

http://pyjamas.googlecode.com/
Python | 122 lines | 104 code | 18 blank | 0 comment | 5 complexity | 20e2ce01d70bbca1374eca190fa46ef2 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. from Sink import Sink, SinkInfo
  2. from ui import Tree, TreeItem
  3. class Trees(Sink):
  4. def __init__(self):
  5. self.fProto = [
  6. Proto("Beethoven", [
  7. Proto("Concertos", [
  8. Proto("No. 1 - C"),
  9. Proto("No. 2 - B-Flat Major"),
  10. Proto("No. 3 - C Minor"),
  11. Proto("No. 4 - G Major"),
  12. Proto("No. 5 - E-Flat Major")
  13. ]),
  14. Proto("Quartets", [
  15. Proto("Six String Quartets"),
  16. Proto("Three String Quartets"),
  17. Proto("Grosse Fugue for String Quartets")
  18. ]),
  19. Proto("Sonatas", [
  20. Proto("Sonata in A Minor"),
  21. Proto("Sonata in F Major")
  22. ]),
  23. Proto("Symphonies", [
  24. Proto("No. 1 - C Major"),
  25. Proto("No. 2 - D Major"),
  26. Proto("No. 3 - E-Flat Major"),
  27. Proto("No. 4 - B-Flat Major"),
  28. Proto("No. 5 - C Minor"),
  29. Proto("No. 6 - F Major"),
  30. Proto("No. 7 - A Major"),
  31. Proto("No. 8 - F Major"),
  32. Proto("No. 9 - D Minor")
  33. ])
  34. ]),
  35. Proto("Brahms", [
  36. Proto("Concertos", [
  37. Proto("Violin Concerto"),
  38. Proto("Double Concerto - A Minor"),
  39. Proto("Piano Concerto No. 1 - D Minor"),
  40. Proto("Piano Concerto No. 2 - B-Flat Major")
  41. ]),
  42. Proto("Quartets", [
  43. Proto("Piano Quartet No. 1 - G Minor"),
  44. Proto("Piano Quartet No. 2 - A Major"),
  45. Proto("Piano Quartet No. 3 - C Minor"),
  46. Proto("String Quartet No. 3 - B-Flat Minor")
  47. ]),
  48. Proto("Sonatas", [
  49. Proto("Two Sonatas for Clarinet - F Minor"),
  50. Proto("Two Sonatas for Clarinet - E-Flat Major")
  51. ]),
  52. Proto("Symphonies", [
  53. Proto("No. 1 - C Minor"),
  54. Proto("No. 2 - D Minor"),
  55. Proto("No. 3 - F Major"),
  56. Proto("No. 4 - E Minor")
  57. ])
  58. ]),
  59. Proto("Mozart", [
  60. Proto("Concertos", [
  61. Proto("Piano Concerto No. 12"),
  62. Proto("Piano Concerto No. 17"),
  63. Proto("Clarinet Concerto"),
  64. Proto("Violin Concerto No. 5"),
  65. Proto("Violin Concerto No. 4")
  66. ]),
  67. ])
  68. ]
  69. self.fTree = Tree()
  70. for i in range(len(self.fProto)):
  71. self.createItem(self.fProto[i])
  72. self.fTree.addItem(self.fProto[i].item)
  73. self.fTree.addTreeListener(self)
  74. self.initWidget(self.fTree)
  75. def onTreeItemSelected(self, item):
  76. pass
  77. def onTreeItemStateChanged(self, item):
  78. child = item.getChild(0)
  79. if hasattr(child, "isPendingItem"):
  80. item.removeItem(child)
  81. proto = item.getUserObject()
  82. for i in range(len(proto.children)):
  83. self.createItem(proto.children[i])
  84. item.addItem(proto.children[i].item)
  85. def createItem(self, proto):
  86. proto.item = TreeItem(proto.text)
  87. proto.item.setUserObject(proto)
  88. if len(proto.children) > 0:
  89. proto.item.addItem(PendingItem())
  90. class Proto:
  91. def __init__(self, text, children=None):
  92. self.children = []
  93. self.item = None
  94. self.text = text
  95. if children != None:
  96. self.children = children
  97. class PendingItem(TreeItem):
  98. def __init__(self):
  99. TreeItem.__init__(self, "Please wait...")
  100. def isPendingItem(self):
  101. return True
  102. def init():
  103. text="GWT has a built-in <code>Tree</code> widget. The tree is focusable and has keyboard support as well."
  104. return SinkInfo("Trees", text, Trees)