PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 9ms RepoModel.GetById 1ms 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
 1from Sink import Sink, SinkInfo
 2from ui import Button, VerticalPanel, PopupPanel, ListBox, HTML, DockPanel, DialogBox, Frame, HasAlignment
 3import DOM
 4
 5class Popups(Sink):
 6    def __init__(self):
 7        self.fDialogButton = Button("Show Dialog", self)
 8        self.fPopupButton = Button("Show Popup", self)
 9        
10        panel = VerticalPanel()
11        panel.add(self.fPopupButton)
12        panel.add(self.fDialogButton)
13        
14        list = ListBox()
15        list.setVisibleItemCount(5)
16        for i in range(10):
17            list.addItem("list item " + i)
18        panel.add(list)
19        
20        panel.setSpacing(8)
21        self.initWidget(panel)
22
23    def onShow(self):
24        pass
25
26    def onClick(self, sender):
27        if sender == self.fPopupButton:
28            p = MyPopup()
29            left = sender.getAbsoluteLeft() + 10
30            top = sender.getAbsoluteTop() + 10
31            p.setPopupPosition(left, top)
32            p.show()
33        elif sender == self.fDialogButton:
34            dlg = MyDialog()
35            left = self.fDialogButton.getAbsoluteLeft() + 10
36            top = self.fDialogButton.getAbsoluteTop() + 10
37            dlg.setPopupPosition(left, top)
38            dlg.show()
39
40
41def init():
42    text="This page demonstrates GWT's built-in support for in-page "
43    text+="popups.  The first is a very simple informational popup that closes "
44    text+="itself automatically when you click off of it.  The second is a more "
45    text+="complex draggable dialog box. If you're wondering why there's "
46    text+="a list box at the bottom, it's to demonstrate that you can drag the "
47    text+="dialog box over it.  "
48    text+="This is noteworthy because some browsers render lists and combos in "
49    text+="a funky way that, if GWT didn't do some magic for you, would "
50    text+="normally cause the dialog box to appear to hover <i>underneath</i> "
51    text+="the list box.  Fortunately, you don't have to worry about it -- "
52    text+="just use the GWT <code>DialogBox</code> class."
53    return SinkInfo("Popups", text, Popups)
54
55
56class MyDialog(DialogBox):
57    def __init__(self):
58        DialogBox.__init__(self)
59        self.setText("Sample DialogBox with embedded Frame")
60        
61        iframe = Frame(Popups.baseURL() + "rembrandt/LaMarcheNocturne.html")
62        closeButton = Button("Close", self)
63        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)
64        
65        dock = DockPanel()
66        dock.setSpacing(4)
67        
68        dock.add(closeButton, DockPanel.SOUTH)
69        dock.add(msg, DockPanel.NORTH)
70        dock.add(iframe, DockPanel.CENTER)
71        
72        dock.setCellHorizontalAlignment(closeButton, HasAlignment.ALIGN_RIGHT)
73        dock.setCellWidth(iframe, "100%")
74        dock.setWidth("100%")
75        iframe.setWidth("36em")
76        iframe.setHeight("20em")
77        self.setWidget(dock)
78
79    def onClick(self, sender):
80        self.hide()
81
82
83class MyPopup(PopupPanel):
84    def __init__(self):
85        PopupPanel.__init__(self, True)
86        
87        contents = HTML("Click anywhere outside this popup to make it disappear.")
88        contents.setWidth("128px")
89        self.setWidget(contents)
90        
91        self.setStyleName("ks-popups-Popup")