Skip to content

Commit 6f7b171

Browse files
committed
__main__: Reimplement update prompt as notification
1 parent e599235 commit 6f7b171

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

Orange/canvas/__main__.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -273,23 +273,32 @@ def ua_string():
273273

274274
def compare_versions(latest):
275275
version = pkg_resources.parse_version
276-
if version(latest) <= version(current):
276+
skipped = settings.value('startup/latest-skipped-version', "", type=str)
277+
if version(latest) <= version(current) or \
278+
latest == skipped:
277279
return
278-
question = QMessageBox(
279-
QMessageBox.Information,
280-
'Orange Update Available',
281-
'A newer version of Orange is available.<br><br>'
282-
'<b>Current version:</b> {}<br>'
283-
'<b>Latest version:</b> {}'.format(current, latest),
284-
textFormat=Qt.RichText)
285-
ok = question.addButton('Download Now', question.AcceptRole)
286-
question.setDefaultButton(ok)
287-
question.addButton('Remind Later', question.RejectRole)
288-
question.finished.connect(
289-
lambda:
290-
question.clickedButton() == ok and
291-
QDesktopServices.openUrl(QUrl("https://orange.biolab.si/download/")))
292-
question.show()
280+
281+
from Orange.canvas.utils.overlay import NotificationWidget
282+
283+
questionButtons = NotificationWidget.Ok | NotificationWidget.Close
284+
question = NotificationWidget(icon=QIcon('Orange/widgets/icons/Dlg_down3.png'),
285+
title='Orange Update Available',
286+
text='Current version: <b>{}</b><br>'
287+
'Latest version: <b>{}</b>'.format(current, latest),
288+
standardButtons=questionButtons,
289+
acceptLabel="Download",
290+
rejectLabel="Skip this Version")
291+
question.setTextFormat(Qt.RichText)
292+
293+
def handle_click(b):
294+
if question.buttonRole(b) != question.DismissRole:
295+
settings.setValue('startup/latest-skipped-version', latest)
296+
if question.buttonRole(b) == question.AcceptRole:
297+
QDesktopServices.openUrl(QUrl("https://orange.biolab.si/download/"))
298+
299+
question.clicked.connect(handle_click)
300+
301+
NotificationOverlay.registerNotification(question)
293302

294303
thread = GetLatestVersion()
295304
thread.resultReady.connect(compare_versions)

Orange/canvas/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def init():
5656
("startup/check-updates", bool, True,
5757
"Check for updates"),
5858

59-
("startup/launch-count", int, 0, ""),
59+
("startup/launch-count", int, 0,
60+
""),
6061

6162
("startup/show-short-survey", bool, True,
6263
"Has the user not been asked to take a short survey yet"),

Orange/canvas/utils/overlay.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ButtonRole(enum.IntEnum):
3636
_Button = namedtuple("_Button", ["button", "role", "stdbutton"])
3737

3838
def __init__(self, parent=None, icon=QIcon(), title="", text="", wordWrap=False,
39-
textFormat=Qt.AutoText, standardButtons=NoButton, acceptLabel="Ok",
39+
textFormat=Qt.PlainText, standardButtons=NoButton, acceptLabel="Ok",
4040
rejectLabel="No", **kwargs):
4141
super().__init__(parent, **kwargs)
4242
self._title = title
@@ -53,7 +53,6 @@ def __init__(self, parent=None, icon=QIcon(), title="", text="", wordWrap=False,
5353
wordWrap=wordWrap, textFormat=textFormat)
5454
self._textlabel = QLabel(objectName="text-label", text=text,
5555
wordWrap=wordWrap, textFormat=textFormat)
56-
self._textlabel.setTextFormat(Qt.RichText)
5756
self._textlabel.setTextInteractionFlags(Qt.TextBrowserInteraction)
5857
self._textlabel.setOpenExternalLinks(True)
5958

0 commit comments

Comments
 (0)