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

__main__: Update Orange in-app #5064

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 34 additions & 6 deletions Orange/canvas/__main__.py
Expand Up @@ -20,25 +20,31 @@
import pickle
import shlex
import shutil
from unittest.mock import patch
import json
from urllib.request import urlopen, Request

import pkg_resources
import requests
from unittest.mock import patch

import yaml

from AnyQt.QtGui import QFont, QColor, QPalette, QDesktopServices, QIcon
from AnyQt.QtCore import (
Qt, QDir, QUrl, QSettings, QThread, pyqtSignal, QT_VERSION
)
from AnyQt.QtWidgets import QApplication
import pyqtgraph

import orangecanvas
from orangecanvas import config as canvasconfig
from orangecanvas.registry import qt, WidgetRegistry, set_global_registry, cache
from orangecanvas.application import addons
from orangecanvas.application.addons import Command
from orangecanvas.application.application import CanvasApplication
from orangecanvas.application.outputview import TextStream, ExceptHook
from orangecanvas.document.usagestatistics import UsageStatistics
from orangecanvas.gui.splashscreen import SplashScreen
from orangecanvas.utils import findf
from orangecanvas.utils.overlay import Notification, NotificationServer
from orangecanvas.main import (
fix_win_pythonw_std_stream, fix_set_proxy_env, fix_macos_nswindow_tabbing,
Expand Down Expand Up @@ -88,6 +94,30 @@ def make_stdout_handler(level, fmt=None):
return handler


def open_orange_update_menu():
if not addons.have_install_permissions():
QDesktopServices.openUrl(QUrl("https://orange.biolab.si/download/"))
return

dlg = addons.AddonManagerDialog(
windowTitle="Installer", modal=True
)
dlg.setStyle(QApplication.style())
dlg.setAttribute(Qt.WA_DeleteOnClose)
@dlg.stateChanged.connect
def _():
dlg.stateChanged.disconnect(_)

items = dlg.items()
item = findf(items, lambda i: i.normalized_name == "orange3")
if not item:
return
dlg.setItemState([(Command.Upgrade, item)])

dlg.start(canvasconfig.default)
dlg.exec_()


def check_for_updates():
settings = QSettings()
check_updates = settings.value('startup/check-updates', True, type=bool)
Expand Down Expand Up @@ -133,7 +163,7 @@ def handle_click(role):
if role == notif.RejectRole:
settings.setValue('startup/latest-skipped-version', latest)
if role == notif.AcceptRole:
QDesktopServices.openUrl(QUrl("https://orange.biolab.si/download/"))
open_orange_update_menu()

notif.clicked.connect(handle_click)
canvas.notification_server_instance.registerNotification(notif)
Expand Down Expand Up @@ -308,8 +338,6 @@ def setup_notification_feed(feed_str):
def send_usage_statistics():
def send_statistics(url):
"""Send the statistics to the remote at `url`"""
import json
import requests
settings = QSettings()
if not settings.value("reporting/send-statistics", False,
type=bool):
Expand All @@ -336,7 +364,7 @@ def send_statistics(url):
r = requests.post(url, files={'file': json.dumps(data)})
if r.status_code != 200:
log.warning("Error communicating with server while attempting to send "
"usage statistics. Status code " + str(r.status_code))
"usage statistics. Status code %d" % r.status_code)
return
# success - wipe statistics file
log.info("Usage statistics sent.")
Expand Down