PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/kitchensink/Popups.py

http://pyjamas.googlecode.com/
Python | 91 lines | 72 code | 19 blank | 0 comment | 3 complexity | cf42ad29e651b3bc79728ba13601a68e MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. from Sink import Sink, SinkInfo
  2. from ui import Button, VerticalPanel, PopupPanel, ListBox, HTML, DockPanel, DialogBox, Frame, HasAlignment
  3. import DOM
  4. class Popups(Sink):
  5. def __init__(self):
  6. self.fDialogButton = Button("Show Dialog", self)
  7. self.fPopupButton = Button("Show Popup", self)
  8. panel = VerticalPanel()
  9. panel.add(self.fPopupButton)
  10. panel.add(self.fDialogButton)
  11. list = ListBox()
  12. list.setVisibleItemCount(5)
  13. for i in range(10):
  14. list.addItem("list item " + i)
  15. panel.add(list)
  16. panel.setSpacing(8)
  17. self.initWidget(panel)
  18. def onShow(self):
  19. pass
  20. def onClick(self, sender):
  21. if sender == self.fPopupButton:
  22. p = MyPopup()
  23. left = sender.getAbsoluteLeft() + 10
  24. top = sender.getAbsoluteTop() + 10
  25. p.setPopupPosition(left, top)
  26. p.show()
  27. elif sender == self.fDialogButton:
  28. dlg = MyDialog()
  29. left = self.fDialogButton.getAbsoluteLeft() + 10
  30. top = self.fDialogButton.getAbsoluteTop() + 10
  31. dlg.setPopupPosition(left, top)
  32. dlg.show()
  33. def init():
  34. text="This page demonstrates GWT's built-in support for in-page "
  35. text+="popups. The first is a very simple informational popup that closes "
  36. text+="itself automatically when you click off of it. The second is a more "
  37. text+="complex draggable dialog box. If you're wondering why there's "
  38. text+="a list box at the bottom, it's to demonstrate that you can drag the "
  39. text+="dialog box over it. "
  40. text+="This is noteworthy because some browsers render lists and combos in "
  41. text+="a funky way that, if GWT didn't do some magic for you, would "
  42. text+="normally cause the dialog box to appear to hover <i>underneath</i> "
  43. text+="the list box. Fortunately, you don't have to worry about it -- "
  44. text+="just use the GWT <code>DialogBox</code> class."
  45. return SinkInfo("Popups", text, Popups)
  46. class MyDialog(DialogBox):
  47. def __init__(self):
  48. DialogBox.__init__(self)
  49. self.setText("Sample DialogBox with embedded Frame")
  50. iframe = Frame(Popups.baseURL() + "rembrandt/LaMarcheNocturne.html")
  51. closeButton = Button("Close", self)
  52. msg = HTML("<center>This is an example of a standard dialog box component.<br> You can put pretty much anything you like into it,<br>such as the following IFRAME:</center>", True)
  53. dock = DockPanel()
  54. dock.setSpacing(4)
  55. dock.add(closeButton, DockPanel.SOUTH)
  56. dock.add(msg, DockPanel.NORTH)
  57. dock.add(iframe, DockPanel.CENTER)
  58. dock.setCellHorizontalAlignment(closeButton, HasAlignment.ALIGN_RIGHT)
  59. dock.setCellWidth(iframe, "100%")
  60. dock.setWidth("100%")
  61. iframe.setWidth("36em")
  62. iframe.setHeight("20em")
  63. self.setWidget(dock)
  64. def onClick(self, sender):
  65. self.hide()
  66. class MyPopup(PopupPanel):
  67. def __init__(self):
  68. PopupPanel.__init__(self, True)
  69. contents = HTML("Click anywhere outside this popup to make it disappear.")
  70. contents.setWidth("128px")
  71. self.setWidget(contents)
  72. self.setStyleName("ks-popups-Popup")