Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Check if updates are available upon startup #2273

Merged
merged 1 commit into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 81 additions & 24 deletions Orange/canvas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import gc
import re
import time
import logging
from logging.handlers import RotatingFileHandler
import optparse
Expand All @@ -19,7 +20,7 @@

from AnyQt.QtGui import QFont, QColor, QDesktopServices
from AnyQt.QtWidgets import QMessageBox
from AnyQt.QtCore import Qt, QDir, QUrl, QSettings
from AnyQt.QtCore import Qt, QDir, QUrl, QSettings, QThread, pyqtSignal

from Orange import canvas
from Orange.canvas.application.application import CanvasApplication
Expand Down Expand Up @@ -85,6 +86,82 @@ def make_sql_logger(level=logging.INFO):
sql_log.addHandler(handler)


def show_survey():
# If run for the first time, open a browser tab with a survey
settings = QSettings()
show_survey = settings.value("startup/show-survey", True, type=bool)
if show_survey:
question = QMessageBox(
QMessageBox.Question,
'Orange Survey',
'We would like to know more about how our software is used.\n\n'
'Would you care to fill our short 1-minute survey?',
QMessageBox.Yes | QMessageBox.No)
question.setDefaultButton(QMessageBox.Yes)
later = question.addButton('Ask again later', QMessageBox.NoRole)
question.setEscapeButton(later)

def handle_response(result):
if result == QMessageBox.Yes:
success = QDesktopServices.openUrl(
QUrl("https://orange.biolab.si/survey/short.html"))
settings.setValue("startup/show-survey", not success)
else:
settings.setValue("startup/show-survey", result != QMessageBox.No)

question.finished.connect(handle_response)
question.show()
return question


def check_for_updates():
settings = QSettings()
check_updates = settings.value('startup/check-updates', True, type=bool)
last_check_time = settings.value('startup/last-update-check-time', 0, type=int)
ONE_DAY = 86400

if check_updates and time.time() - last_check_time > ONE_DAY:
settings.setValue('startup/last-update-check-time', int(time.time()))

from urllib.request import urlopen
from distutils.version import LooseVersion
from Orange.version import version as current

class GetLatestVersion(QThread):
resultReady = pyqtSignal(str)

def run(self):
try:
self.resultReady.emit(
urlopen('https://orange.biolab.si/version', timeout=10).read().decode())
except OSError:
log.exception('Failed to check for updates')

def compare_versions(latest):
if LooseVersion(latest) <= LooseVersion(current):
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()

thread = GetLatestVersion()
thread.resultReady.connect(compare_versions)
thread.start()
return thread


def main(argv=None):
if argv is None:
argv = sys.argv
Expand Down Expand Up @@ -328,29 +405,9 @@ def show_message(message):
open_requests[-1])
canvas_window.load_scheme(open_requests[-1].toLocalFile())

# If run for the first time, open a browser tab with a survey
show_survey = settings.value("startup/show-survey", True, type=bool)
if show_survey:
question = QMessageBox(
QMessageBox.Question,
'Orange Survey',
'We would like to know more about how our software is used.\n\n'
'Would you care to fill our short 1-minute survey?',
QMessageBox.Yes | QMessageBox.No)
question.setDefaultButton(QMessageBox.Yes)
later = question.addButton('Ask again later', QMessageBox.NoRole)
question.setEscapeButton(later)

def handle_response(result):
if result == QMessageBox.Yes:
success = QDesktopServices.openUrl(
QUrl("http://orange.biolab.si/survey/short.html"));
settings.setValue("startup/show-survey", not success)
else:
settings.setValue("startup/show-survey", result != QMessageBox.No)

question.finished.connect(handle_response)
question.show()
# local references prevent destruction
_ = show_survey()
__ = check_for_updates()

# Tee stdout and stderr into Output dock
log_view = canvas_window.log_view()
Expand Down
7 changes: 6 additions & 1 deletion Orange/canvas/application/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,18 @@ def __setupUi(self):
objectName="show-splash-screen")

cb_welcome = QCheckBox(self.tr("Show welcome screen"), self,
objectName="show-welcome-screen")
objectName="show-welcome-screen")

cb_updates = QCheckBox(self.tr("Check for updates"), self,
objectName="check-updates")

self.bind(cb_splash, "checked", "startup/show-splash-screen")
self.bind(cb_welcome, "checked", "startup/show-welcome-screen")
self.bind(cb_updates, "checked", "startup/check-updates")

startup.layout().addWidget(cb_splash)
startup.layout().addWidget(cb_welcome)
startup.layout().addWidget(cb_updates)

form.addRow(self.tr("On startup"), startup)

Expand Down
3 changes: 3 additions & 0 deletions Orange/canvas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def init():
("startup/show-welcome-screen", bool, True,
"Show Welcome screen at startup"),

("startup/check-updates", bool, True,
"Check for updates"),

("stylesheet", str, "orange",
"QSS stylesheet to use"),

Expand Down