chiark / gitweb /
Added copy to SD feature. Fixed #138
authorDaid <daid303@gmail.com>
Fri, 22 Jun 2012 04:42:07 +0000 (06:42 +0200)
committerDaid <daid303@gmail.com>
Fri, 22 Jun 2012 04:42:07 +0000 (06:42 +0200)
Cura/gui/preferencesDialog.py
Cura/gui/sliceProgessPanel.py
Cura/util/profile.py
Cura/util/sliceRun.py

index 6df56be5581cd5ff9658331d9dfb9ea92d4244ca..9ff3bd6eb3535efde635d9f0047a402aea902875 100644 (file)
@@ -1,7 +1,7 @@
 from __future__ import absolute_import\r
 import __init__\r
 \r
-import wx, os, platform, types\r
+import wx, os, platform, types, string\r
 import ConfigParser\r
 \r
 from gui import configBase\r
@@ -51,7 +51,14 @@ class preferencesDialog(configBase.configWindowBase):
                configBase.TitleRow(right, 'Slicer settings')\r
                #c = configBase.SettingRow(right, 'Slicer selection', 'slicer', ['Cura (Skeinforge based)', 'Slic3r'], 'Which slicer to use to slice objects. Usually the Cura engine produces the best results. But Slic3r is developing fast and is faster with slicing.', type = 'preference')\r
                c = configBase.SettingRow(right, 'Save profile on slice', 'save_profile', False, 'When slicing save the profile as [stl_file]_profile.ini next to the model.', type = 'preference')\r
-               \r
+\r
+               configBase.TitleRow(right, 'SD Card settings')\r
+               if len(getDrives()) > 1:\r
+                       c = configBase.SettingRow(right, 'SD card drive', 'sdpath', getDrives(), 'Location of your SD card, when using the copy to SD feature.', type = 'preference')\r
+               else:\r
+                       c = configBase.SettingRow(right, 'SD card path', 'sdpath', '', 'Location of your SD card, when using the copy to SD feature.', type = 'preference')\r
+               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')\r
+\r
                self.okButton = wx.Button(left, -1, 'Ok')\r
                left.GetSizer().Add(self.okButton, (left.GetSizer().GetRows(), 1))\r
                self.okButton.Bind(wx.EVT_BUTTON, self.OnClose)\r
@@ -65,3 +72,14 @@ class preferencesDialog(configBase.configWindowBase):
                        wx.MessageBox('After changing the amount of extruders you need to restart Cura for full effect.', 'Extruder amount warning.', wx.OK | wx.ICON_INFORMATION)\r
                self.MakeModal(False)\r
                self.Destroy()\r
+\r
+def getDrives():\r
+       drives = ['']\r
+       if platform.system() == "Windows":\r
+               from ctypes import windll\r
+               bitmask = windll.kernel32.GetLogicalDrives()\r
+               for letter in string.uppercase:\r
+                       if bitmask & 1:\r
+                               drives.append(letter + ':/')\r
+                       bitmask >>= 1\r
+       return drives\r
index 8a6a518992149f63e401369f339d16a725346b57..b195c9d63e42a3ce9fffe4a7036ba538a9313485 100644 (file)
@@ -1,7 +1,7 @@
 from __future__ import absolute_import
 import __init__
 
-import wx, sys, os, math, threading, subprocess, time, re
+import wx, sys, os, shutil, math, threading, subprocess, time, re
 
 from util import profile
 from util import sliceRun
@@ -70,6 +70,13 @@ class sliceProgessPanel(wx.Panel):
        def OnOpenFileLocation(self, e):
                exporer.openExporer(sliceRun.getExportFilename(self.filelist[0]))
        
+       def OnCopyToSD(self, e):
+               exportFilename = sliceRun.getExportFilename(self.filelist[0])
+               filename = os.path.basename(exportFilename)
+               if profile.getPreference('sdshortnames') == 'True':
+                       filename = sliceRun.getShortFilename(filename)
+               shutil.copy(exportFilename, os.path.join(profile.getPreference('sdpath'), filename))
+       
        def OnSliceDone(self, result):
                self.progressGauge.Destroy()
                self.abortButton.Destroy()
@@ -90,6 +97,10 @@ class sliceProgessPanel(wx.Panel):
                                self.openFileLocationButton = wx.Button(self, -1, "Open file location")
                                self.Bind(wx.EVT_BUTTON, self.OnOpenFileLocation, self.openFileLocationButton)
                                self.sizer.Add(self.openFileLocationButton, 0)
+                       if profile.getPreference('sdpath') != '':
+                               self.copyToSDButton = wx.Button(self, -1, "To SDCard")
+                               self.Bind(wx.EVT_BUTTON, self.OnCopyToSD, self.copyToSDButton)
+                               self.sizer.Add(self.copyToSDButton, 0)
                        self.showButton = wx.Button(self, -1, "Show result")
                        self.Bind(wx.EVT_BUTTON, self.OnShowGCode, self.showButton)
                        self.sizer.Add(self.showButton, 0)
index 6c06afb499dbc31423714b50a0c6bfef84309cc0..ae5cdd66959e9397a39a57dfd90d69e60200b1f3 100644 (file)
@@ -161,6 +161,8 @@ preferencesDefaultSettings = {
        'save_profile': 'False',\r
        'filament_cost_kg': '0',\r
        'filament_cost_meter': '0',\r
+       'sdpath': '',\r
+       'sdshortnames': 'True',\r
        \r
        'extruder_head_size_min_x': '70.0',\r
        'extruder_head_size_min_y': '18.0',\r
index 44b0a995516ba6dc9d15a987d5ca9b3de4db0484..1b561692959b6d4c42fd3f5b9c14785da3b9d462 100644 (file)
@@ -100,6 +100,12 @@ def runSlice(fileNames):
 def getExportFilename(filename, ext = "gcode"):
        return "%s_export.%s" % (filename[: filename.rfind('.')], ext)
 
+#Get a short filename in 8.3 format for proper saving on SD.
+def getShortFilename(filename):
+       ext = filename[filename.rfind('.'):]
+       filename = filename[: filename.rfind('.')]
+       return filename[:8] + ext[:2]
+
 def getSliceCommand(filename):
        if profile.getPreference('slicer').startswith('Slic3r') and getSlic3rExe() != False:
                slic3rExe = getSlic3rExe()