예제 #1
0
def convert(input_file, output_file, options=[]):

    init_uniconv()

    from app.io import load
    from uniconvertor import filters
    import app

    app.init_lib()

    filters.load_plugin_configuration()

    if len(options) and options[0] == '-parse':
        load.parse_drawing(input_file, output_file)
    else:
        doc = load.load_drawing(input_file)
        extension = os.path.splitext(output_file)[1].lower()
        fileformat = filters.guess_export_plugin(extension)
        if fileformat:
            saver = filters.find_export_plugin(fileformat)
            saver(doc, output_file)
        else:
            sys.stderr.write('ERROR: unrecognized extension %s\n' % extension)
            sys.exit(1)
        doc.Destroy()
예제 #2
0
 def __init__(self, filename, width=None, height=None, kind='direct'):
     Flowable.__init__(self)
     ext = os.path.splitext(filename)[-1]
     self._kind = kind
     # Prefer svglib for SVG, as it works better
     if ext in ('.svg', '.svgz') and svglib is not None:
         self._mode = 'svglib'
         self.doc = svglib.svg2rlg(filename)
         self.width = width
         self.height = height
         _, _, self._w, self._h = self.doc.getBounds()
         if not self.width:
             self.width = self._w
         if not self.height:
             self.height = self._h
     # Use uniconvertor for the rest
     elif load is not None:
         self._mode = 'uniconvertor'
         self.doc = load.load_drawing(filename.encode('utf-8'))
         self.saver = plugins.find_export_plugin(
             plugins.guess_export_plugin('.pdf'))
         self.width = width
         self.height = height
         _, _, self._w, self._h = self.doc.BoundingRect()
         if not self.width:
             self.width = self._w
         if not self.height:
             self.height = self._h
     else:
         self._mode = None
         log.error("Vector image support not enabled,"
                   " please install svglib and/or uniconvertor.")
     if self._mode:
         self.__ratio = float(self.width) / self.height
예제 #3
0
 def open_callback(self, arg):
     app.updateInfo(inf1=_("Document parsing"), inf2=_("Start document processing"), inf3=3)
     filename = arg[0]
     doc = load.load_drawing(filename)
     app.updateInfo(inf1=_("Document parsing"), inf2=_("Document has been loaded"), inf3=100)
     time.sleep(0.1)
     return doc
예제 #4
0
 def import_callback(self, arg):
     app.updateInfo(inf1=_("File importing"), inf2=_("Start file parsing"), inf3=3)
     filename = arg[0]
     doc = load.load_drawing(filename)
     app.updateInfo(inf1=_("File importing"), inf2=_("File has been imported"), inf3=100)
     time.sleep(0.1)
     return doc
예제 #5
0
def convert(input_file, output_file, options=[]):

	init_uniconv()

	from app.io import load
	from uniconvertor import filters
	import app

	app.init_lib()

	filters.load_plugin_configuration()

	if len(options) and options[0] == '-parse':
		load.parse_drawing(input_file, output_file)
	else:
		doc = load.load_drawing(input_file)
		extension = os.path.splitext(output_file)[1].lower()
		fileformat = filters.guess_export_plugin(extension)
		if fileformat:
			saver = filters.find_export_plugin(fileformat)
			saver(doc, output_file)
		else:
			sys.stderr.write('ERROR: unrecognized extension %s\n' % extension)
			sys.exit(1)
		doc.Destroy()
예제 #6
0
 def import_callback(self, arg):
     app.updateInfo(inf1=_('File importing'),
                    inf2=_('Start file parsing'),
                    inf3=3)
     filename = arg[0]
     doc = load.load_drawing(filename)
     app.updateInfo(inf1=_('File importing'),
                    inf2=_('File has been imported'),
                    inf3=100)
     time.sleep(.1)
     return doc
예제 #7
0
 def open_callback(self, arg):
     app.updateInfo(inf1=_('Document parsing'),
                    inf2=_('Start document processing'),
                    inf3=3)
     filename = arg[0]
     doc = load.load_drawing(filename)
     app.updateInfo(inf1=_('Document parsing'),
                    inf2=_('Document has been loaded'),
                    inf3=100)
     time.sleep(.1)
     return doc
예제 #8
0
 def __init__(self,filename,width=None,height=None):
     Flowable.__init__(self)
     if HAS_UNICONVERTOR:
         self.doc = load.load_drawing(filename)
         self.saver = plugins.find_export_plugin(plugins.guess_export_plugin(".pdf"))
         self.width=width
         self.height=height
         _,_,self._w,self._h=self.doc.BoundingRect()
         if not self.width: self.width=self._w
         if not self.height: self.height=self._h
     else:
         raise ImportError("SVG image support not enabled, install uniconvertor >= 1.1.3")
def uniconv_run():	
	_pkgdir = __path__[0]
	app_dir = os.path.join(_pkgdir, 'app')
	app_ver = string.strip(open(os.path.join(app_dir, 'VERSION')).read())

	if len(sys.argv)<3 or sys.argv[1]=='--help':
		print '\nUniConvertor',app_ver
		print __doc__
		sys.exit(0)
		
	options=[]
	input_file=sys.argv[-2]
	output_file=sys.argv[-1]
	
	if len(sys.argv)>3:
		options=sys.argv[1:-2]
		
	if not os.path.isfile(input_file):
		print '\nERROR: %s file is not found!' % input_file
		print '\nUniConvertor',app_ver
		print __doc__
		sys.exit(1)
	
	sys.path.insert(1, _pkgdir)
	
	from app.io import load
	from sk1libs import filters
	import app
	
	app.init_lib()
	
	filters.load_plugin_configuration()
	
	if len(options) and options[0]=='-parse':
		load.parse_drawing(input_file, output_file)
		sys.exit(0)
	else:
		doc = load.load_drawing(input_file)
		extension = os.path.splitext(output_file)[1]
		fileformat = filters.guess_export_plugin(extension)
		if fileformat:
			saver = filters.find_export_plugin(fileformat)
			saver(doc, output_file)
		else:
			sys.stderr.write('ERROR: unrecognized extension %s\n' % extension)
			sys.exit(1)
		doc.Destroy()
	
	sys.exit(0)
def uniconv_run():
    _pkgdir = __path__[0]
    app_dir = os.path.join(_pkgdir, 'app')
    app_ver = string.strip(open(os.path.join(app_dir, 'VERSION')).read())

    if len(sys.argv) < 3 or sys.argv[1] == '--help':
        print '\nUniConvertor', app_ver
        print __doc__
        sys.exit(0)

    options = []
    input_file = sys.argv[-2]
    output_file = sys.argv[-1]

    if len(sys.argv) > 3:
        options = sys.argv[1:-2]

    if not os.path.isfile(input_file):
        print '\nERROR: %s file is not found!' % input_file
        print '\nUniConvertor', app_ver
        print __doc__
        sys.exit(1)

    sys.path.insert(1, _pkgdir)

    from app.io import load
    from sk1libs import filters
    import app

    app.init_lib()

    filters.load_plugin_configuration()

    if len(options) and options[0] == '-parse':
        load.parse_drawing(input_file, output_file)
        sys.exit(0)
    else:
        doc = load.load_drawing(input_file)
        extension = os.path.splitext(output_file)[1]
        fileformat = filters.guess_export_plugin(extension)
        if fileformat:
            saver = filters.find_export_plugin(fileformat)
            saver(doc, output_file)
        else:
            sys.stderr.write('ERROR: unrecognized extension %s\n' % extension)
            sys.exit(1)
        doc.Destroy()

    sys.exit(0)
예제 #11
0
	def callback(self):
		self.init_convertor()
		self.send_msgs("Start", "UniConvertor is initialized",0.02)
		
		from app.io import load
		from sk1libs import filters
		import app, time
		
		app.receiver=self.progress_dlg.msg_receiver

		app.init_lib()
		
		self.send_msgs("Start", "Loading plugin configuration",0.03)
		time.sleep(0.3)
		filters.load_plugin_configuration()
		
		input_file=self.file
		output_file=self.file+'.'+self.options[self.combo.get_active()][1]
		
		doc=None
		
		try:
			self.send_msgs("Start", "Parsing document file",0.05)
			doc = load.load_drawing(input_file)
			extension = os.path.splitext(output_file)[1]
			
			self.send_msgs("", "Parsing is completed",1.0)
			
			fileformat = filters.guess_export_plugin(extension)
			
			self.send_msgs("", "Saving translated file",0.5)
			if fileformat:
				
				saver = filters.find_export_plugin(fileformat)
				saver(doc, output_file)
				self.send_msgs("", "Translated file is saved",1.0)
			else:
				self.msg_dialog('\nERROR: unrecognized extension %s\n' % extension, gtk.MESSAGE_WARNING)
		except Exception, value:
			self.msg_dialog("\nAn error occurred: " + str(value), gtk.MESSAGE_WARNING)