|
5 | 5 | from collections import namedtuple |
6 | 6 |
|
7 | 7 | from AnyQt import QtGui |
8 | | -from AnyQt.QtCore import Signal, Qt, QSize, QUrl |
9 | | -from PyQt5.QtGui import QIcon, QPixmap, QDesktopServices, QPainter |
10 | | -from PyQt5.QtWidgets import QAbstractButton, QHBoxLayout, QPushButton, QStyle, QWidget, \ |
| 8 | +from AnyQt.QtCore import Signal, Qt, QSize |
| 9 | +from AnyQt.QtGui import QIcon, QPixmap, QPainter |
| 10 | +from AnyQt.QtWidgets import QAbstractButton, QHBoxLayout, QPushButton, QStyle, QWidget, \ |
11 | 11 | QVBoxLayout, QLabel, QSizePolicy, QStyleOption |
12 | 12 |
|
13 | 13 | from Orange.canvas.gui.stackedwidget import StackLayout |
@@ -183,6 +183,34 @@ def textFormat(self): |
183 | 183 | """ |
184 | 184 | return self._textlabel.textFormat() |
185 | 185 |
|
| 186 | + def setAcceptLabel(self, label): |
| 187 | + """ |
| 188 | + Set the accept button label. |
| 189 | + :type label: str |
| 190 | + """ |
| 191 | + self._acceptLabel = label |
| 192 | + |
| 193 | + def acceptLabel(self): |
| 194 | + """ |
| 195 | + Return the accept button label. |
| 196 | + :rtype str |
| 197 | + """ |
| 198 | + return self._acceptLabel |
| 199 | + |
| 200 | + def setRejectLabel(self, label): |
| 201 | + """ |
| 202 | + Set the reject button label. |
| 203 | + :type label: str |
| 204 | + """ |
| 205 | + self._rejectLabel = label |
| 206 | + |
| 207 | + def rejectLabel(self): |
| 208 | + """ |
| 209 | + Return the reject button label. |
| 210 | + :rtype str |
| 211 | + """ |
| 212 | + return self._rejectLabel |
| 213 | + |
186 | 214 | def changeEvent(self, event): |
187 | 215 | # reimplemented |
188 | 216 | if event.type() == 177: # QEvent.MacSizeChange: |
@@ -219,7 +247,7 @@ def addButton(self, button, *rolearg): |
219 | 247 | "addButton(QAbstractButton, role)") |
220 | 248 | role = rolearg[0] |
221 | 249 | elif isinstance(button, NotificationMessageWidget.StandardButton): |
222 | | - if len(rolearg) != 0: |
| 250 | + if rolearg: |
223 | 251 | raise TypeError("Wrong number of arguments for " |
224 | 252 | "addButton(StandardButton)") |
225 | 253 | stdbutton = button |
@@ -294,8 +322,7 @@ def button(self, standardButton): |
294 | 322 | for slot in self._buttons: |
295 | 323 | if slot.stdbutton == standardButton: |
296 | 324 | return slot.button |
297 | | - else: |
298 | | - return None |
| 325 | + return None |
299 | 326 |
|
300 | 327 | def _button_clicked(self): |
301 | 328 | button = self.sender() |
@@ -390,12 +417,15 @@ def clone(self): |
390 | 417 | textFormat=self._msgwidget.textFormat(), |
391 | 418 | icon=self.icon(), |
392 | 419 | standardButtons=self._msgwidget.standardButtons(), |
393 | | - acceptLabel=self._msgwidget._acceptLabel, |
394 | | - rejectLabel=self._msgwidget._rejectLabel) |
| 420 | + acceptLabel=self._msgwidget.acceptLabel(), |
| 421 | + rejectLabel=self._msgwidget.rejectLabel()) |
395 | 422 | cloned.accepted.connect(self.accepted) |
396 | 423 | cloned.rejected.connect(self.rejected) |
397 | 424 | cloned.dismissed.connect(self.dismissed) |
398 | 425 |
|
| 426 | + # each canvas displays a clone of the original notification, |
| 427 | + # therefore the cloned buttons' events are connected to the original's |
| 428 | + # pylint: disable=protected-access |
399 | 429 | button_map = dict(zip( |
400 | 430 | [b.button for b in cloned._msgwidget._buttons] + [cloned._dismiss_button], |
401 | 431 | [b.button for b in self._msgwidget._buttons] + [self._dismiss_button])) |
|
0 commit comments