Skip to content

Commit

Permalink
__main__: Reimplement update prompt as notification
Browse files Browse the repository at this point in the history
  • Loading branch information
irgolic committed Jun 11, 2019
1 parent dd28eaa commit 6ca8c16
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
41 changes: 25 additions & 16 deletions Orange/canvas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,32 @@ def ua_string():

def compare_versions(latest):
version = pkg_resources.parse_version
if version(latest) <= version(current):
skipped = settings.value('startup/latest-skipped-version', "", type=str)
if version(latest) <= version(current) or \
latest == skipped:
return
question = QMessageBox(
QMessageBox.Information,
'Orange Update Available',
'A newer version of Orange is available.<br><br>'
'<b>Current version:</b> {}<br>'
'<b>Latest version:</b> {}'.format(current, latest),
textFormat=Qt.RichText)
ok = question.addButton('Download Now', question.AcceptRole)
question.setDefaultButton(ok)
question.addButton('Remind Later', question.RejectRole)
question.finished.connect(
lambda:
question.clickedButton() == ok and
QDesktopServices.openUrl(QUrl("https://orange.biolab.si/download/")))
question.show()

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',
text='Current version: <b>{}</b><br>'
'Latest version: <b>{}</b>'.format(current, latest),
standardButtons=questionButtons,
acceptLabel="Download",
rejectLabel="Skip this Version")
question.setTextFormat(Qt.RichText)

def handle_click(b):
if question.buttonRole(b) != question.DismissRole:
settings.setValue('startup/latest-skipped-version', latest)
if question.buttonRole(b) == question.AcceptRole:
QDesktopServices.openUrl(QUrl("https://orange.biolab.si/download/"))

question.clicked.connect(handle_click)

NotificationOverlay.registerNotification(question)

thread = GetLatestVersion()
thread.resultReady.connect(compare_versions)
Expand Down
3 changes: 2 additions & 1 deletion Orange/canvas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def init():
("startup/check-updates", bool, True,
"Check for updates"),

("startup/launch-count", int, 0, ""),
("startup/launch-count", int, 0,
""),

("startup/show-short-survey", bool, True,
"Has the user not been asked to take a short survey yet"),
Expand Down
3 changes: 1 addition & 2 deletions Orange/canvas/utils/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ButtonRole(enum.IntEnum):
_Button = namedtuple("_Button", ["button", "role", "stdbutton"])

def __init__(self, parent=None, icon=QIcon(), title="", text="", wordWrap=False,
textFormat=Qt.AutoText, standardButtons=NoButton, acceptLabel="Ok",
textFormat=Qt.PlainText, standardButtons=NoButton, acceptLabel="Ok",
rejectLabel="No", **kwargs):
super().__init__(parent, **kwargs)
self._title = title
Expand All @@ -53,7 +53,6 @@ def __init__(self, parent=None, icon=QIcon(), title="", text="", wordWrap=False,
wordWrap=wordWrap, textFormat=textFormat)
self._textlabel = QLabel(objectName="text-label", text=text,
wordWrap=wordWrap, textFormat=textFormat)
self._textlabel.setTextFormat(Qt.RichText)
self._textlabel.setTextInteractionFlags(Qt.TextBrowserInteraction)
self._textlabel.setOpenExternalLinks(True)

Expand Down

0 comments on commit 6ca8c16

Please sign in to comment.