Ejemplo n.º 1
0
	def convert(self, *args):
		self.progress_dlg=ConvProgress(self.window, self.callback, self.icon)
		self.progress_dlg.run_dialog("Start", "UniConvertor initialization")
		while gtk.events_pending():
			gtk.main_iteration()
		self.progress_dlg.window.destroy()
		if not self.stand_alone:
			self.destroy()
Ejemplo n.º 2
0
class UniConvw:
	
	file=None
	initialized=False
	stand_alone=False
	icon=None
	
	def __init__(self, icon, options, filetypes, file=None):
		self.icon=icon
		self.options=options
		exit_message=' '+'Cancel'+' '
		if not file is None:
			if os.path.isfile(file): self.file=file
		self.filetypes=filetypes		
		
		#Window creation
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.set_title("UniConvertor")
		self.window.set_icon_from_file(icon)
		self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
		self.window.set_resizable(False)
		
		self.window.connect("delete_event", self.delete_event)
		self.window.connect("destroy", self.destroy)	
		self.window.set_border_width(10)
		
		self.win_box = gtk.VBox(False, 5)
		self.window.add(self.win_box)
		
		self.buttonConvert = gtk.Button(" Convert ")
		
		#Optional file selection
		if self.file is None:
			self.stand_alone=True
			exit_message='  '+'Close'+'  '
			self.buttonConvert.set_sensitive(False)
			
			self.file_hbox = gtk.HBox(False, 5)
			self.win_box.add(self.file_hbox)
			
			
			self.dialog = gtk.FileChooserDialog("Select a file for translation...",
						None,
						gtk.FILE_CHOOSER_ACTION_OPEN,
						(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
							gtk.STOCK_OPEN, gtk.RESPONSE_OK))
			self.dialog.set_default_response(gtk.RESPONSE_OK)
			
			#All supported formats filter
			filter = gtk.FileFilter()
			filter.set_name('All supported formats (*.cdr, *cmx, *.ccx, *.ai, *.svg etc.)')			
			for item in filetypes:
				filter.add_pattern(item[1])
			self.dialog.add_filter(filter)
				
			#Fiter per each format
			for item in filetypes:
				filter = gtk.FileFilter()
				filter.set_name(item[0])
				filter.add_pattern(item[1])
				self.dialog.add_filter(filter)
				
			#All files filter
			filter = gtk.FileFilter()
			filter.set_name('All files (*.*)')
			filter.add_pattern('*')
			self.dialog.add_filter(filter)
			
			self.filechooserbutton = gtk.FileChooserButton(self.dialog)
			self.filechooserbutton.set_current_folder('/home/igor')
			self.filechooserbutton.connect("file-set", self.file_changed)
			self.file_hbox.pack_end(self.filechooserbutton, expand=True, fill=True, padding=0)
			
			self.file_label=gtk.Label("File:")
			self.file_hbox.pack_end(self.file_label, expand=False, fill=False, padding=0)
			
			self.file_label.show()
			self.file_hbox.show()
			self.filechooserbutton.show()
		
		#ComboBox creation
		self.frame=gtk.Frame(" Convert to: ")
		self.win_box.add(self.frame)
		
		self.cb_vbox = gtk.VBox(False, 5)
		self.frame.add(self.cb_vbox)
		
		self.cb_hbox = gtk.HBox(False, 5)
		self.cb_vbox.pack_start(self.cb_hbox, expand=False, fill=True, padding=10)
		
		self.combo=gtk.combo_box_new_text()
		for item in self.options:
			self.combo.append_text(item[0])
		self.combo.set_active(1)
		self.cb_hbox.pack_start(self.combo, expand=False, fill=True, padding=10)
		
		#Buttons
		self.buttons_box = gtk.HBox(False, 10)
		self.win_box.add(self.buttons_box)
		
		self.buttonExit = gtk.Button(exit_message)
		self.buttonExit.connect_object("clicked", gtk.Widget.destroy, self.window)
		self.buttons_box.pack_end(self.buttonExit, expand=False, fill=False, padding=0)

		
		self.buttonConvert.connect("clicked", self.convert)
		self.buttons_box.pack_end(self.buttonConvert, expand=False, fill=False, padding=0)
		
		#App label
		self.label_box = gtk.VBox(False, 0)
		self.buttons_box.pack_start(self.label_box, expand=False, fill=True, padding=0)
		
		self.link=gtk.Label("http://sk1project.org")
		self.link.set_sensitive(False)
		self.label_box.pack_end(self.link, expand=False, fill=False, padding=0)		
		
			

		self.link.show()
		self.label_box.show()
		self.combo.show()
		self.buttonExit.show()
		self.buttonConvert.show()
		self.buttons_box.show()
		self.cb_hbox.show()
		self.cb_vbox.show()
		self.frame.show()
		self.win_box.show()
		self.window.show()

		
	def init_convertor(self):
		if not self.initialized:
			from uniconvertor import init_uniconv
			init_uniconv()
			self.initialized=True	
		
	def file_changed(self, *args):
		file=self.dialog.get_filename()
		if os.path.isfile(file):
			self.file=file
			self.buttonConvert.set_sensitive(True)
		
	def convert(self, *args):
		self.progress_dlg=ConvProgress(self.window, self.callback, self.icon)
		self.progress_dlg.run_dialog("Start", "UniConvertor initialization")
		while gtk.events_pending():
			gtk.main_iteration()
		self.progress_dlg.window.destroy()
		if not self.stand_alone:
			self.destroy()
		
	def send_msgs(self,msg1,msg2,val):
		while gtk.events_pending():
			gtk.main_iteration()
		self.progress_dlg.msg_receiver(msg1,msg2,val)
		
	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)
		finally:
Ejemplo n.º 3
0
class UniConvw:

    file = None
    initialized = False
    stand_alone = False
    icon = None
    window = None
    initialdir = ''
    app_ver = ''

    def __init__(self, icon, options, filetypes, file=None, app_ver=None):
        self.icon = icon
        self.options = options
        self.encoding = sys.getfilesystemencoding()
        if self.encoding is None:
            self.encoding = sys.getdefaultencoding()
        if not app_ver is None:
            self.app_ver = app_ver

        exit_message = 'Cancel'
        if not file is None:
            if os.path.isfile(file): self.file = file
        self.filetypes = filetypes

        self.window = Tkinter.Tk()
        self.window.withdraw()
        self.window.title('UniConvertor ' + self.app_ver)
        self.window.tk.call('wm', 'iconbitmap', self.window, self.icon)

        self.win_panel = TFrame(self.window, borderwidth=10)
        self.win_panel.pack(side=TOP, fill=Tkinter.BOTH, expand=1)

        #File selection
        file_panel = TFrame(self.win_panel)

        label = TLabel(file_panel, text='File: ')
        label.pack(side=LEFT, padx=5)

        self.file_button = TButton(file_panel,
                                   text='...',
                                   command=self.openFile,
                                   width=0)
        self.file_button.pack(side=RIGHT)

        self.file_reference = StringVar(self.window)
        self.file_reference.set('<None>')

        self.file_entry = TEntry(file_panel,
                                 text='<None>',
                                 state='readonly',
                                 textvariable=self.file_reference)
        self.file_entry.pack(side=RIGHT, fill=X, expand=1)

        if self.file is None:
            file_panel.pack(side=TOP, fill=X)
            self.stand_alone = True

        #Formats
        label = TLabel(self.win_panel, text=' Convert to: ')
        label.pack(side=TOP, padx=5)

        format_frame = TLabelframe(self.win_panel,
                                   labelwidget=label,
                                   borderwidth=2)
        format_frame.pack(side=TOP, fill=Tkinter.X, expand=1, pady=2)

        formats = []
        for item in self.options:
            formats.append(item[0])

        self.format_reference = StringVar(self.window)
        self.format_reference.set(self.options[1][0])

        self.format_combo = TCombobox(format_frame,
                                      values=formats,
                                      width=50,
                                      state='readonly',
                                      textvariable=self.format_reference)
        self.format_combo.pack(expand=1, padx=10, pady=10)

        #Buttons
        button_panel = TFrame(self.win_panel)
        button_panel.pack(side=BOTTOM, fill=X, expand=1, pady=5)

        self.but_close = TButton(button_panel,
                                 text='Cancel',
                                 width=10,
                                 command=self.close)
        self.but_close.pack(side=RIGHT)

        self.but_convert = TButton(button_panel,
                                   text='Convert',
                                   width=10,
                                   command=self.convert)
        self.but_convert.pack(side=RIGHT, padx=10)
        if self.file is None:
            self.but_convert['state'] = 'disabled'
            self.but_close['text'] = 'Close'

        label = TLabel(button_panel,
                       text='http://sk1project.org',
                       state='disabled')
        label.pack(side=LEFT, anchor='sw')

        self.window.resizable(False, False)
        self.set_position()
        self.window.deiconify()

    def convert(self):
        self.progress_dlg = ConvProgress(self.window, self.callback, self.icon)
        self.progress_dlg.run_dialog()
        if not self.stand_alone:
            self.close()

    def init_convertor(self):
        if not self.initialized:
            from uniconvertor import init_uniconv
            init_uniconv()
            self.initialized = True

    def get_format(self):
        format = self.format_reference.get()
        for item in self.options:
            if item[0] == format: format = item[1]
        return format

    def callback(self):
        self.init_convertor()
        self.send_msgs("Start", "UniConvertor is initialized", 2)

        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", 3)
        filters.load_plugin_configuration()

        input_file = self.file
        output_file = self.file + '.' + self.get_format()

        doc = None

        try:
            self.send_msgs("Start", "Parsing document file", 5)
            doc = load.load_drawing(input_file)
            extension = os.path.splitext(output_file)[1]

            self.send_msgs("", "Parsing is completed", 100)

            fileformat = filters.guess_export_plugin(extension)

            self.send_msgs("", "Saving translated file", 50)
            if fileformat:
                saver = filters.find_export_plugin(fileformat)
                saver(doc, output_file)
                self.send_msgs("", "Translated file is saved", 100)
            else:
                self.msg_dialog('\nERROR: unrecognized extension %s\n' %
                                extension)
        except Exception, value:
            self.msg_dialog("\nAn error occurred: " + str(value))
        finally:
Ejemplo n.º 4
0
 def convert(self):
     self.progress_dlg = ConvProgress(self.window, self.callback, self.icon)
     self.progress_dlg.run_dialog()
     if not self.stand_alone:
         self.close()
Ejemplo n.º 5
0
class UniConvw:
	
	file=None
	initialized=False
	stand_alone=False
	icon=None
	window=None
	initialdir=''
	app_ver=''
	
	def __init__(self, icon, options, filetypes, file=None, app_ver=None):
		self.icon=icon
		self.options=options
		self.encoding=sys.getfilesystemencoding()
		if self.encoding is None:
			self.encoding=sys.getdefaultencoding()
		if not app_ver is None:
			self.app_ver=app_ver
		
		exit_message='Cancel'
		if not file is None:
			if os.path.isfile(file): self.file=file
		self.filetypes=filetypes
		
		self.window=Tkinter.Tk()
		self.window.withdraw()
		self.window.title('UniConvertor '+self.app_ver)
		self.window.tk.call('wm', 'iconbitmap', self.window, self.icon)
		
		self.win_panel=TFrame(self.window, borderwidth=10)
		self.win_panel.pack(side=TOP, fill=Tkinter.BOTH, expand=1)
		
		#File selection
		file_panel=TFrame(self.win_panel)
		
		label=TLabel(file_panel, text='File: ')
		label.pack(side = LEFT, padx=5)
		
		self.file_button=TButton(file_panel, text='...', command=self.openFile, width=0)
		self.file_button.pack(side=RIGHT)
		
		self.file_reference = StringVar(self.window)
		self.file_reference.set('<None>')
		
		self.file_entry=TEntry(file_panel, text='<None>', state='readonly', textvariable=self.file_reference)
		self.file_entry.pack(side=RIGHT, fill=X, expand=1)
		
		if self.file is None:
			file_panel.pack(side = TOP, fill=X)
			self.stand_alone=True				
		
		#Formats
		label=TLabel(self.win_panel, text=' Convert to: ')
		label.pack(side = TOP, padx=5)
		
		format_frame=TLabelframe(self.win_panel, labelwidget=label, borderwidth=2)
		format_frame.pack(side = TOP, fill=Tkinter.X, expand=1, pady=2)
		
		formats=[]
		for item in self.options:
			formats.append(item[0])
			
		self.format_reference = StringVar(self.window)
		self.format_reference.set(self.options[1][0])
		
		self.format_combo=TCombobox(format_frame, values=formats, width=50, state='readonly', textvariable=self.format_reference)
		self.format_combo.pack(expand=1, padx=10, pady=10)		
		
		#Buttons
		button_panel=TFrame(self.win_panel)
		button_panel.pack(side=BOTTOM, fill=X, expand=1, pady=5)
		
		self.but_close=TButton(button_panel, text='Cancel', width=10, command=self.close)
		self.but_close.pack(side=RIGHT)
		
		self.but_convert=TButton(button_panel, text='Convert', width=10, command=self.convert)
		self.but_convert.pack(side=RIGHT, padx=10)
		if self.file is None: 
			self.but_convert['state']='disabled'
			self.but_close['text']='Close'
			
		
		label=TLabel(button_panel, text='http://sk1project.org', state='disabled')
		label.pack(side = LEFT, anchor='sw')
		
		self.window.resizable(False,False)
		self.set_position()
		self.window.deiconify()
		
	def convert(self):
		self.progress_dlg=ConvProgress(self.window, self.callback, self.icon)
		self.progress_dlg.run_dialog()
		if not self.stand_alone:
			self.close()
			
	def init_convertor(self):
		if not self.initialized:
			from uniconvertor import init_uniconv
			init_uniconv()
			self.initialized=True
			
	def get_format(self):
		format=self.format_reference.get()
		for item in self.options:
			if item[0]==format: format=item[1]
		return format
			
	def callback(self):
		self.init_convertor()
		self.send_msgs("Start", "UniConvertor is initialized",2)
		
		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",3)
		filters.load_plugin_configuration()
		
		input_file=self.file
		output_file=self.file+'.'+ self.get_format()
		
		doc=None
		
		try:
			self.send_msgs("Start", "Parsing document file",5)
			doc = load.load_drawing(input_file)
			extension = os.path.splitext(output_file)[1]
			
			self.send_msgs("", "Parsing is completed",100)
			
			fileformat = filters.guess_export_plugin(extension)
			
			self.send_msgs("", "Saving translated file",50)
			if fileformat:				
				saver = filters.find_export_plugin(fileformat)
				saver(doc, output_file)
				self.send_msgs("", "Translated file is saved",100)
			else:
				self.msg_dialog('\nERROR: unrecognized extension %s\n' % extension)
		except Exception, value:
			self.msg_dialog("\nAn error occurred: " + str(value))
		finally:
Ejemplo n.º 6
0
	def convert(self):
		self.progress_dlg=ConvProgress(self.window, self.callback, self.icon)
		self.progress_dlg.run_dialog()
		if not self.stand_alone:
			self.close()