Esempio n. 1
0
 def execute(self):
     "Convert to postscript button has been clicked."
     "Export the canvas as a postscript file."
     postscriptFileName = gcodec.getFilePathWithUnderscoredBasename(
         self.fileName, self.suffix)
     boundingBox = self.canvas.bbox(
         settings.Tkinter.ALL)  # tuple (w, n, e, s)
     boxW = boundingBox[0]
     boxN = boundingBox[1]
     boxWidth = boundingBox[2] - boxW
     boxHeight = boundingBox[3] - boxN
     print('Exported postscript file saved as ' + postscriptFileName)
     self.canvas.postscript(file=postscriptFileName,
                            height=boxHeight,
                            width=boxWidth,
                            pageheight=boxHeight,
                            pagewidth=boxWidth,
                            x=boxW,
                            y=boxN)
     fileExtension = self.fileExtension.value
     postscriptProgram = self.postscriptProgram.value
     if postscriptProgram == '':
         return
     postscriptFilePath = '"' + os.path.normpath(
         postscriptFileName) + '"'  # " to send in file name with spaces
     shellCommand = postscriptProgram + ' ' + postscriptFilePath
     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.'
                 % postscriptProgram)
             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:'
                 % postscriptProgram)
             print('http://www.gimp.org/')
         return
     convertedFileName = gcodec.getFilePathWithUnderscoredBasename(
         postscriptFilePath, '.' + 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 postscript to the %s file format.'
             % (postscriptProgram, fileExtension))
         print(
             'Try installing the %s program or look for another one, like Image Magick which can be found at:'
             % postscriptProgram)
         print('http://www.imagemagick.org/script/index.php')
	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__, os.path.join('templates', 'canvas_template.svg') )
		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
		svgViewer = self.svgViewer.value
		if svgViewer == '':
			return
		if svgViewer == 'webbrowser':
			settings.openWebPage( svgFileName )
			return
		svgFilePath = '"' + os.path.normpath( svgFileName ) + '"' # " to send in file name with spaces
		shellCommand = svgViewer + ' ' + 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.' % svgViewer )
				print('If so, try installing the %s program or look for another svg viewer, like Netscape which can be found at:' % svgViewer )
				print('http://www.netscape.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.' % ( svgViewer, fileExtension ) )
			print('Try installing the %s program or look for another one, like Image Magick which can be found at:' % svgViewer )
			print('http://www.imagemagick.org/script/index.php')
	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__, os.path.join( 'templates', 'canvas_template.svg' ) )
		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' )
Esempio n. 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 %s to carve the file.' % euclidean.getDurationString( time.time() - startTime ) )
	settings.openWebPage( suffixFileName )
Esempio n. 5
0
	def execute( self ):
		"Convert to postscript button has been clicked."
		"Export the canvas as a postscript file."
		postscriptFileName = gcodec.getFilePathWithUnderscoredBasename( self.fileName, self.suffix )
		boundingBox = self.canvas.bbox( settings.Tkinter.ALL ) # tuple (w, n, e, s)
		boxW = boundingBox[ 0 ]
		boxN = boundingBox[ 1 ]
		boxWidth = boundingBox[ 2 ] - boxW
		boxHeight = boundingBox[ 3 ] - boxN
		print( 'Exported postscript file saved as ' + postscriptFileName )
		self.canvas.postscript( file = postscriptFileName, height = boxHeight, width = boxWidth, pageheight = boxHeight, pagewidth = boxWidth, x = boxW, y = boxN )
		fileExtension = self.fileExtension.value
		postscriptProgram = self.postscriptProgram.value
		if postscriptProgram == '':
			return
		postscriptFilePath = '"' + os.path.normpath( postscriptFileName ) + '"' # " to send in file name with spaces
		shellCommand = postscriptProgram + ' ' + postscriptFilePath
		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.' % postscriptProgram )
				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:' % postscriptProgram )
				print( 'http://www.gimp.org/' )
			return
		convertedFileName = gcodec.getFilePathWithUnderscoredBasename( postscriptFilePath, '.' + 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 postscript to the %s file format.' % ( postscriptProgram, fileExtension ) )
			print( 'Try installing the %s program or look for another one, like Image Magick which can be found at:' % postscriptProgram )
			print( 'http://www.imagemagick.org/script/index.php' )