示例#1
0
def writeOutput(fileName=''):
    "Cleave a GNU Triangulated Surface file.  If no fileName is specified, cleave the first GNU Triangulated Surface file in this folder."
    if fileName == '':
        unmodified = gcodec.getFilesWithFileTypesWithoutWords(
            interpret.getImportPluginFileNames())
        if len(unmodified) == 0:
            print("There are no carvable files in this folder.")
            return
        fileName = unmodified[0]
    startTime = time.time()
    print('File ' + gcodec.getSummarizedFileName(fileName) +
          ' is being cleaved.')
    cleaveGcode = getCraftedText(fileName)
    if cleaveGcode == '':
        return
    suffixFileName = fileName[:fileName.rfind('.')] + '_cleave.svg'
    suffixDirectoryName = os.path.dirname(suffixFileName)
    suffixReplacedBaseName = os.path.basename(suffixFileName).replace(' ', '_')
    suffixFileName = os.path.join(suffixDirectoryName, suffixReplacedBaseName)
    gcodec.writeFileText(suffixFileName, cleaveGcode)
    print('The cleaved file is saved as ' +
          gcodec.getSummarizedFileName(suffixFileName))
    print('It took ' + str(int(round(time.time() - startTime))) +
          ' seconds to cleave the file.')
    settings.openWebPage(suffixFileName)
示例#2
0
def writeOutput( fileName = '' ):
	"Carve a GNU Triangulated Surface file."
	startTime = time.time()
	print( 'File ' + gcodec.getSummarizedFileName( fileName ) + ' is being carved.' )
	carveGcode = getCraftedText( fileName )
	if carveGcode == '':
		return
	suffixFileName = gcodec.getFilePathWithUnderscoredBasename( fileName, '_carve.svg' )
	gcodec.writeFileText( suffixFileName, carveGcode )
	print( 'The carved file is saved as ' + gcodec.getSummarizedFileName( suffixFileName ) )
	print( 'It took ' + str( int( round( time.time() - startTime ) ) ) + ' seconds to carve the file.' )
	settings.openWebPage( suffixFileName )
示例#3
0
	def execute( self ):
		"Export the canvas as an svg file."
		svgFileName = gcodec.getFilePathWithUnderscoredBasename( self.fileName, self.suffix )
		boundingBox = self.canvas.bbox( settings.Tkinter.ALL ) # tuple (w, n, e, s)
		self.boxW = boundingBox[ 0 ]
		self.boxN = boundingBox[ 1 ]
		boxWidth = boundingBox[ 2 ] - self.boxW
		boxHeight = boundingBox[ 3 ] - self.boxN
		print( 'Exported svg file saved as ' + svgFileName )
		svgTemplateText = gcodec.getFileTextInFileDirectory( settings.__file__, 'svg_canvas.template' )
		output = cStringIO.StringIO()
		lines = gcodec.getTextLines( svgTemplateText )
		firstWordTable = {}
		firstWordTable[ 'height="999px"' ] = '		height="%spx"' % int( round( boxHeight ) )
		firstWordTable[ '<!--replaceLineWith_coloredLines-->' ] = self.getCanvasLinesOutput()
		firstWordTable[ 'replaceLineWithTitle' ] = gcodec.getSummarizedFileName( self.fileName )
		firstWordTable[ 'width="999px"' ] = '		width="%spx"' % int( round( boxWidth ) )
		for line in lines:
			parseLineReplace( firstWordTable, line, output )
		gcodec.writeFileText( svgFileName, output.getvalue() )
		fileExtension = self.fileExtension.value
		svgProgram = self.svgProgram.value
		if svgProgram == '':
			return
		if svgProgram == 'webbrowser':
			settings.openWebPage( svgFileName )
			return
		svgFilePath = '"' + os.path.normpath( svgFileName ) + '"' # " to send in file name with spaces
		shellCommand = svgProgram + ' ' + svgFilePath
		print( '' )
		if fileExtension == '':
			print( 'Sending the shell command:' )
			print( shellCommand )
			commandResult = os.system( shellCommand )
			if commandResult != 0:
				print( 'It may be that the system could not find the %s program.' % svgProgram )
				print( 'If so, try installing the %s program or look for another one, like the Gnu Image Manipulation Program (Gimp) which can be found at:' % svgProgram )
				print( 'http://www.gimp.org/' )
			return
		convertedFileName = gcodec.getFilePathWithUnderscoredBasename( svgFilePath, '.' + fileExtension + '"' )
		shellCommand += ' ' + convertedFileName
		print( 'Sending the shell command:' )
		print( shellCommand )
		commandResult = os.system( shellCommand )
		if commandResult != 0:
			print( 'The %s program could not convert the svg to the %s file format.' % ( svgProgram, fileExtension ) )
			print( 'Try installing the %s program or look for another one, like Image Magick which can be found at:' % svgProgram )
			print( 'http://www.imagemagick.org/script/index.php' )
示例#4
0
def writeOutput(fileName=''):
    "Carve a GNU Triangulated Surface file."
    startTime = time.time()
    print('File ' + gcodec.getSummarizedFileName(fileName) +
          ' is being carved.')
    carveGcode = getCraftedText(fileName)
    if carveGcode == '':
        return
    suffixFileName = gcodec.getFilePathWithUnderscoredBasename(
        fileName, '_carve.svg')
    gcodec.writeFileText(suffixFileName, carveGcode)
    print('The carved file is saved as ' +
          gcodec.getSummarizedFileName(suffixFileName))
    print('It took ' + str(int(round(time.time() - startTime))) +
          ' seconds to carve the file.')
    settings.openWebPage(suffixFileName)
示例#5
0
def analyzeFileGivenText( fileName, gcodeText, repository = None ):
	"Write scalable vector graphics for a gcode file given the settings."
	if gcodeText == '':
		return ''
	if repository == None:
		repository = settings.getReadRepository( VectorwriteRepository() )
	startTime = time.time()
	vectorwriteGcode = VectorwriteSkein().getSVG( fileName, gcodeText, repository )
	if vectorwriteGcode == '':
		return
	suffixFileName = fileName[ : fileName.rfind( '.' ) ] + '_vectorwrite.svg'
	suffixDirectoryName = os.path.dirname( suffixFileName )
	suffixReplacedBaseName = os.path.basename( suffixFileName ).replace( ' ', '_' )
	suffixFileName = os.path.join( suffixDirectoryName, suffixReplacedBaseName )
	gcodec.writeFileText( suffixFileName, vectorwriteGcode )
	print( 'The vectorwrite file is saved as ' + gcodec.getSummarizedFileName( suffixFileName ) )
	print( 'It took ' + str( int( round( time.time() - startTime ) ) ) + ' seconds to vectorwrite the file.' )
	settings.openWebPage( suffixFileName )
示例#6
0
def writeOutput(fileName=""):
    "Chop a GNU Triangulated Surface file.  If no fileName is specified, chop the first GNU Triangulated Surface file in this folder."
    if fileName == "":
        unmodified = gcodec.getFilesWithFileTypesWithoutWords(interpret.getImportPluginFileNames())
        if len(unmodified) == 0:
            print("There are no carvable files in this folder.")
            return
        fileName = unmodified[0]
    startTime = time.time()
    print("File " + gcodec.getSummarizedFileName(fileName) + " is being chopped.")
    chopGcode = getCraftedText(fileName)
    if chopGcode == "":
        return
    suffixFileName = fileName[: fileName.rfind(".")] + "_chop.svg"
    suffixDirectoryName = os.path.dirname(suffixFileName)
    suffixReplacedBaseName = os.path.basename(suffixFileName).replace(" ", "_")
    suffixFileName = os.path.join(suffixDirectoryName, suffixReplacedBaseName)
    gcodec.writeFileText(suffixFileName, chopGcode)
    print("The chopped file is saved as " + gcodec.getSummarizedFileName(suffixFileName))
    print("It took " + str(int(round(time.time() - startTime))) + " seconds to chop the file.")
    settings.openWebPage(suffixFileName)
示例#7
0
def analyzeFileGivenText(fileName, gcodeText, repository=None):
    "Write scalable vector graphics for a gcode file given the settings."
    if gcodeText == '':
        return ''
    if repository == None:
        repository = settings.getReadRepository(VectorwriteRepository())
    startTime = time.time()
    vectorwriteGcode = VectorwriteSkein().getSVG(fileName, gcodeText,
                                                 repository)
    if vectorwriteGcode == '':
        return
    suffixFileName = fileName[:fileName.rfind('.')] + '_vectorwrite.svg'
    suffixDirectoryName = os.path.dirname(suffixFileName)
    suffixReplacedBaseName = os.path.basename(suffixFileName).replace(' ', '_')
    suffixFileName = os.path.join(suffixDirectoryName, suffixReplacedBaseName)
    gcodec.writeFileText(suffixFileName, vectorwriteGcode)
    print('The vectorwrite file is saved as ' +
          gcodec.getSummarizedFileName(suffixFileName))
    print('It took ' + str(int(round(time.time() - startTime))) +
          ' seconds to vectorwrite the file.')
    settings.openWebPage(suffixFileName)
示例#8
0
def writeOutput( fileName = '' ):
	"Cleave a GNU Triangulated Surface file.  If no fileName is specified, cleave the first GNU Triangulated Surface file in this folder."
	if fileName == '':
		unmodified = gcodec.getFilesWithFileTypesWithoutWords( interpret.getImportPluginFileNames() )
		if len( unmodified ) == 0:
			print( "There are no carvable files in this folder." )
			return
		fileName = unmodified[ 0 ]
	startTime = time.time()
	print( 'File ' + gcodec.getSummarizedFileName( fileName ) + ' is being cleaved.' )
	cleaveGcode = getCraftedText( fileName )
	if cleaveGcode == '':
		return
	suffixFileName = fileName[ : fileName.rfind( '.' ) ] + '_cleave.svg'
	suffixDirectoryName = os.path.dirname( suffixFileName )
	suffixReplacedBaseName = os.path.basename( suffixFileName ).replace( ' ', '_' )
	suffixFileName = os.path.join( suffixDirectoryName, suffixReplacedBaseName )
	gcodec.writeFileText( suffixFileName, cleaveGcode )
	print( 'The cleaved file is saved as ' + gcodec.getSummarizedFileName( suffixFileName ) )
	print( 'It took ' + str( int( round( time.time() - startTime ) ) ) + ' seconds to cleave the file.' )
	settings.openWebPage( suffixFileName )