Mercurial > libervia-web
diff src/browser/sat_browser/main_panel.py @ 844:2ef71ec07d87
browser (warning message): resuses the popup if it already exists, allows a None duration, and added INFO and WARNING types
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 15 Jan 2016 15:42:37 +0100 |
parents | 73cc4658f431 |
children | 5d9f6d25c586 |
line wrap: on
line diff
--- a/src/browser/sat_browser/main_panel.py Fri Jan 15 15:42:37 2016 +0100 +++ b/src/browser/sat_browser/main_panel.py Fri Jan 15 15:42:37 2016 +0100 @@ -54,26 +54,31 @@ def __init__(self): self._popup = None self._timer = Timer(notify=self._timeCb) + self.timeout = None + self._html = None + self._last_type = None + self._last_html = None def showWarning(self, type_=None, msg=None, duration=2000): """Display a popup information message, e.g. to notify the recipient of a message being composed. + If type_ is None, a popup being currently displayed will be hidden. @type_: a type determining the CSS style to be applied (see _showWarning) @msg: message to be displayed + @duration(int, None): time (in ms) to display the message """ if type_ is None: - self.__removeWarning() + self._removeWarning() return - if not self._popup: + + self.timeout = duration + + if not self._popup or self._last_type != type_ or self._last_html != msg: self._showWarning(type_, msg) - elif (type_, msg) != self._popup.target_data: - self._timeCb(None) # we remove the popup - self._showWarning(type_, msg) - - self._timer.schedule(duration) def _showWarning(self, type_, msg): """Display a popup information message, e.g. to notify the recipient of a message being composed. + @type_: a type determining the CSS style to be applied. For now the defined styles are "NONE" (will do nothing), "PUBLIC", "GROUP", "STATUS" and "ONE2ONE". @msg: message to be displayed @@ -91,31 +96,44 @@ style = "targetStatus" elif type_ == "ONE2ONE": style = "targetOne2One" + elif type_ == "INFO": + style = "notifInfo" + elif type_ == "WARNING": + style = "notifWarning" else: log.error("unknown message type") return - contents = HTML(msg) + + self._last_html = msg + + if self._popup is None: + self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) + self._html = HTML(msg) + self._popup.add(self._html) - self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) - self._popup.target_data = (type_, msg) - self._popup.add(contents) - self._popup.setStyleName("warningPopup") - if style: + left = 0 + top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) + self._popup.setPopupPosition(left, top) + self._popup.show() + else: + self._html.setHTML(msg) + + if type_ != self._last_type: + self._last_type = type_ + self._popup.setStyleName("warningPopup") self._popup.addStyleName(style) - left = 0 - top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) - self._popup.setPopupPosition(left, top) - self._popup.show() + if self.timeout is not None: + self._timer.schedule(self.timeout) def _timeCb(self, timer): if self._popup: self._popup.hide() - del self._popup self._popup = None - def __removeWarning(self): + def _removeWarning(self): """Remove the popup""" + self._timer.cancel() self._timeCb(None)