changeset 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 ddb909ab5cbc
children 9bb78c09e9fc
files browser_side/dialog.py
diffstat 1 files changed, 23 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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"""