chiark / gitweb /
Add progress bar to YouMagine upload.
authordaid <daid303@gmail.com>
Mon, 19 Aug 2013 07:16:31 +0000 (09:16 +0200)
committerdaid <daid303@gmail.com>
Mon, 19 Aug 2013 07:16:31 +0000 (09:16 +0200)
Cura/gui/configWizard.py
Cura/gui/mainWindow.py
Cura/gui/tools/youmagineGui.py
Cura/util/youmagine.py

index ddb07bad6eb60fc571c44ca833fe599a9d1769f2..42a11b4043e02d50325b42f4ccfedf87d537ac54 100644 (file)
@@ -337,14 +337,11 @@ class SelectParts(InfoPage):
 class FirmwareUpgradePage(InfoPage):
        def __init__(self, parent):
                super(FirmwareUpgradePage, self).__init__(parent, "Upgrade Ultimaker Firmware")
-               self.AddText(
-                       'Firmware is the piece of software running directly on your 3D printer.\nThis firmware controls the step motors, regulates the temperature\nand ultimately makes your printer work.')
+               self.AddText('Firmware is the piece of software running directly on your 3D printer.\nThis firmware controls the step motors, regulates the temperature\nand ultimately makes your printer work.')
                self.AddHiddenSeperator()
-               self.AddText(
-                       'The firmware shipping with new Ultimakers works, but upgrades\nhave been made to make better prints, and make calibration easier.')
+               self.AddText('The firmware shipping with new Ultimakers works, but upgrades\nhave been made to make better prints, and make calibration easier.')
                self.AddHiddenSeperator()
-               self.AddText(
-                       'Cura requires these new features and thus\nyour firmware will most likely need to be upgraded.\nYou will get the chance to do so now.')
+               self.AddText('Cura requires these new features and thus\nyour firmware will most likely need to be upgraded.\nYou will get the chance to do so now.')
                upgradeButton, skipUpgradeButton = self.AddDualButton('Upgrade to Marlin firmware', 'Skip upgrade')
                upgradeButton.Bind(wx.EVT_BUTTON, self.OnUpgradeClick)
                skipUpgradeButton.Bind(wx.EVT_BUTTON, self.OnSkipClick)
@@ -367,7 +364,7 @@ class FirmwareUpgradePage(InfoPage):
                self.GetParent().ShowPage(self.GetNext())
 
        def OnUrlClick(self, e):
-               webbrowser.open('http://daid.mine.nu/~daid/marlin_build/')
+               webbrowser.open('http://marlinbuilder.robotfuzz.com/')
 
 
 class UltimakerCheckupPage(InfoPage):
index e432b8a81533d06ac892f797ae9c8183e52d1f09..3e7fa396d53e723bc2fe3d0e05dcea063550b0b8 100644 (file)
@@ -167,7 +167,7 @@ class mainWindow(wx.Frame):
                self.simpleSettingsPanel = simpleMode.simpleModePanel(self.leftPane, lambda : self.scene.sceneUpdated())
                self.normalSettingsPanel = normalSettingsPanel(self.leftPane, lambda : self.scene.sceneUpdated())
 
-               self.youmagineButton = wx.BitmapButton(self.leftPane, -1, wx.Bitmap(resources.getPathForImage('youmagine-text.png')))
+               self.youmagineButton = wx.BitmapButton(self.leftPane, -1, wx.Bitmap(resources.getPathForImage('youmagine-icon.png')))
                self.youmagineButton.SetToolTipString("Share your design to YouMagine.com")
                self.youmagineButton.Bind(wx.EVT_BUTTON, self.OnYouMagine)
 
index 7c2cd62ca957ea47879dc26a845853f1a3b2f833..b68a9db0bd664c988110ee33fa313f1c5de4154a 100644 (file)
@@ -35,7 +35,7 @@ class youmagineManager(object):
        def __init__(self, parent, objectScene):
                self._mainWindow = parent
                self._scene = objectScene
-               self._ym = youmagine.Youmagine(profile.getPreference('youmagine_token'))
+               self._ym = youmagine.Youmagine(profile.getPreference('youmagine_token'), self._progressCallback)
 
                self._indicatorWindow = workingIndicatorWindow(self._mainWindow)
                self._getAuthorizationWindow = getAuthorizationWindow(self._mainWindow, self._ym)
@@ -45,6 +45,9 @@ class youmagineManager(object):
                thread.daemon = True
                thread.start()
 
+       def _progressCallback(self, progress):
+               self._indicatorWindow.progress(progress)
+
        #Do all the youmagine communication in a background thread, because it can take a while and block the UI thread otherwise
        def checkAuthorizationThread(self):
                wx.CallAfter(self._indicatorWindow.showBusy, 'Checking token')
@@ -142,11 +145,15 @@ class workingIndicatorWindow(wx.Frame):
 
                self._indicatorBitmap = wx.StaticBitmap(self._panel, -1, wx.EmptyBitmapRGBA(24, 24, red=255, green=255, blue=255, alpha=1))
                self._statusText = wx.StaticText(self._panel, -1, '...')
+               self._progress = wx.Gauge(self._panel, -1)
+               self._progress.SetRange(1000)
+               self._progress.SetMinSize((250, 30))
 
                self._panel._sizer = wx.GridBagSizer(2, 2)
                self._panel.SetSizer(self._panel._sizer)
                self._panel._sizer.Add(self._indicatorBitmap, (0, 0))
                self._panel._sizer.Add(self._statusText, (0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
+               self._panel._sizer.Add(self._progress, (1, 0), span=(1,2), flag=wx.EXPAND)
 
                self._busyState = 0
                self._busyTimer = wx.Timer(self)
@@ -161,8 +168,16 @@ class workingIndicatorWindow(wx.Frame):
                        self._busyState = 0
                self._indicatorBitmap.SetBitmap(self._busyBitmaps[self._busyState])
 
+       def progress(self, progressAmount):
+               wx.CallAfter(self._progress.Show)
+               wx.CallAfter(self._progress.SetValue, progressAmount*1000)
+               wx.CallAfter(self.Layout)
+               wx.CallAfter(self.Fit)
+
        def showBusy(self, text):
                self._statusText.SetLabel(text)
+               self._progress.Hide()
+               self.Layout()
                self.Fit()
                self.Centre()
                self.Show()
index 68b49a2091b5951a906e11ce95d86892657b96a4..d0da6c9d5aed6c3b5739ec6f7a6c8e9736864a41 100644 (file)
@@ -1,22 +1,50 @@
 from __future__ import absolute_import
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
-import sys
 import json
 import httplib as httpclient
 import urllib
-import cStringIO as StringIO
+
+class httpUploadDataStream(object):
+       def __init__(self, progressCallback):
+               self._dataList = []
+               self._totalLength = 0
+               self._readPos = 0
+               self._progressCallback = progressCallback
+
+       def write(self, data):
+               size = len(data)
+               if size < 1:
+                       return
+               blocks = size / 2048
+               for n in xrange(0, blocks):
+                       self._dataList.append(data[n*2048:n*2048+2048])
+               self._dataList.append(data[blocks*2048:])
+               self._totalLength += size
+
+       def read(self, size):
+               if self._readPos >= len(self._dataList):
+                       return None
+               ret = self._dataList[self._readPos]
+               self._readPos += 1
+               if self._progressCallback is not None:
+                       self._progressCallback(float(self._readPos / len(self._dataList)))
+               return ret
+
+       def __len__(self):
+               return self._totalLength
 
 class Youmagine(object):
-       def __init__(self, authToken):
-               self._hostUrl = ''
-               self._viewUrl = ''
-               self._authUrl = ''
+       def __init__(self, authToken, progressCallback = None):
+               self._hostUrl = 'api.youmagine.com'
+               self._viewUrl = 'www.youmagine.com'
+               self._authUrl = 'https://www.youmagine.com/integrations/cura/authorized_integrations/new'
                self._authToken = authToken
                self._userName = None
                self._userID = None
                self._http = None
                self._hostReachable = True
+               self._progressCallback = progressCallback
                self._categories = [
                        ('Art', 2),
                        ('Fashion', 3),
@@ -117,7 +145,7 @@ class Youmagine(object):
                        try:
                                if files is not None:
                                        boundary = 'wL36Yn8afVp8Ag7AmP8qZ0SA4n1v9T'
-                                       s = StringIO.StringIO()
+                                       s = httpUploadDataStream(self._progressCallback)
                                        for k, v in files.iteritems():
                                                filename = v[0]
                                                fileContents = v[1]
@@ -137,8 +165,7 @@ class Youmagine(object):
                                                s.write('\r\n')
                                        s.write('--%s--\r\n' % (boundary))
 
-                                       s = s.getvalue()
-                                       self._http.request(method, url, StringIO.StringIO(s), {"Content-type": "multipart/form-data; boundary=%s" % (boundary), "Content-Length": len(s)})
+                                       self._http.request(method, url, s, {"Content-type": "multipart/form-data; boundary=%s" % (boundary), "Content-Length": len(s)})
                                elif postData is not None:
                                        self._http.request(method, url, urllib.urlencode(postData), {"Content-type": "application/x-www-form-urlencoded"})
                                else:
@@ -158,6 +185,7 @@ class Youmagine(object):
                                return json.loads(responseText)
                        except ValueError:
                                print response.getheaders()
+                               print responseText
                                error = 'Failed to decode JSON response'
                self._hostReachable = False
                return {'error': error}