PageRenderTime 37ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/mail/AboutDialog.py

http://pyjamas.googlecode.com/
Python | 51 lines | 27 code | 12 blank | 12 comment | 2 complexity | 83bc4f39cb29f1d5d3d66f559f6c0329 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. from ui import Button, ClickListener, DialogBox, DockPanel, HorizontalPanel, HTML, Image, KeyboardListener, Widget, HasAlignment
  2. class AboutDialog(DialogBox):
  3. LOGO_IMAGE = "http://trac.pyworks.org/pyjamas/chrome/site/pyjamas-logo-small.png"
  4. def __init__(self):
  5. DialogBox.__init__(self)
  6. # Use this opportunity to set the dialog's caption.
  7. self.setText("About the Mail Sample")
  8. # Create a DockPanel to contain the 'about' label and the 'OK' button.
  9. outer = DockPanel()
  10. outer.setSpacing(4)
  11. outer.add(Image(AboutDialog.LOGO_IMAGE), DockPanel.WEST)
  12. # Create the 'OK' button, along with a listener that hides the dialog
  13. # when the button is clicked. Adding it to the 'south' position within
  14. # the dock causes it to be placed at the bottom.
  15. buttonPanel = HorizontalPanel()
  16. buttonPanel.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT)
  17. buttonPanel.add(Button("Close", self))
  18. outer.add(buttonPanel, DockPanel.SOUTH)
  19. # Create the 'about' label. Placing it in the 'rest' position within the
  20. # dock causes it to take up any remaining space after the 'OK' button
  21. # has been laid out.
  22. textplain = "This sample application demonstrates the construction "
  23. textplain += "of a complex user interface using pyjamas' built-in widgets. Have a look "
  24. textplain += "at the code to see how easy it is to build your own apps!"
  25. text = HTML(textplain)
  26. text.setStyleName("mail-AboutText")
  27. outer.add(text, DockPanel.CENTER)
  28. # Add a bit of spacing and margin to the dock to keep the components from
  29. # being placed too closely together.
  30. outer.setSpacing(8)
  31. self.setWidget(outer)
  32. def onClick(self, sender):
  33. self.hide()
  34. def onKeyDownPreview(self, key, modifiers):
  35. # Use the popup's key preview hooks to close the dialog when either
  36. # enter or escape is pressed.
  37. if (key == KeyboardListener.KEY_ESCAPE or key == KeyboardListener.KEY_ENTER):
  38. self.hide()
  39. return True