Skip to content

Commit

Permalink
pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
irgolic committed Jun 12, 2019
1 parent f123e5e commit cc8145a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 23 deletions.
12 changes: 5 additions & 7 deletions Orange/canvas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -195,15 +194,15 @@ 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"))
settings["startup/show-short-survey"] = not success
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)

Expand All @@ -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)

Expand Down Expand Up @@ -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',
Expand All @@ -304,6 +301,7 @@ def handle_click(b):
thread.resultReady.connect(compare_versions)
thread.start()
return thread
return None


def send_usage_statistics():
Expand Down
2 changes: 1 addition & 1 deletion Orange/canvas/application/canvasmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 10 additions & 5 deletions Orange/canvas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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]
Expand Down
46 changes: 38 additions & 8 deletions Orange/canvas/utils/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -183,6 +183,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:
Expand Down Expand Up @@ -219,7 +247,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
Expand Down Expand Up @@ -294,8 +322,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()
Expand Down Expand Up @@ -390,12 +417,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]))
Expand Down
5 changes: 3 additions & 2 deletions Orange/canvas/utils/tests/test_overlay.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: disable=protected-access

import unittest.mock

from AnyQt.QtCore import Qt, QEvent
Expand Down Expand Up @@ -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)

Expand All @@ -91,4 +93,3 @@ def handle_survey_response(b):

self.assertFalse(notif1.isVisible())
self.assertTrue(notif2.isVisible())

0 comments on commit cc8145a

Please sign in to comment.