Exemplo n.º 1
0
def render_preview(filename, startx, starty, width, height, resolution=None):
    import tempfile
    temp = tempfile.mktemp()

    try:
        # quote the filename so that it can have spaces and to avoid a
        # security hole
        filename = utils.sh_quote(filename)
        if resolution is None:
            resolution = config.preferences.eps_preview_resolution
        factor = resolution / 72.0
        width = int(math.ceil(width * factor))
        height = int(math.ceil(height * factor))
        offx = -startx
        offy = -starty
        os.system(gs_command % locals())

        image = Image.open(temp)
        image.load()
        return image
    finally:
        try:
            os.unlink(temp)
        except:
            pass
Exemplo n.º 2
0
def render_preview(filename, startx, starty, width, height, resolution = None):
	import tempfile
	temp = tempfile.mktemp()

	try:
		# quote the filename so that it can have spaces and to avoid a
		# security hole
		filename = utils.sh_quote(filename)
		if resolution is None:
			resolution = config.preferences.eps_preview_resolution
		factor = resolution / 72.0
		width = int(math.ceil(width * factor))
		height = int(math.ceil(height * factor))
		offx = -startx
		offy = -starty
		os.system(gs_command % locals())

		image = Image.open(temp)
		image.load()
		return image
	finally:
		try:
			os.unlink(temp)
		except:
			pass
Exemplo n.º 3
0
	def Load(self):
		basename, ext = os.path.splitext(self.filename)
		if ext != '.bz2':
			basename = self.filename
		stream = os.popen('bzip2 -d -c ' + sh_quote(self.filename))
		doc = load.load_drawing_from_file(stream, basename,
											doc_class = self.doc_class)
		if doc:
			doc.meta.compressed = "bzip2"
			doc.meta.compressed_file = self.filename
			self.messages = doc.meta.load_messages
		return doc
Exemplo n.º 4
0
 def Load(self):
     basename, ext = os.path.splitext(self.filename)
     if ext != '.bz2':
         basename = self.filename
     stream = os.popen('bzip2 -d -c ' + sh_quote(self.filename))
     doc = load.load_drawing_from_file(stream,
                                       basename,
                                       doc_class=self.doc_class)
     if doc:
         doc.meta.compressed = "bzip2"
         doc.meta.compressed_file = self.filename
         self.messages = doc.meta.load_messages
     return doc
Exemplo n.º 5
0
	def Load(self):
		if self.filename:
			basename, ext = os.path.splitext(self.filename)
			if ext != '.gz':
				basename = self.filename
			stream = os.popen('gzip -d -c ' + sh_quote(self.filename))
			doc = load.load_drawing_from_file(stream, basename,
												doc_class = self.doc_class)
			if doc:
				doc.meta.compressed = "gzip"
				doc.meta.compressed_file = self.filename
				self.messages = doc.meta.load_messages
			return doc
		raise SketchLoadError('gziploader must be instantiated with filename')
 def Load(self):
     if self.filename:
         basename, ext = os.path.splitext(self.filename)
         if ext != '.gz':
             basename = self.filename
         stream = os.popen('gzip -d -c ' + sh_quote(self.filename))
         doc = load.load_drawing_from_file(stream,
                                           basename,
                                           doc_class=self.doc_class)
         if doc:
             doc.meta.compressed = "gzip"
             doc.meta.compressed_file = self.filename
             self.messages = doc.meta.load_messages
         return doc
     raise SketchLoadError('gziploader must be instantiated with filename')