diff src/browser/sat_browser/dialog.py @ 625:ed9cd20260ff frontends_multi_profiles

browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
author souliane <souliane@mailoo.org>
date Sun, 22 Feb 2015 21:55:27 +0100
parents d41e850b31b9
children ba2555c29c84
line wrap: on
line diff
--- a/src/browser/sat_browser/dialog.py	Sun Feb 22 21:51:20 2015 +0100
+++ b/src/browser/sat_browser/dialog.py	Sun Feb 22 21:55:27 2015 +0100
@@ -245,13 +245,16 @@
 
 class GenericConfirmDialog(DialogBox):
 
-    def __init__(self, widgets, callback, title='Confirmation', prompt=None, **kwargs):
+    def __init__(self, widgets, callback, title='Confirmation', prompt_widgets=None, **kwargs):
         """
         Dialog to confirm an action
         @param widgets (list[Widget]): widgets to attach
-        @param callback: method to call when a button is clicked
+        @param callback (callable): method to call when a button is pressed,
+            with the following arguments:
+                - result (bool): set to True if the dialog has been confirmed
+                - *args: a list of unicode (the values for the prompt_widgets)
         @param title: title of the dialog
-        @param prompt (TextBox, list[TextBox]): input widgets from which to retrieve
+        @param prompt_widgets (list[TextBox]): input widgets from which to retrieve
         the string value(s) to be passed to the callback when OK button is pressed.
         If None, OK button will return "True". Cancel button always returns "False".
         """
@@ -261,16 +264,14 @@
         if added_style:
             self.addStyleName(added_style)
 
-        if prompt is None:
-            prompt = []
-        elif isinstance(prompt, TextBox):
-            prompt = [prompt]
+        if prompt_widgets is None:
+            prompt_widgets = []
 
         content = VerticalPanel()
         content.setWidth('100%')
         for wid in widgets:
             content.add(wid)
-            if wid in prompt:
+            if wid in prompt_widgets:
                 wid.setWidth('100%')
         button_panel = HorizontalPanel()
         button_panel.addStyleName("marginAuto")
@@ -281,11 +282,12 @@
         content.add(button_panel)
         self.setHTML(title)
         self.setWidget(content)
-        self.prompt = prompt
+        self.prompt_widgets = prompt_widgets
 
     def onConfirm(self, sender):
         self.hide()
-        result = [box.getText() for box in self.prompt] if self.prompt else [True]
+        result = [True]
+        result.extend([box.getText() for box in self.prompt_widgets])
         self.callback(*result)
 
     def onCancel(self, sender):
@@ -294,8 +296,8 @@
 
     def show(self):
         DialogBox.show(self)
-        if self.prompt:
-            self.prompt[0].setFocus(True)
+        if self.prompt_widgets:
+            self.prompt_widgets[0].setFocus(True)
 
 
 class ConfirmDialog(GenericConfirmDialog):
@@ -328,7 +330,7 @@
         _body.add(main_widget)
         _body.setCellWidth(main_widget, '100%')
         _body.setCellHeight(main_widget, '100%')
-        if not 'NO_CLOSE' in options:
+        if 'NO_CLOSE' not in options:
             _close_button = Button("Close", self.onClose)
             _body.add(_close_button)
             _body.setCellHorizontalAlignment(_close_button, HasAlignment.ALIGN_CENTER)
@@ -357,19 +359,18 @@
     def __init__(self, callback, textes=None, values=None, title='User input', **kwargs):
         """Prompt the user for one or more input(s).
 
-        @param callback (callable): method to call when clicking OK
-        @param textes (str, list[str]): HTML textes to display before the inputs
-        @param values (str, list[str]): default values for each input
-        @param title (str): dialog title
+        @param callback (callable): method to call when a button is pressed,
+            with the following arguments:
+                - result (bool): set to True if the dialog has been confirmed
+                - *args: a list of unicode (the values entered by the user)
+        @param textes (list[unicode]): HTML textes to display before the inputs
+        @param values (list[unicode]): default values for each input
+        @param title (unicode): dialog title
         """
         if textes is None:
             textes = ['']  # display a single input without any description
-        elif not isinstance(textes, list):
-            textes = [textes]  # allow to pass a single string instead of a list
         if values is None:
             values = []
-        elif not isinstance(values, list):
-            values = [values]  # allow to pass a single string instead of a list
         all_widgets = []
         prompt_widgets = []
         for count in xrange(len(textes)):
@@ -388,7 +389,7 @@
 
     def onEventPreview(self, event):
         if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE:
-            #needed to prevent request cancellation in Firefox
+            # needed to prevent request cancellation in Firefox
             event.preventDefault()
         return PopupPanel.onEventPreview(self, event)