X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=Cura%2Fgui%2FfirmwareInstall.py;h=8dc16fac8138d0d55a8f4fc17881931a286f3253;hb=05abbdad2dbbe51f89c6cb527af4f17c7b0963e2;hp=885a2a478f6244f28c62498eace9c492fe9a8377;hpb=d7ef250e691993a1c756c4df3a763cf7d6b5a0fa;p=cura.git diff --git a/Cura/gui/firmwareInstall.py b/Cura/gui/firmwareInstall.py index 885a2a47..8dc16fac 100644 --- a/Cura/gui/firmwareInstall.py +++ b/Cura/gui/firmwareInstall.py @@ -1,6 +1,11 @@ from __future__ import absolute_import +__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License" -import os, wx, threading, sys +import os +import wx +import threading +import sys +import time from Cura.avr_isp import stk500v2 from Cura.avr_isp import ispBase @@ -11,12 +16,12 @@ from Cura.util import profile from Cura.util import resources def getDefaultFirmware(): - if profile.getPreference('machine_type') == 'ultimaker': - if profile.getPreference('has_heated_bed') == 'True': + if profile.getMachineSetting('machine_type') == 'ultimaker': + if profile.getMachineSetting('has_heated_bed') == 'True': return None - if profile.getPreferenceFloat('extruder_amount') > 2: + if profile.getMachineSettingFloat('extruder_amount') > 2: return None - if profile.getPreferenceFloat('extruder_amount') > 1: + if profile.getMachineSettingFloat('extruder_amount') > 1: if sys.platform.startswith('linux'): return resources.getPathForFirmware("MarlinUltimaker-115200-dual.hex") else: @@ -25,77 +30,95 @@ def getDefaultFirmware(): return resources.getPathForFirmware("MarlinUltimaker-115200.hex") else: return resources.getPathForFirmware("MarlinUltimaker-250000.hex") + if profile.getMachineSetting('machine_type') == 'ultimaker2': + return resources.getPathForFirmware("MarlinUltimaker2.hex") return None class InstallFirmware(wx.Dialog): def __init__(self, filename = None, port = None): - super(InstallFirmware, self).__init__(parent=None, title="Firmware install", size=(250, 100)) + super(InstallFirmware, self).__init__(parent=None, title="Firmware install for %s" % (profile.getMachineSetting('machine_name').title()), size=(250, 100)) if port is None: - port = profile.getPreference('serial_port') + port = profile.getMachineSetting('serial_port') if filename is None: filename = getDefaultFirmware() if filename is None: - wx.MessageBox('I am sorry, but Cura does not ship with a default firmware for your machine configuration.', 'Firmware update', wx.OK | wx.ICON_ERROR) + wx.MessageBox(_("I am sorry, but Cura does not ship with a default firmware for your machine configuration."), _("Firmware update"), wx.OK | wx.ICON_ERROR) self.Destroy() return + if profile.getMachineSetting('machine_type') == 'reprap': + wx.MessageBox(_("Cura only supports firmware updates for ATMega2560 based hardware.\nSo updating your RepRap with Cura might or might not work."), _("Firmware update"), wx.OK | wx.ICON_INFORMATION) sizer = wx.BoxSizer(wx.VERTICAL) - - self.progressLabel = wx.StaticText(self, -1, 'Reading firmware...') - sizer.Add(self.progressLabel, 0, flag=wx.ALIGN_CENTER) + + self.progressLabel = wx.StaticText(self, -1, 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nX') + sizer.Add(self.progressLabel, 0, flag=wx.ALIGN_CENTER|wx.ALL, border=5) self.progressGauge = wx.Gauge(self, -1) sizer.Add(self.progressGauge, 0, flag=wx.EXPAND) - self.okButton = wx.Button(self, -1, 'Ok') + self.okButton = wx.Button(self, -1, _("OK")) self.okButton.Disable() self.okButton.Bind(wx.EVT_BUTTON, self.OnOk) - sizer.Add(self.okButton, 0, flag=wx.ALIGN_CENTER) + sizer.Add(self.okButton, 0, flag=wx.ALIGN_CENTER|wx.ALL, border=5) self.SetSizer(sizer) - + self.filename = filename self.port = port - - threading.Thread(target=self.OnRun).start() - + + self.Layout() + self.Fit() + + self.thread = threading.Thread(target=self.OnRun) + self.thread.daemon = True + self.thread.start() + self.ShowModal() self.Destroy() return def OnRun(self): + wx.CallAfter(self.updateLabel, _("Reading firmware...")) hexFile = intelHex.readHex(self.filename) - wx.CallAfter(self.updateLabel, "Connecting to machine...") + wx.CallAfter(self.updateLabel, _("Connecting to machine...")) programmer = stk500v2.Stk500v2() programmer.progressCallback = self.OnProgress if self.port == 'AUTO': - for self.port in machineCom.serialList(True): - try: - programmer.connect(self.port) - break - except ispBase.IspError: - pass + wx.CallAfter(self.updateLabel, _("Please connect the printer to\nyour computer with the USB cable.")) + while not programmer.isConnected(): + for self.port in machineCom.serialList(True): + try: + programmer.connect(self.port) + break + except ispBase.IspError: + pass + time.sleep(1) + if not self: + #Window destroyed + return else: try: programmer.connect(self.port) except ispBase.IspError: pass - - if programmer.isConnected(): - wx.CallAfter(self.updateLabel, "Uploading firmware...") - try: - programmer.programChip(hexFile) - wx.CallAfter(self.updateLabel, "Done!\nInstalled firmware: %s" % (os.path.basename(self.filename))) - except ispBase.IspError as e: - wx.CallAfter(self.updateLabel, "Failed to write firmware.\n" + str(e)) - - programmer.close() - wx.CallAfter(self.okButton.Enable) + + if not programmer.isConnected(): + wx.MessageBox(_("Failed to find machine for firmware upgrade\nIs your machine connected to the PC?"), + _("Firmware update"), wx.OK | wx.ICON_ERROR) + wx.CallAfter(self.Close) return - wx.MessageBox('Failed to find machine for firmware upgrade\nIs your machine connected to the PC?', 'Firmware update', wx.OK | wx.ICON_ERROR) - wx.CallAfter(self.Close) - + + wx.CallAfter(self.updateLabel, _("Uploading firmware...")) + try: + programmer.programChip(hexFile) + wx.CallAfter(self.updateLabel, _("Done!\nInstalled firmware: %s") % (os.path.basename(self.filename))) + except ispBase.IspError as e: + wx.CallAfter(self.updateLabel, _("Failed to write firmware.\n") + str(e)) + + programmer.close() + wx.CallAfter(self.okButton.Enable) + def updateLabel(self, text): self.progressLabel.SetLabel(text) - self.Layout() - + #self.Layout() + def OnProgress(self, value, max): wx.CallAfter(self.progressGauge.SetRange, max) wx.CallAfter(self.progressGauge.SetValue, value)