Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
843:83a40d786e7a | 844:2ef71ec07d87 |
---|---|
52 class WarningPopup(): | 52 class WarningPopup(): |
53 | 53 |
54 def __init__(self): | 54 def __init__(self): |
55 self._popup = None | 55 self._popup = None |
56 self._timer = Timer(notify=self._timeCb) | 56 self._timer = Timer(notify=self._timeCb) |
57 self.timeout = None | |
58 self._html = None | |
59 self._last_type = None | |
60 self._last_html = None | |
57 | 61 |
58 def showWarning(self, type_=None, msg=None, duration=2000): | 62 def showWarning(self, type_=None, msg=None, duration=2000): |
59 """Display a popup information message, e.g. to notify the recipient of a message being composed. | 63 """Display a popup information message, e.g. to notify the recipient of a message being composed. |
64 | |
60 If type_ is None, a popup being currently displayed will be hidden. | 65 If type_ is None, a popup being currently displayed will be hidden. |
61 @type_: a type determining the CSS style to be applied (see _showWarning) | 66 @type_: a type determining the CSS style to be applied (see _showWarning) |
62 @msg: message to be displayed | 67 @msg: message to be displayed |
68 @duration(int, None): time (in ms) to display the message | |
63 """ | 69 """ |
64 if type_ is None: | 70 if type_ is None: |
65 self.__removeWarning() | 71 self._removeWarning() |
66 return | 72 return |
67 if not self._popup: | 73 |
74 self.timeout = duration | |
75 | |
76 if not self._popup or self._last_type != type_ or self._last_html != msg: | |
68 self._showWarning(type_, msg) | 77 self._showWarning(type_, msg) |
69 elif (type_, msg) != self._popup.target_data: | |
70 self._timeCb(None) # we remove the popup | |
71 self._showWarning(type_, msg) | |
72 | |
73 self._timer.schedule(duration) | |
74 | 78 |
75 def _showWarning(self, type_, msg): | 79 def _showWarning(self, type_, msg): |
76 """Display a popup information message, e.g. to notify the recipient of a message being composed. | 80 """Display a popup information message, e.g. to notify the recipient of a message being composed. |
81 | |
77 @type_: a type determining the CSS style to be applied. For now the defined styles are | 82 @type_: a type determining the CSS style to be applied. For now the defined styles are |
78 "NONE" (will do nothing), "PUBLIC", "GROUP", "STATUS" and "ONE2ONE". | 83 "NONE" (will do nothing), "PUBLIC", "GROUP", "STATUS" and "ONE2ONE". |
79 @msg: message to be displayed | 84 @msg: message to be displayed |
80 """ | 85 """ |
81 if type_ == "NONE": | 86 if type_ == "NONE": |
89 style = "targetGroup" | 94 style = "targetGroup" |
90 elif type_ == "STATUS": | 95 elif type_ == "STATUS": |
91 style = "targetStatus" | 96 style = "targetStatus" |
92 elif type_ == "ONE2ONE": | 97 elif type_ == "ONE2ONE": |
93 style = "targetOne2One" | 98 style = "targetOne2One" |
99 elif type_ == "INFO": | |
100 style = "notifInfo" | |
101 elif type_ == "WARNING": | |
102 style = "notifWarning" | |
94 else: | 103 else: |
95 log.error("unknown message type") | 104 log.error("unknown message type") |
96 return | 105 return |
97 contents = HTML(msg) | 106 |
98 | 107 self._last_html = msg |
99 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) | 108 |
100 self._popup.target_data = (type_, msg) | 109 if self._popup is None: |
101 self._popup.add(contents) | 110 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
102 self._popup.setStyleName("warningPopup") | 111 self._html = HTML(msg) |
103 if style: | 112 self._popup.add(self._html) |
113 | |
114 left = 0 | |
115 top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) | |
116 self._popup.setPopupPosition(left, top) | |
117 self._popup.show() | |
118 else: | |
119 self._html.setHTML(msg) | |
120 | |
121 if type_ != self._last_type: | |
122 self._last_type = type_ | |
123 self._popup.setStyleName("warningPopup") | |
104 self._popup.addStyleName(style) | 124 self._popup.addStyleName(style) |
105 | 125 |
106 left = 0 | 126 if self.timeout is not None: |
107 top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) | 127 self._timer.schedule(self.timeout) |
108 self._popup.setPopupPosition(left, top) | |
109 self._popup.show() | |
110 | 128 |
111 def _timeCb(self, timer): | 129 def _timeCb(self, timer): |
112 if self._popup: | 130 if self._popup: |
113 self._popup.hide() | 131 self._popup.hide() |
114 del self._popup | |
115 self._popup = None | 132 self._popup = None |
116 | 133 |
117 def __removeWarning(self): | 134 def _removeWarning(self): |
118 """Remove the popup""" | 135 """Remove the popup""" |
136 self._timer.cancel() | |
119 self._timeCb(None) | 137 self._timeCb(None) |
120 | 138 |
121 | 139 |
122 ### Status ### | 140 ### Status ### |
123 | 141 |