Mercurial > libervia-web
comparison browser_side/dialog.py @ 145:c0035e5e2d08
browser side: misc dialog improvment:
- size fix
- new "options" parameter, NO_CLOSE option to show a dialog without close button
- new close method to simulate close button click
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 09 Dec 2012 23:34:20 +0100 |
parents | ddfcc4cb6cee |
children | 9763dec220ed |
comparison
equal
deleted
inserted
replaced
144:88512fbeb128 | 145:c0035e5e2d08 |
---|---|
127 GenericConfirmDialog.__init__(self,[HTML(text)], callback, title) | 127 GenericConfirmDialog.__init__(self,[HTML(text)], callback, title) |
128 | 128 |
129 class GenericDialog(DialogBox): | 129 class GenericDialog(DialogBox): |
130 """Dialog which just show a widget and a close button""" | 130 """Dialog which just show a widget and a close button""" |
131 | 131 |
132 def __init__(self, title, widget, callback = None): | 132 def __init__(self, title, main_widget, callback = None, options = None): |
133 """Simple notice dialog box | 133 """Simple notice dialog box |
134 @param title: HTML put in the header | 134 @param title: HTML put in the header |
135 @param body: widget put in the body""" | 135 @param main_widget: widget put in the body |
136 @param callback: method to call on closing | |
137 @param options: one or more of the following options: | |
138 - NO_CLOSE: don't add a close button""" | |
136 DialogBox.__init__(self, centered=True) | 139 DialogBox.__init__(self, centered=True) |
137 self.callback = callback | 140 self.callback = callback |
141 if not options: | |
142 options = [] | |
138 _body = VerticalPanel() | 143 _body = VerticalPanel() |
139 _body.setSize('100%','100%') | 144 _body.setSize('100%','100%') |
140 _body.setSpacing(4) | 145 _body.setSpacing(4) |
141 _body.add(widget) | 146 _body.add(main_widget) |
142 _body.setCellWidth(widget, '100%') | 147 _body.setCellWidth(main_widget, '100%') |
143 _close_button = Button("Close", self.onClose) | 148 _body.setCellHeight(main_widget, '100%') |
144 _body.add(_close_button) | 149 if not 'NO_CLOSE' in options: |
145 _body.setCellHorizontalAlignment(_close_button, HasAlignment.ALIGN_CENTER) | 150 _close_button = Button("Close", self.onClose) |
151 _body.add(_close_button) | |
152 _body.setCellHorizontalAlignment(_close_button, HasAlignment.ALIGN_CENTER) | |
146 self.setHTML(title) | 153 self.setHTML(title) |
147 self.setWidget(_body) | 154 self.setWidget(_body) |
148 if isinstance(widget, Frame): | 155 self.panel.setSize('100%', '100%') #Need this hack to have correct size in Gecko & Webkit |
149 #Need this hack to have correct size for About box + Social Contract | 156 |
150 #in Gecko & Webkit | 157 def close(self): |
151 self.panel.setWidth('100%') | 158 """Same effect as clicking the close button""" |
159 self.onClose(None) | |
152 | 160 |
153 def onClose(self, sender): | 161 def onClose(self, sender): |
154 self.hide() | 162 self.hide() |
155 if self.callback: | 163 if self.callback: |
156 self.callback() | 164 self.callback() |
157 | 165 |
158 class InfoDialog(GenericDialog): | 166 class InfoDialog(GenericDialog): |
159 | 167 |
160 def __init__(self, title, body, callback = None): | 168 def __init__(self, title, body, callback = None, options = None): |
161 GenericDialog.__init__(self, title, HTML(body), callback) | 169 GenericDialog.__init__(self, title, HTML(body), callback, options) |
162 | 170 |
163 class PopupPanelWrapper(PopupPanel): | 171 class PopupPanelWrapper(PopupPanel): |
164 """This wrapper catch Escape event to avoid request cancellation by Firefox""" | 172 """This wrapper catch Escape event to avoid request cancellation by Firefox""" |
165 | 173 |
166 def onEventPreview(self, event): | 174 def onEventPreview(self, event): |