# HG changeset patch # User souliane # Date 1381232322 -7200 # Node ID fab7aa3665764a762d4e44dab6b0bba0f187029b # Parent 266e9678eec0626abb201916b15f7715192787b3 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... diff -r 266e9678eec0 -r fab7aa366576 browser_side/dialog.py --- 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""" diff -r 266e9678eec0 -r fab7aa366576 browser_side/panels.py --- 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"):