PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 1ms

/examples/mail/AboutDialog.py

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