|
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 |
@@ -186,6 +186,34 @@ def textFormat(self): |
186 | 186 | """ |
187 | 187 | return self._textlabel.textFormat() |
188 | 188 |
|
| 189 | + def setAcceptLabel(self, label): |
| 190 | + """ |
| 191 | + Set the accept button label. |
| 192 | + :type label: str |
| 193 | + """ |
| 194 | + self._acceptLabel = label |
| 195 | + |
| 196 | + def acceptLabel(self): |
| 197 | + """ |
| 198 | + Return the accept button label. |
| 199 | + :rtype str |
| 200 | + """ |
| 201 | + return self._acceptLabel |
| 202 | + |
| 203 | + def setRejectLabel(self, label): |
| 204 | + """ |
| 205 | + Set the reject button label. |
| 206 | + :type label: str |
| 207 | + """ |
| 208 | + self._rejectLabel = label |
| 209 | + |
| 210 | + def rejectLabel(self): |
| 211 | + """ |
| 212 | + Return the reject button label. |
| 213 | + :rtype str |
| 214 | + """ |
| 215 | + return self._rejectLabel |
| 216 | + |
189 | 217 | def changeEvent(self, event): |
190 | 218 | # reimplemented |
191 | 219 | if event.type() == 177: # QEvent.MacSizeChange: |
@@ -222,7 +250,7 @@ def addButton(self, button, *rolearg): |
222 | 250 | "addButton(QAbstractButton, role)") |
223 | 251 | role = rolearg[0] |
224 | 252 | elif isinstance(button, NotificationMessageWidget.StandardButton): |
225 | | - if len(rolearg) != 0: |
| 253 | + if rolearg: |
226 | 254 | raise TypeError("Wrong number of arguments for " |
227 | 255 | "addButton(StandardButton)") |
228 | 256 | stdbutton = button |
@@ -297,8 +325,7 @@ def button(self, standardButton): |
297 | 325 | for slot in self._buttons: |
298 | 326 | if slot.stdbutton == standardButton: |
299 | 327 | return slot.button |
300 | | - else: |
301 | | - return None |
| 328 | + return None |
302 | 329 |
|
303 | 330 | def _button_clicked(self): |
304 | 331 | button = self.sender() |
@@ -399,12 +426,15 @@ def clone(self): |
399 | 426 | textFormat=self._msgwidget.textFormat(), |
400 | 427 | icon=self.icon(), |
401 | 428 | standardButtons=self._msgwidget.standardButtons(), |
402 | | - acceptLabel=self._msgwidget._acceptLabel, |
403 | | - rejectLabel=self._msgwidget._rejectLabel) |
| 429 | + acceptLabel=self._msgwidget.acceptLabel(), |
| 430 | + rejectLabel=self._msgwidget.rejectLabel()) |
404 | 431 | cloned.accepted.connect(self.accepted) |
405 | 432 | cloned.rejected.connect(self.rejected) |
406 | 433 | cloned.dismissed.connect(self.dismissed) |
407 | 434 |
|
| 435 | + # each canvas displays a clone of the original notification, |
| 436 | + # therefore the cloned buttons' events are connected to the original's |
| 437 | + # pylint: disable=protected-access |
408 | 438 | button_map = dict(zip( |
409 | 439 | [b.button for b in cloned._msgwidget._buttons] + [cloned._dismiss_button], |
410 | 440 | [b.button for b in self._msgwidget._buttons] + [self._dismiss_button])) |
|
0 commit comments