chiark / gitweb /
Add feature which checks for newer releases on startup.
authordaid303 <daid303@gmail.com>
Thu, 10 Jan 2013 13:19:48 +0000 (14:19 +0100)
committerdaid303 <daid303@gmail.com>
Thu, 10 Jan 2013 13:19:48 +0000 (14:19 +0100)
Cura/gui/app.py
Cura/gui/preferencesDialog.py
Cura/util/profile.py
Cura/util/settings.py [new file with mode: 0644]
Cura/util/version.py

index 6372d7236c9eabe0e88b1855689423175c86cde7..c1618de70e76b176d13a14d3d93e4f9ea5357b89 100644 (file)
@@ -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)
index b583bc4e292f6c0dd364b333deca447534b26157..55e73ccc3a221989e67d6cd5d427503ed5aab184 100644 (file)
@@ -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)
index d8f0f27e135d04c554ef5daa2dfae4ed8bb487a6..48453d9fc5baf726e98bf62cf13f7fbd0e5b386e 100644 (file)
@@ -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 (file)
index 0000000..9e81310
--- /dev/null
@@ -0,0 +1,6 @@
+
+class setting(object):
+       def __init__(self, key, name, description):
+               self._key = key
+               self._name = name
+               self._description = description
index 93117f7c2f6dc259974b840d60f7568bac0b2a0c..8ffceb4e30eb0e0168149ad4401a162482e9b74b 100644 (file)
@@ -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())
-