1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from pyjamas import DOM
17 from pyjamas import Factory
18
19 from pyjamas.ui.PopupPanel import PopupPanel
20 from pyjamas.ui.HTML import HTML
21 from pyjamas.ui.FlexTable import FlexTable
22 from pyjamas.ui.SimplePanel import SimplePanel
23 from pyjamas.ui import HasHorizontalAlignment
24 from pyjamas.ui import HasVerticalAlignment
25 from pyjamas.ui import GlassWidget
29 _props = [
30 ("caption", "Caption", "HTML", None),
31 ]
32
33 - def __init__(self, autoHide=None, modal=True, centered=False,
34 **kwargs):
35
36 self.dragging = False
37 self.dragStartX = 0
38 self.dragStartY = 0
39 self.child = None
40 self.panel = FlexTable(
41 Height="100%",
42 BorderWidth="0",
43 CellPadding="0",
44 CellSpacing="0",
45 )
46
47 cf = self.panel.getCellFormatter()
48 rf = self.panel.getRowFormatter()
49
50
51 self.modal = modal
52 self.caption = HTML()
53 self.caption.setStyleName("Caption")
54 self.caption.addMouseListener(self)
55
56
57
58
59
60 self.generate_gwt15 = kwargs.pop('gwt15', False) and True
61
62 if not self.generate_gwt15:
63 cf.setHeight(1, 0, "100%")
64 cf.setWidth(1, 0, "100%")
65 cf.setAlignment(
66 1, 0,
67 HasHorizontalAlignment.ALIGN_CENTER,
68 HasVerticalAlignment.ALIGN_MIDDLE,
69 )
70 self.panel.setWidget(0, 0, self.caption)
71 else:
72 row_labels = ['Top', 'Middle', 'Bottom']
73 col_labels = ['Left', 'Center', 'Right']
74
75 for r in range(3):
76 rf.setStyleName(r, 'dialog%s' % row_labels[r])
77 for c in range(3):
78 cf.setStyleName(r, c, 'dialog%s%s' % (row_labels[r],
79 col_labels[c]))
80 sp = SimplePanel()
81 sp.setStyleName('dialog%s%sInner' % (row_labels[r],
82 col_labels[c]))
83 self.panel.setWidget(r, c, sp)
84
85 cf.setAlignment(
86 1, 1,
87 HasHorizontalAlignment.ALIGN_CENTER,
88 HasVerticalAlignment.ALIGN_MIDDLE,
89 )
90
91 self.dialog_content = SimplePanel()
92 self.dialog_content.setStyleName('dialogContent')
93
94 self.panel.getWidget(0, 1).add(self.caption)
95 self.panel.getWidget(1, 1).add(self.dialog_content)
96
97
98 kwargs['StyleName'] = kwargs.get('StyleName', "gwt-DialogBox")
99 PopupPanel.__init__(self, autoHide, modal, **kwargs)
100 PopupPanel.setWidget(self, self.panel)
101
102 self.centered = centered
103
108
113
114 @classmethod
117
129
132
134 return self.caption.getText()
135
138
139 - def setText(self, text):
140 self.caption.setText(text)
141
143 self.dragging = True
144 GlassWidget.show(self.caption)
145 self.dragStartX = x
146 self.dragStartY = y
147
150
153
161
164
167
170
172 if not self.dragging:
173 return
174 self.dragging = False
175 GlassWidget.hide()
176
178 if self.child != widget:
179 return False
180
181 self.panel.remove(widget)
182 self.child = None
183 return True
184
188
192
207
208 Factory.registerClass('pyjamas.ui.DialogBox', 'DialogBox', DialogBox)
209