# HG changeset patch # User souliane # Date 1392283838 -3600 # Node ID c417a7acfe44404564a941c0d8470404b0ac6f27 # Parent ddb909ab5cbcce16f914c3dbdf7a4c54cf12ab8d browser_side: class PromptDialog based on GenericConfirmDialog asks the user for a text input diff -r ddb909ab5cbc -r c417a7acfe44 browser_side/dialog.py --- a/browser_side/dialog.py Thu Feb 13 01:33:24 2014 +0100 +++ b/browser_side/dialog.py Thu Feb 13 10:30:38 2014 +0100 @@ -233,10 +233,14 @@ class GenericConfirmDialog(DialogBox): - def __init__(self, widgets, callback, title='Confirmation', **kwargs): + def __init__(self, widgets, callback, title='Confirmation', prompt=None, **kwargs): """ Dialog to confirm an action - @param callback: method to call when contacts have been choosed + @param widgets: widgets to attach + @param callback: method to call when a button is clicked + @param title: title of the dialog + @param prompt: textbox from which to retrieve the string value to be passed to the callback when + OK button is pressed. If None, OK button will return "True". Cancel button always returns "False". """ self.callback = callback DialogBox.__init__(self, centered=True, **kwargs) @@ -245,6 +249,8 @@ content.setWidth('100%') for wid in widgets: content.add(wid) + if wid == prompt: + wid.setWidth('100%') button_panel = HorizontalPanel() button_panel.addStyleName("marginAuto") self.confirm_button = Button("OK", self.onConfirm) @@ -253,15 +259,21 @@ content.add(button_panel) self.setHTML(title) self.setWidget(content) + self.prompt = prompt def onConfirm(self, sender): self.hide() - self.callback(True) + self.callback(self.prompt.getText() if self.prompt else True) def onCancel(self, sender): self.hide() self.callback(False) + def show(self): + DialogBox.show(self) + if self.prompt: + self.prompt.setFocus(True) + class ConfirmDialog(GenericConfirmDialog): @@ -313,6 +325,14 @@ GenericDialog.__init__(self, title, HTML(body), callback, options, **kwargs) +class PromptDialog(GenericConfirmDialog): + + def __init__(self, callback, text='', title='User input', **kwargs): + prompt = TextBox() + prompt.setText(text) + GenericConfirmDialog.__init__(self, [prompt], callback, title, prompt, **kwargs) + + class PopupPanelWrapper(PopupPanel): """This wrapper catch Escape event to avoid request cancellation by Firefox"""