PageRenderTime 120ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/kitchensink/Layouts.py

http://pyjamas.googlecode.com/
Python | 112 lines | 96 code | 16 blank | 0 comment | 1 complexity | 5f320a2b2622ea08570b1d1c160d71b7 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. from Sink import Sink, SinkInfo
  2. from ui import Button, CheckBox, VerticalPanel, HorizontalPanel, HTML, DockPanel, HasAlignment, FlowPanel, HTMLPanel, MenuBar, MenuItem, ScrollPanel
  3. from Logger import Logger
  4. import DOM
  5. class Layouts(Sink):
  6. def __init__(self):
  7. text="This is a <code>ScrollPanel</code> contained at "
  8. text+= "the center of a <code>DockPanel</code>. "
  9. text+= "By putting some fairly large contents "
  10. text+= "in the middle and setting its size explicitly, it becomes a "
  11. text+= "scrollable area within the page, but without requiring the use of "
  12. text+= "an IFRAME."
  13. text+= "Here's quite a bit more meaningless text that will serve primarily "
  14. text+= "to make this thing scroll off the bottom of its visible area. "
  15. text+= "Otherwise, you might have to make it really, really small in order "
  16. text+= "to see the nifty scroll bars!"
  17. contents = HTML(text)
  18. scroller = ScrollPanel(contents)
  19. scroller.setStyleName("ks-layouts-Scroller")
  20. dock = DockPanel()
  21. dock.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
  22. north0 = HTML("This is the <i>first</i> north component", True)
  23. east = HTML("<center>This<br>is<br>the<br>east<br>component</center>", True)
  24. south = HTML("This is the south component")
  25. west = HTML("<center>This<br>is<br>the<br>west<br>component</center>", True)
  26. north1 = HTML("This is the <b>second</b> north component", True)
  27. dock.add(north0, DockPanel.NORTH)
  28. dock.add(east, DockPanel.EAST)
  29. dock.add(south, DockPanel.SOUTH)
  30. dock.add(west, DockPanel.WEST)
  31. dock.add(north1, DockPanel.NORTH)
  32. dock.add(scroller, DockPanel.CENTER)
  33. Logger.write("Layouts", "TODO: flowpanel")
  34. flow = FlowPanel()
  35. for i in range(8):
  36. flow.add(CheckBox("Flow " + i))
  37. horz = HorizontalPanel()
  38. horz.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
  39. horz.add(Button("Button"))
  40. horz.add(HTML("<center>This is a<br>very<br>tall thing</center>", True))
  41. horz.add(Button("Button"))
  42. vert = VerticalPanel()
  43. vert.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
  44. vert.add(Button("Small"))
  45. vert.add(Button("--- BigBigBigBig ---"))
  46. vert.add(Button("tiny"))
  47. menu = MenuBar()
  48. menu0 = MenuBar(True)
  49. menu1 = MenuBar(True)
  50. menu.addItem("menu0", menu0)
  51. menu.addItem("menu1", menu1)
  52. menu0.addItem("child00")
  53. menu0.addItem("child01")
  54. menu0.addItem("child02")
  55. menu1.addItem("child10")
  56. menu1.addItem("child11")
  57. menu1.addItem("child12")
  58. Logger.write("Layouts", "TODO: htmlpanel")
  59. id = HTMLPanel.createUniqueId()
  60. text="This is an <code>HTMLPanel</code>. It allows you to add "
  61. text+="components inside existing HTML, like this:" + "<span id='" + id
  62. text+="'></span>" + "Notice how the menu just fits snugly in there? Cute."
  63. html = HTMLPanel(text)
  64. DOM.setStyleAttribute(menu.getElement(), "display", "inline")
  65. html.add(menu, id)
  66. panel = VerticalPanel()
  67. panel.setSpacing(8)
  68. panel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
  69. panel.add(self.makeLabel("Dock Panel"))
  70. panel.add(dock)
  71. panel.add(self.makeLabel("Flow Panel"))
  72. panel.add(flow)
  73. panel.add(self.makeLabel("Horizontal Panel"))
  74. panel.add(horz)
  75. panel.add(self.makeLabel("Vertical Panel"))
  76. panel.add(vert)
  77. panel.add(self.makeLabel("HTML Panel"))
  78. panel.add(html)
  79. self.initWidget(panel)
  80. self.setStyleName("ks-layouts")
  81. def onShow(self):
  82. pass
  83. def makeLabel(self, caption):
  84. html = HTML(caption)
  85. html.setStyleName("ks-layouts-Label")
  86. return html
  87. def init():
  88. text="This page demonstrates some of the basic GWT panels, each of which"
  89. text+="arranges its contained widgets differently. "
  90. text+="These panels are designed to take advantage of the browser's "
  91. text+="built-in layout mechanics, which keeps the user interface snappy "
  92. text+="and helps your AJAX code play nicely with existing HTML. "
  93. text+="On the other hand, if you need pixel-perfect control, "
  94. text+="you can tweak things at a low level using the "
  95. text+="<code>DOM</code> class."
  96. return SinkInfo("Layouts", text, Layouts)