The slicing code is the same as Skeinforge. But the UI has been revamped to be... sane.
"""
-
from __future__ import absolute_import
import __init__
import os
import sys
import traceback
+import zipfile
__author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
def getFilePathsByDirectory(directoryName):
'Get the file paths in the directory of the file in directory.'
absoluteDirectoryPath = os.path.abspath(directoryName)
- directory = os.listdir(directoryName)
filePaths = []
- for fileName in directory:
- filePaths.append(os.path.join(absoluteDirectoryPath, fileName))
+ if os.path.isdir(directoryName):
+ for fileName in os.listdir(directoryName):
+ filePaths.append(os.path.join(absoluteDirectoryPath, fileName))
+ elif '.zip/' in directoryName:
+ zipfilename = directoryName[:directoryName.rfind('.zip/')+4]
+ subpath = directoryName[directoryName.rfind('.zip/')+5:]
+
+ z = zipfile.ZipFile(zipfilename, 'r')
+ for name in z.namelist():
+ if os.path.dirname(name) == subpath:
+ filePaths.append(os.path.join(zipfilename, name))
+ z.close()
+ print directoryName, filePaths
return filePaths
def getFilePathsRecursively(fileInDirectory=''):
def getFileText(fileName, printWarning=True, readMode='r'):
'Get the entire text of a file.'
+ if '.zip/' in fileName:
+ zipfilename = fileName[:fileName.rfind('.zip/')+4]
+ subpath = fileName[fileName.rfind('.zip/')+5:]
+
+ try:
+ z = zipfile.ZipFile(zipfilename, 'r')
+ f = z.open(subpath, 'r')
+ fileText = f.read()
+ f.close()
+ z.close()
+ return fileText
+ except KeyError:
+ if printWarning:
+ print('The file ' + fileName + ' does not exist.')
+ return ''
try:
- file = open(fileName, readMode)
- fileText = file.read()
- file.close()
+ f = open(fileName, readMode)
+ fileText = f.read()
+ f.close()
return fileText
except IOError:
if printWarning:
print('The file ' + fileName + ' does not exist.')
+
return ''
def getFileTextInFileDirectory(fileInDirectory, fileName, readMode='r'):
def getGNUTranslatorGcodeFileTypeTuples():
"Get the file type tuples from the translators in the import plugins folder plus gcode."
- fileTypeTuples = getTranslatorFileTypeTuples()
+ fileTypeTuples = [] #getTranslatorFileTypeTuples()
fileTypeTuples.append( ('Gcode text files', '*.gcode') )
fileTypeTuples.sort()
return fileTypeTuples
matrix[2][2] = 1.0\r
\r
if matrix[3][2] != 0.0:\r
- matrix[3][0] /= -matrix[3][2] / 100\r
- matrix[3][1] /= -matrix[3][2] / 100\r
+ matrix[3][0] = matrix[3][0] / (-matrix[3][2] / 100)\r
+ matrix[3][1] = matrix[3][1] / (-matrix[3][2] / 100)\r
matrix[3][2] = -100\r
else:\r
matrix[0][0] = scale2D\r
-import sys
+import sys, os, zipfile
try:
import cx_Freeze
except:
print "ERROR: Your cx-Freeze version is too old to use with Cura."
sys.exit(1)
-sys.path.append('./cura_sf/')
+sys.path.append(os.path.abspath('cura_sf'))
# Dependencies are automatically detected, but it might need fine tuning.
-build_exe_options = {"packages": [
+build_exe_options = {
+"silent": True,
+"packages": [
'encodings.utf_8',
"OpenGL", "OpenGL.arrays", "OpenGL.platform", "OpenGL.GLU",
-], "excludes": ['Tkinter', 'tcl'], "optimize": 0, "include_files": [
+], "excludes": [
+ 'Tkinter', 'tcl', 'cura_sf', 'fabmetheus_utilities', 'skeinforge_application', 'numpy',
+], "include_files": [
('images', 'images'),
- ('cura.py', 'cura.py'),
- ('__init__.py', '__init__.py'),
- ('util', 'util'),
- ('cura_sf', 'cura_sf')
-]}
+], "build_exe": 'freeze_build'}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = "Win32GUI"
cx_Freeze.setup( name = "Cura",
- version = "RC5",
- description = "Cura",
- options = {"build_exe": build_exe_options},
- executables = [cx_Freeze.Executable("cura.py", base=base)])
+ version = "RC5",
+ description = "Cura",
+ options = {"build_exe": build_exe_options},
+ executables = [cx_Freeze.Executable("cura.py", base=base)])
+
+m = cx_Freeze.ModuleFinder(excludes=["gui"])
+m.IncludeFile(os.path.abspath("cura.py"))
+m.IncludeFile(os.path.abspath("cura_sf/skeinforge_application/skeinforge_plugins/profile_plugins/extrusion.py"))
+m.IncludeFile(os.path.abspath("cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/stl.py"))
+m.IncludeFile(os.path.abspath("cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/export_plugins/static_plugins/gcode_small.py"))
+for name in os.listdir("cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins"):
+ if name.endswith('.py'):
+ m.IncludeFile(os.path.abspath("cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/" + name))
+m.ReportMissingModules()
+cwd = os.path.abspath(".")
+
+z = zipfile.ZipFile("freeze_build/cura_sf.zip", "w", zipfile.ZIP_DEFLATED)
+for mod in m.modules:
+ if mod.file != None and mod.file.startswith(cwd):
+ if mod.file[len(cwd)+1:] == "cura.py":
+ z.write(mod.file[len(cwd)+1:], "__main__.py")
+ else:
+ z.write(mod.file[len(cwd)+1:])
+z.write('cura_sf/fabmetheus_utilities/templates/layer_template.svg')
+z.write('cura_sf/fabmetheus_utilities/version.txt')
+z.write('__init__.py')
+z.close()
import platform, os, subprocess, sys
-cura_sf_path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../cura_sf/"))
-if cura_sf_path not in sys.path:
- sys.path.append(cura_sf_path)
-from skeinforge_application.skeinforge_utilities import skeinforge_craft
+if not hasattr(sys, 'frozen'):
+ cura_sf_path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../cura_sf/"))
+ if cura_sf_path not in sys.path:
+ sys.path.append(cura_sf_path)
+ from skeinforge_application.skeinforge_utilities import skeinforge_craft
from util import profile
if platform.python_implementation() == "PyPy":
skeinforge_craft.writeOutput(fileName)
elif pypyExe == False:
- print "************************************************"
- print "* Failed to find pypy, so slicing with python! *"
- print "************************************************"
- skeinforge_craft.writeOutput(fileName)
- print "************************************************"
- print "* Failed to find pypy, so sliced with python! *"
- print "************************************************"
+ if not hasattr(sys, 'frozen'):
+ print "************************************************"
+ print "* Failed to find pypy, so slicing with python! *"
+ print "************************************************"
+ skeinforge_craft.writeOutput(fileName)
+ print "************************************************"
+ print "* Failed to find pypy, so sliced with python! *"
+ print "************************************************"
+ else:
+ print "******************************************************************"
+ print "* Failed to find pypy, we need pypy to slice with a frozen build *"
+ print "* Place pypy in the same directory as Cura so Cura can find it. *"
+ print "******************************************************************"
+ sys.exit(1)
else:
subprocess.call(getSliceCommand(fileName))
#In case we have a frozen exe, then argv[0] points to the executable, but we want to give pypy a real script file.
if hasattr(sys, 'frozen'):
- mainScriptFile = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "cura.py"))
+ mainScriptFile = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..", "cura_sf.zip"))
else:
mainScriptFile = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", os.path.split(sys.argv[0])[1]))
cmd = [pypyExe, mainScriptFile, '-p', profile.getGlobalProfileString()]