From 7124a970f7b3d7ff3050462e08509cc6eb957029 Mon Sep 17 00:00:00 2001 From: Rafael Irgolic Date: Wed, 12 Jun 2019 11:12:51 +0200 Subject: [PATCH] pylint --- Orange/canvas/__main__.py | 12 +++--- Orange/canvas/application/canvasmain.py | 2 +- Orange/canvas/config.py | 15 +++++--- Orange/canvas/utils/overlay.py | 46 +++++++++++++++++++---- Orange/canvas/utils/tests/test_overlay.py | 5 ++- 5 files changed, 57 insertions(+), 23 deletions(-) diff --git a/Orange/canvas/__main__.py b/Orange/canvas/__main__.py index e501ff854be..b7b11dfae94 100644 --- a/Orange/canvas/__main__.py +++ b/Orange/canvas/__main__.py @@ -20,7 +20,6 @@ import pkg_resources from AnyQt.QtGui import QFont, QColor, QPalette, QDesktopServices, QIcon -from AnyQt.QtWidgets import QMessageBox from AnyQt.QtCore import ( Qt, QDir, QUrl, QSettings, QThread, pyqtSignal, QT_VERSION ) @@ -195,7 +194,7 @@ def setup_notifications(): "Would you like to take a short survey?", standardButtons=surveyDialogButtons) - def handle_response(button): + def handle_survey_response(button): if surveyDialog.buttonRole(button) == NotificationWidget.AcceptRole: success = QDesktopServices.openUrl( QUrl("https://orange.biolab.si/survey/short.html")) @@ -203,7 +202,7 @@ def handle_response(button): elif surveyDialog.buttonRole(button) == NotificationWidget.RejectRole: settings["startup/show-short-survey"] = False - surveyDialog.clicked.connect(handle_response) + surveyDialog.clicked.connect(handle_survey_response) NotificationOverlay.registerNotification(surveyDialog) @@ -221,13 +220,13 @@ def handle_response(button): btnOK = permDialog.button(NotificationWidget.AcceptRole) btnOK.setText("Allow") - def handle_response(button): + def handle_permission_response(button): if permDialog.buttonRole(button) != permDialog.DismissRole: settings["error-reporting/permission-requested"] = True if permDialog.buttonRole(button) == permDialog.AcceptRole: settings["error-reporting/send-statistics"] = True - permDialog.clicked.connect(handle_response) + permDialog.clicked.connect(handle_permission_response) NotificationOverlay.registerNotification(permDialog) @@ -278,8 +277,6 @@ def compare_versions(latest): latest == skipped: return - from Orange.canvas.utils.overlay import NotificationWidget - questionButtons = NotificationWidget.Ok | NotificationWidget.Close question = NotificationWidget(icon=QIcon('Orange/widgets/icons/Dlg_down3.png'), title='Orange Update Available', @@ -304,6 +301,7 @@ def handle_click(b): thread.resultReady.connect(compare_versions) thread.start() return thread + return None def send_usage_statistics(): diff --git a/Orange/canvas/application/canvasmain.py b/Orange/canvas/application/canvasmain.py index 90a4e8859ee..79f09d567c2 100644 --- a/Orange/canvas/application/canvasmain.py +++ b/Orange/canvas/application/canvasmain.py @@ -59,7 +59,7 @@ def user_documents_path(): from ..gui.utils import message_critical, message_question, \ message_warning, message_information -from ..utils.overlay import NotificationWidget, NotificationOverlay +from ..utils.overlay import NotificationOverlay from ..document.usagestatistics import UsageStatistics diff --git a/Orange/canvas/config.py b/Orange/canvas/config.py index 8f8413d407e..8606bccb10e 100644 --- a/Orange/canvas/config.py +++ b/Orange/canvas/config.py @@ -117,11 +117,14 @@ def init(): ("quickmenu/trigger-on-any-key", bool, False, "Show quick menu on double click."), - ("logging/level", int, 1, "Logging level"), + ("logging/level", int, 1, + "Logging level"), - ("logging/show-on-error", bool, True, "Show log window on error"), + ("logging/show-on-error", bool, True, + "Show log window on error"), - ("logging/dockable", bool, True, "Allow log window to be docked"), + ("logging/dockable", bool, True, + "Allow log window to be docked"), ("help/open-in-external-browser", bool, False, "Open help in an external browser"), @@ -141,9 +144,11 @@ def init(): ("add-ons/pip-install-arguments", str, '', 'Arguments to pass to "pip install" when installing add-ons.'), - ("network/http-proxy", str, '', 'HTTP proxy.'), + ("network/http-proxy", str, '', + 'HTTP proxy.'), - ("network/https-proxy", str, '', 'HTTPS proxy.'), + ("network/https-proxy", str, '', + 'HTTPS proxy.'), ] spec = [config_slot(*t) for t in spec] diff --git a/Orange/canvas/utils/overlay.py b/Orange/canvas/utils/overlay.py index 11ba2ea0d8b..114e8de1c37 100644 --- a/Orange/canvas/utils/overlay.py +++ b/Orange/canvas/utils/overlay.py @@ -5,9 +5,9 @@ from collections import namedtuple from AnyQt import QtGui -from AnyQt.QtCore import Signal, Qt, QSize, QUrl -from PyQt5.QtGui import QIcon, QPixmap, QDesktopServices, QPainter -from PyQt5.QtWidgets import QAbstractButton, QHBoxLayout, QPushButton, QStyle, QWidget, \ +from AnyQt.QtCore import Signal, Qt, QSize +from AnyQt.QtGui import QIcon, QPixmap, QPainter +from AnyQt.QtWidgets import QAbstractButton, QHBoxLayout, QPushButton, QStyle, QWidget, \ QVBoxLayout, QLabel, QSizePolicy, QStyleOption from Orange.canvas.gui.stackedwidget import StackLayout @@ -186,6 +186,34 @@ def textFormat(self): """ return self._textlabel.textFormat() + def setAcceptLabel(self, label): + """ + Set the accept button label. + :type label: str + """ + self._acceptLabel = label + + def acceptLabel(self): + """ + Return the accept button label. + :rtype str + """ + return self._acceptLabel + + def setRejectLabel(self, label): + """ + Set the reject button label. + :type label: str + """ + self._rejectLabel = label + + def rejectLabel(self): + """ + Return the reject button label. + :rtype str + """ + return self._rejectLabel + def changeEvent(self, event): # reimplemented if event.type() == 177: # QEvent.MacSizeChange: @@ -222,7 +250,7 @@ def addButton(self, button, *rolearg): "addButton(QAbstractButton, role)") role = rolearg[0] elif isinstance(button, NotificationMessageWidget.StandardButton): - if len(rolearg) != 0: + if rolearg: raise TypeError("Wrong number of arguments for " "addButton(StandardButton)") stdbutton = button @@ -297,8 +325,7 @@ def button(self, standardButton): for slot in self._buttons: if slot.stdbutton == standardButton: return slot.button - else: - return None + return None def _button_clicked(self): button = self.sender() @@ -399,12 +426,15 @@ def clone(self): textFormat=self._msgwidget.textFormat(), icon=self.icon(), standardButtons=self._msgwidget.standardButtons(), - acceptLabel=self._msgwidget._acceptLabel, - rejectLabel=self._msgwidget._rejectLabel) + acceptLabel=self._msgwidget.acceptLabel(), + rejectLabel=self._msgwidget.rejectLabel()) cloned.accepted.connect(self.accepted) cloned.rejected.connect(self.rejected) cloned.dismissed.connect(self.dismissed) + # each canvas displays a clone of the original notification, + # therefore the cloned buttons' events are connected to the original's + # pylint: disable=protected-access button_map = dict(zip( [b.button for b in cloned._msgwidget._buttons] + [cloned._dismiss_button], [b.button for b in self._msgwidget._buttons] + [self._dismiss_button])) diff --git a/Orange/canvas/utils/tests/test_overlay.py b/Orange/canvas/utils/tests/test_overlay.py index e0c4f75a10e..d29046cd9cc 100644 --- a/Orange/canvas/utils/tests/test_overlay.py +++ b/Orange/canvas/utils/tests/test_overlay.py @@ -1,3 +1,5 @@ +# pylint: disable=protected-access + import unittest.mock from AnyQt.QtCore import Qt, QEvent @@ -73,7 +75,7 @@ def test_queued_notifications(self): standardButtons=surveyDialogButtons) def handle_survey_response(b): - self.assertEquals(self.notif.buttonRole(b), NotificationWidget.DismissRole) + self.assertEqual(self.notif.buttonRole(b), NotificationWidget.DismissRole) self.notif.clicked.connect(handle_survey_response) @@ -91,4 +93,3 @@ def handle_survey_response(b): self.assertFalse(notif1.isVisible()) self.assertTrue(notif2.isVisible()) -