From 4588a61185291a9b807bdac84ba2d8c3bf406495 Mon Sep 17 00:00:00 2001 From: daid303 Date: Thu, 10 Jan 2013 14:19:48 +0100 Subject: [PATCH] Add feature which checks for newer releases on startup. --- Cura/gui/app.py | 13 ++++++++++--- Cura/gui/preferencesDialog.py | 3 +++ Cura/util/profile.py | 3 ++- Cura/util/settings.py | 6 ++++++ Cura/util/version.py | 29 ++++++++++++++++++++++++++++- 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 Cura/util/settings.py diff --git a/Cura/gui/app.py b/Cura/gui/app.py index 6372d723..c1618de7 100644 --- a/Cura/gui/app.py +++ b/Cura/gui/app.py @@ -10,9 +10,6 @@ import warnings #Only import the _core to save import time import wx._core -from Cura.util import profile -from Cura.util import resources - class CuraApp(wx.App): def __init__(self): if platform.system() == "Windows" and not 'PYCHARM_HOSTED' in os.environ: @@ -38,8 +35,12 @@ class CuraApp(wx.App): def afterSplashCallback(self): #These imports take most of the time and thus should be done after showing the splashscreen + import webbrowser from Cura.gui import mainWindow from Cura.gui import configWizard + from Cura.util import profile + from Cura.util import resources + from Cura.util import version #If we haven't run it before, run the configuration wizard. if profile.getPreference('machine_type') == 'unknown': @@ -59,6 +60,12 @@ class CuraApp(wx.App): #Hide the splashscreen before showing the main window. if self.splash is not None: self.splash.Show(False) + if profile.getPreference('check_for_updates') == 'True': + newVersion = version.checkForNewerVersion() + if newVersion is not None: + if wx.MessageBox('A new version of Cura is available, would you like to download?', 'New version available', wx.YES_NO | wx.ICON_INFORMATION) == wx.YES: + webbrowser.open(newVersion) + return self.mainWindow = mainWindow.mainWindow() setFullScreenCapable(self.mainWindow) diff --git a/Cura/gui/preferencesDialog.py b/Cura/gui/preferencesDialog.py index b583bc4e..55e73ccc 100644 --- a/Cura/gui/preferencesDialog.py +++ b/Cura/gui/preferencesDialog.py @@ -66,6 +66,9 @@ class preferencesDialog(wx.Frame): c = configBase.SettingRow(right, 'SD card path', 'sdpath', '', 'Location of your SD card, when using the copy to SD feature.', type = 'preference') c = configBase.SettingRow(right, 'Copy to SD with 8.3 names', 'sdshortnames', False, 'Save the gcode files in short filenames, so they are properly shown on the UltiController', type = 'preference') + configBase.TitleRow(right, 'Cura settings') + c = configBase.SettingRow(right, 'Check for updates', 'check_for_updates', True, 'Check for newer versions of Cura on startup', type = 'preference') + self.okButton = wx.Button(right, -1, 'Ok') right.GetSizer().Add(self.okButton, (right.GetSizer().GetRows(), 0), flag=wx.BOTTOM, border=5) self.okButton.Bind(wx.EVT_BUTTON, self.OnClose) diff --git a/Cura/util/profile.py b/Cura/util/profile.py index d8f0f27e..48453d9f 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -174,7 +174,8 @@ preferencesDefaultSettings = { 'filament_cost_kg': '0', 'filament_cost_meter': '0', 'sdpath': '', - 'sdshortnames': 'True', + 'sdshortnames': 'False', + 'check_for_updates': 'True', 'planner_always_autoplace': 'True', 'extruder_head_size_min_x': '75.0', diff --git a/Cura/util/settings.py b/Cura/util/settings.py new file mode 100644 index 00000000..9e81310d --- /dev/null +++ b/Cura/util/settings.py @@ -0,0 +1,6 @@ + +class setting(object): + def __init__(self, key, name, description): + self._key = key + self._name = name + self._description = description diff --git a/Cura/util/version.py b/Cura/util/version.py index 93117f7c..8ffceb4e 100644 --- a/Cura/util/version.py +++ b/Cura/util/version.py @@ -2,6 +2,10 @@ from __future__ import absolute_import import os import sys +import urllib2 +import platform +from xml.etree import ElementTree + from Cura.util import resources def getVersion(getGitVersion = True): @@ -28,6 +32,29 @@ def isDevVersion(): gitPath = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], "../../.git")) return os.path.exists(gitPath) +def checkForNewerVersion(): + if isDevVersion(): + return None + try: + updateBaseURL = 'http://software.ultimaker.com' + localVersion = map(int, getVersion(False).split('.')) + while len(localVersion) < 3: + localVersion += [1] + latestFile = urllib2.urlopen("%s/latest.xml" % (updateBaseURL)) + latestXml = latestFile.read() + latestFile.close() + xmlTree = ElementTree.fromstring(latestXml) + for release in xmlTree.iter('release'): + os = str(release.attrib['os']) + version = [int(release.attrib['major']), int(release.attrib['minor']), int(release.attrib['revision'])] + filename = release.find("filename").text + if platform.system() == os: + if version > localVersion: + return "%s/current/%s" % (updateBaseURL, filename) + except: + print sys.exc_info() + return None + return None + if __name__ == '__main__': print(getVersion()) - -- 2.30.2