1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 from pyjamas import DOM
16 from pyjamas import Factory
17
18 from pyjamas.ui.UIObject import UIObject
19 from DialogBox import DialogBox
20 from HTML import HTML
21 from FlexTable import FlexTable
22 from pyjamas.ui.HorizontalPanel import HorizontalPanel
23 from pyjamas.ui.SimplePanel import SimplePanel
24 from pyjamas.ui import HasHorizontalAlignment
25 from pyjamas.ui import HasVerticalAlignment
26 from pyjamas.ui.Image import Image
27 from pyjamas.ui.Button import Button
28 from pyjamas.ui import GlassWidget
29 from pyjamas.ui import HasAlignment
30 import pyjamas.Window
31
32
33
34
35
36
37
38
39
40
41
42
43
44
46 _props = [
47 ("caption", "Caption", "HTML", None),
48 ]
49
50 - def __init__(self, autoHide=None, modal=True, centered=False,
51 caption=None, minimize=None, maximize=None, close=None,
52 captionStyle=None,
53 **kwargs):
54
55 DialogBox.__init__(self, autoHide, modal, centered, **kwargs)
56 self._dialogListeners = []
57 self._minimized = None
58 self._maximized = None
59
60
61 if isinstance(caption, basestring):
62 self.caption.setText(caption)
63 elif caption is not None:
64 self.caption = caption
65 self.caption.addMouseListener(self)
66 if captionStyle is not None:
67 self.caption.setStyleName(captionStyle)
68 else:
69 self.caption.addStyleName('WindowCaption')
70 self.setControls(minimize, maximize, close)
71
73 if control_type == 'minimize':
74 return Button("_")
75 elif control_type == 'maximize':
76 return Button("^")
77 elif control_type == 'close':
78 return Button("X")
79 raise ValueError("Invalid control '%s'" % control_type)
80
82 if minimize is True:
83 self.minimizeWidget = self.createDefaultControl('minimize')
84 elif isinstance(minimize, basestring):
85 self.minimizeWidget = Image(minimize)
86 else:
87 self.minimizeWidget = minimize
88 if maximize is True:
89 self.maximizeWidget = self.createDefaultControl('maximize')
90 elif isinstance(maximize, basestring):
91 self.maximizeWidget = Image(maximize)
92 else:
93 self.maximizeWidget = maximize
94 if close is True:
95 self.closeWidget = self.createDefaultControl('close')
96 elif isinstance(close, basestring):
97 self.closeWidget = Image(close)
98 else:
99 self.closeWidget = close
100 if (isinstance(self.minimizeWidget, UIObject) or
101 isinstance(self.maximizeWidget, UIObject) or
102 isinstance(self.closeWidget, UIObject)):
103 cf = self.panel.getCellFormatter()
104 captionStyle = self.caption.getStyleName()
105 captionPanel = FlexTable(
106 Width="99%",
107 BorderWidth="0",
108 CellPadding="0",
109 CellSpacing="0",
110 )
111 controls = HorizontalPanel()
112 controls.setStyleName("Controls")
113 controls.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
114 if isinstance(self.minimizeWidget, UIObject):
115 self.minimizeWidget.setStyleName("Minimize")
116 controls.add(self.minimizeWidget)
117 self.minimizeWidget.addClickListener(
118 getattr(self, "onMinimize"),
119 )
120 if isinstance(self.maximizeWidget, UIObject):
121 self.maximizeWidget.setStyleName("Maximize")
122 controls.add(self.maximizeWidget)
123 self.maximizeWidget.addClickListener(
124 getattr(self, "onMaximize"),
125 )
126 if isinstance(self.closeWidget, UIObject):
127 self.closeWidget.setStyleName("Close")
128 controls.add(self.closeWidget)
129 self.closeWidget.addClickListener(
130 getattr(self, "onClose"),
131 )
132 self.closeable = True
133 self.caption.removeStyleName(captionStyle)
134 self.panel.setWidget(0, 0, captionPanel)
135 captionPanel.setWidget(0, 0, self.caption)
136 captionPanel.setWidget(0, 1, controls)
137 captionPanel.setStyleName(captionStyle)
138 cf = captionPanel.getCellFormatter()
139 cf.setWidth(0, 1, '1%')
140
142 return self._dialogListeners
143
145 self._dialogListeners.append(listener)
146
148 self._dialogListeners.remove(listener)
149
151 cont = True
152 for listener in self._dialogListeners:
153 if hasattr(listener, action):
154 if getattr(listener, action)() is False:
155 cont = False
156 return cont
157
163
181
191
210
215
220
221 Factory.registerClass('pyjamas.ui.DialogWindow', 'DialogWindow', DialogWindow)
222