changeset 231:fab7aa366576

browser_side: dialogs take **kwargs arguments + unibox helper method - add the **kwargs arguments to the dialog classes, especially to pass the Width='xxx' setting - add a method getTargetAndData to UniBox, for external use and to get the message recipient and body without dealing with the target hooks, selected panels...
author souliane <souliane@mailoo.org>
date Tue, 08 Oct 2013 13:38:42 +0200
parents 266e9678eec0
children 0ed09cc0566f
files browser_side/dialog.py browser_side/panels.py
diffstat 2 files changed, 35 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/dialog.py	Tue Oct 08 13:57:35 2013 +0200
+++ b/browser_side/dialog.py	Tue Oct 08 13:38:42 2013 +0200
@@ -95,15 +95,16 @@
     def onCancel(self, sender):
         self.hide()
 
+
 class GenericConfirmDialog(DialogBox):
 
-    def __init__(self, widgets, callback, title='Confirmation'):
+    def __init__(self, widgets, callback, title='Confirmation', **kwargs):
         """
         Dialog to confirm an action
         @param callback: method to call when contacts have been choosed
         """
         self.callback = callback
-        DialogBox.__init__(self, centered=True)
+        DialogBox.__init__(self, centered=True, **kwargs)
 
         content = VerticalPanel()
         content.setWidth('100%')
@@ -129,21 +130,21 @@
 
 class ConfirmDialog(GenericConfirmDialog):
 
-    def __init__(self, callback, text='Are you sure ?', title='Confirmation'):
-        GenericConfirmDialog.__init__(self, [HTML(text)], callback, title)
+    def __init__(self, callback, text='Are you sure ?', title='Confirmation', **kwargs):
+        GenericConfirmDialog.__init__(self, [HTML(text)], callback, title, **kwargs)
 
 
 class GenericDialog(DialogBox):
     """Dialog which just show a widget and a close button"""
 
-    def __init__(self, title, main_widget, callback=None, options=None):
+    def __init__(self, title, main_widget, callback=None, options=None, **kwargs):
         """Simple notice dialog box
         @param title: HTML put in the header
         @param main_widget: widget put in the body
         @param callback: method to call on closing
         @param options: one or more of the following options:
                         - NO_CLOSE: don't add a close button"""
-        DialogBox.__init__(self, centered=True)
+        DialogBox.__init__(self, centered=True, **kwargs)
         self.callback = callback
         if not options:
             options = []
@@ -170,10 +171,12 @@
         if self.callback:
             self.callback()
 
+
 class InfoDialog(GenericDialog):
 
-    def __init__(self, title, body, callback = None, options = None):
-        GenericDialog.__init__(self, title, HTML(body), callback, options)
+    def __init__(self, title, body, callback=None, options=None, **kwargs):
+        GenericDialog.__init__(self, title, HTML(body), callback, options, **kwargs)
+
 
 class PopupPanelWrapper(PopupPanel):
     """This wrapper catch Escape event to avoid request cancellation by Firefox"""
@@ -184,6 +187,7 @@
             event.preventDefault()
         return PopupPanel.onEventPreview(self, event)
 
+
 class ExtTextBox(TextBox):
     """Extended TextBox"""
 
--- a/browser_side/panels.py	Tue Oct 08 13:57:35 2013 +0200
+++ b/browser_side/panels.py	Tue Oct 08 13:38:42 2013 +0200
@@ -210,6 +210,29 @@
         else:
             self.__onComposing()
 
+    def getTargetAndData(self):
+        """For external use, to get information about the (hypothetical) message
+        that would be sent if we press Enter right now in the unibox.
+        @return a tuple (target, data) with:
+          - data: what would be the content of the message (body)
+          - target: JID, group with the prefix "@" or the public entity "@@"
+        """
+        _txt = self.getText()
+        target_hook, _type, _msg = self._getTarget(_txt)
+        if target_hook:
+            data, target = target_hook
+            if target is None:
+                return target_hook
+            return (data, "@%s" % (target if target != "" else "@"))
+        if isinstance(self._selected_cache, MicroblogPanel):
+            groups = self._selected_cache.accepted_groups
+            target = "@%s" % (groups[0] if len(groups) > 0 else "@")
+            if len(groups) > 1:
+                Window.alert("Sole the first group of the selected panel is taken in consideration: '%s'" % groups[0])
+        elif isinstance(self._selected_cache, ChatPanel):
+            target = self._selected_cache.target
+        return (_txt, target)
+
     def __onComposing(self):
         """Callback when the user is composing a text."""
         if hasattr(self._selected_cache, "target"):