PageRenderTime 130ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/mail/TopPanel.py

http://pyjamas.googlecode.com/
Python | 50 lines | 35 code | 11 blank | 4 comment | 2 complexity | 94ef9dceb7098bfceefedcc3813d925e MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. import Window
  2. from ui import ClickListener, Composite, HTML, HorizontalPanel, VerticalPanel, Widget, HasAlignment
  3. from AboutDialog import AboutDialog
  4. from Logger import Logger
  5. class TopPanel(Composite):
  6. def __init__(self):
  7. self.signOutLink = HTML("<a href='javascript:;'>Sign Out</a>")
  8. self.aboutLink = HTML("<a href='javascript:;'>About</a>")
  9. outer = HorizontalPanel()
  10. inner = VerticalPanel()
  11. outer.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT)
  12. inner.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT)
  13. links = HorizontalPanel()
  14. links.setSpacing(4)
  15. links.add(self.signOutLink)
  16. links.add(self.aboutLink)
  17. outer.add(inner)
  18. inner.add(HTML("<b>Welcome back, foo@example.com</b>"))
  19. inner.add(links)
  20. self.signOutLink.addClickListener(self)
  21. self.aboutLink.addClickListener(self)
  22. self.initWidget(outer)
  23. inner.setStyleName("mail-TopPanel")
  24. links.setStyleName("mail-TopPanelLinks")
  25. def onClick(self, sender):
  26. if (sender == self.signOutLink):
  27. Window.alert("If this were implemented, you would be signed out now.")
  28. elif (sender == self.aboutLink):
  29. # When the 'About' item is selected, show the AboutDialog.
  30. # Note that showing a dialog box does not block -- execution continues
  31. # normally, and the dialog fires an event when it is closed.
  32. dlg = AboutDialog()
  33. # Position it roughly in the middle of the screen.
  34. left = (Window.getClientWidth() - 512) / 2
  35. top = (Window.getClientHeight() - 256) / 2
  36. Logger("TopPanel", "left: " + left)
  37. Logger("TopPanel", "top: " + top)
  38. dlg.setPopupPosition(left, top)
  39. dlg.show()