PageRenderTime 82ms CodeModel.GetById 41ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 0ms

/examples/mail/TopPanel.py

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