Mercurial > libervia-web
comparison browser_side/dialog.py @ 354:c417a7acfe44
browser_side: class PromptDialog based on GenericConfirmDialog asks the user for a text input
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 13 Feb 2014 10:30:38 +0100 |
parents | ce5b33f499c5 |
children | 2b5503392fbd |
comparison
equal
deleted
inserted
replaced
353:ddb909ab5cbc | 354:c417a7acfe44 |
---|---|
231 DialogBox.hide(self, autoClosed=True) | 231 DialogBox.hide(self, autoClosed=True) |
232 | 232 |
233 | 233 |
234 class GenericConfirmDialog(DialogBox): | 234 class GenericConfirmDialog(DialogBox): |
235 | 235 |
236 def __init__(self, widgets, callback, title='Confirmation', **kwargs): | 236 def __init__(self, widgets, callback, title='Confirmation', prompt=None, **kwargs): |
237 """ | 237 """ |
238 Dialog to confirm an action | 238 Dialog to confirm an action |
239 @param callback: method to call when contacts have been choosed | 239 @param widgets: widgets to attach |
240 @param callback: method to call when a button is clicked | |
241 @param title: title of the dialog | |
242 @param prompt: textbox from which to retrieve the string value to be passed to the callback when | |
243 OK button is pressed. If None, OK button will return "True". Cancel button always returns "False". | |
240 """ | 244 """ |
241 self.callback = callback | 245 self.callback = callback |
242 DialogBox.__init__(self, centered=True, **kwargs) | 246 DialogBox.__init__(self, centered=True, **kwargs) |
243 | 247 |
244 content = VerticalPanel() | 248 content = VerticalPanel() |
245 content.setWidth('100%') | 249 content.setWidth('100%') |
246 for wid in widgets: | 250 for wid in widgets: |
247 content.add(wid) | 251 content.add(wid) |
252 if wid == prompt: | |
253 wid.setWidth('100%') | |
248 button_panel = HorizontalPanel() | 254 button_panel = HorizontalPanel() |
249 button_panel.addStyleName("marginAuto") | 255 button_panel.addStyleName("marginAuto") |
250 self.confirm_button = Button("OK", self.onConfirm) | 256 self.confirm_button = Button("OK", self.onConfirm) |
251 button_panel.add(self.confirm_button) | 257 button_panel.add(self.confirm_button) |
252 button_panel.add(Button("Cancel", self.onCancel)) | 258 button_panel.add(Button("Cancel", self.onCancel)) |
253 content.add(button_panel) | 259 content.add(button_panel) |
254 self.setHTML(title) | 260 self.setHTML(title) |
255 self.setWidget(content) | 261 self.setWidget(content) |
262 self.prompt = prompt | |
256 | 263 |
257 def onConfirm(self, sender): | 264 def onConfirm(self, sender): |
258 self.hide() | 265 self.hide() |
259 self.callback(True) | 266 self.callback(self.prompt.getText() if self.prompt else True) |
260 | 267 |
261 def onCancel(self, sender): | 268 def onCancel(self, sender): |
262 self.hide() | 269 self.hide() |
263 self.callback(False) | 270 self.callback(False) |
271 | |
272 def show(self): | |
273 DialogBox.show(self) | |
274 if self.prompt: | |
275 self.prompt.setFocus(True) | |
264 | 276 |
265 | 277 |
266 class ConfirmDialog(GenericConfirmDialog): | 278 class ConfirmDialog(GenericConfirmDialog): |
267 | 279 |
268 def __init__(self, callback, text='Are you sure ?', title='Confirmation', **kwargs): | 280 def __init__(self, callback, text='Are you sure ?', title='Confirmation', **kwargs): |
311 | 323 |
312 def __init__(self, title, body, callback=None, options=None, **kwargs): | 324 def __init__(self, title, body, callback=None, options=None, **kwargs): |
313 GenericDialog.__init__(self, title, HTML(body), callback, options, **kwargs) | 325 GenericDialog.__init__(self, title, HTML(body), callback, options, **kwargs) |
314 | 326 |
315 | 327 |
328 class PromptDialog(GenericConfirmDialog): | |
329 | |
330 def __init__(self, callback, text='', title='User input', **kwargs): | |
331 prompt = TextBox() | |
332 prompt.setText(text) | |
333 GenericConfirmDialog.__init__(self, [prompt], callback, title, prompt, **kwargs) | |
334 | |
335 | |
316 class PopupPanelWrapper(PopupPanel): | 336 class PopupPanelWrapper(PopupPanel): |
317 """This wrapper catch Escape event to avoid request cancellation by Firefox""" | 337 """This wrapper catch Escape event to avoid request cancellation by Firefox""" |
318 | 338 |
319 def onEventPreview(self, event): | 339 def onEventPreview(self, event): |
320 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: | 340 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: |