Esempio n. 1
0
	def save_selected(self):
		doc_file = '' + self.current_doc.doc_file
		if not doc_file:
			doc_file = '' + self.current_doc.doc_name
		if not os.path.splitext(doc_file)[1] == "." + \
					uc2const.FORMAT_EXTENSION[uc2const.SK2][0]:
			doc_file = os.path.splitext(doc_file)[0] + "." + \
					uc2const.FORMAT_EXTENSION[uc2const.SK2][0]
		if not os.path.lexists(os.path.dirname(doc_file)):
			doc_file = os.path.join(config.save_dir,
								os.path.basename(doc_file))
		doc_file = dialogs.get_save_file_name(self.mw, self, doc_file,
							_('Save selected objects only as...'),
							path_only=True)
		if doc_file:
			try:
				self.make_backup(doc_file)
				self.current_doc.save_selected(doc_file)
				self.history.add_entry(doc_file, appconst.SAVED)
			except:
				first = _('Cannot save document:')
				msg = ("%s\n'%s'.") % (first, doc_file) + '\n'
				msg += _('Please check requested file format and write permissions')
				dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
				self.print_stacktrace()
Esempio n. 2
0
	def open(self, doc_file='', silent=False):
		if not doc_file:
			doc_file = dialogs.get_open_file_name(self.mw, self, config.open_dir)
		if os.path.lexists(doc_file) and os.path.isfile(doc_file):
			try:
				doc = PD_Presenter(self, doc_file, silent)

			except RuntimeError:
				msg = _('Cannot open file:')
				msg = "%s\n'%s'" % (msg, doc_file) + '\n'
				msg += _('The file contains newer SK2 format.\n')
				msg += _('Try updating sK1 application from http://www.sk1project.net')
				dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
				self.print_stacktrace()
				return
			except:
				msg = _('Cannot open file:')
				msg = "%s\n'%s'" % (msg, doc_file) + '\n'
				msg += _('The file may be corrupted or not supported format')
				dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
				self.print_stacktrace()
				return
			self.docs.append(doc)
			config.open_dir = str(os.path.dirname(doc_file))
			self.history.add_entry(doc_file)
			self.set_current_doc(doc)
			events.emit(events.APP_STATUS, _('Document opened'))
Esempio n. 3
0
	def _action(self, objs):
		doc = self.app.current_doc
		paths = self.get_paths_list(objs)
		doc.canvas.set_temp_mode(modes.WAIT_MODE)
		try:
			result = self.do_action(paths)
		except:
			doc.canvas.restore_mode()
			result = []
			msg = _('Error occurred during this operation.')
			msg += '\n' + _('Perhaps this was due to the imperfection of the algorithm.')
			error_dialog(self.app.mw, self.app.appdata.app_name, msg)
			return

		doc.canvas.restore_mode()
		if result:
			style = deepcopy(objs[0].style)
			doc.api.create_curve(result, style)
		elif not result and self.pid == INTERSECTION_MODE:
			msg = _('Selected objects cannot be intersected.')
			msg_dialog(self.app.mw, self.app.appdata.app_name, msg)
			return

		if self.del_check.get_value():
			objs_list = []
			for obj in objs:
				index = obj.parent.childs.index(obj)
				objs_list.append([obj, obj.parent, index])
			doc.api.delete_objects(objs_list)
Esempio n. 4
0
 def save_as(self):
     doc_file = '' + self.current_doc.doc_file
     if not doc_file:
         doc_file = '' + self.current_doc.doc_name
     if not os.path.splitext(doc_file)[1] == "." + \
        uc2const.FORMAT_EXTENSION[uc2const.SK2][0]:
         doc_file = os.path.splitext(doc_file)[0] + "." + \
           uc2const.FORMAT_EXTENSION[uc2const.SK2][0]
     if not os.path.lexists(os.path.dirname(doc_file)):
         doc_file = os.path.join(config.save_dir,
                                 os.path.basename(doc_file))
     doc_file = dialogs.get_save_file_name(self.mw, self, doc_file)[0]
     if doc_file:
         old_file = self.current_doc.doc_file
         old_name = self.current_doc.doc_name
         self.current_doc.set_doc_file(doc_file)
         try:
             self.make_backup(doc_file)
             self.current_doc.save()
         except:
             self.current_doc.set_doc_file(old_file, old_name)
             first = _('Cannot save document')
             msg = ("%s '%s'.") % (first, self.current_doc.doc_name) + '\n'
             msg += _('Please check file name and write permissions')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             self.print_stacktrace()
             return False
         config.save_dir = str(os.path.dirname(doc_file))
         self.history.add_entry(doc_file, appconst.SAVED)
         events.emit(events.DOC_SAVED, self.current_doc)
         events.emit(events.APP_STATUS, _('Document saved'))
         return True
     else:
         return False
Esempio n. 5
0
 def apply_action(self):
     if not self.picture:
         return
     doc_file = 'image'
     doc_file = os.path.join(self.config.save_dir, doc_file)
     doc_file = dialogs.get_save_file_name(self.app.mw,
                                           doc_file,
                                           _('Save image as...'),
                                           file_types=[uc2const.PNG],
                                           path_only=True)
     if doc_file:
         try:
             fileptr = fsutils.get_fileptr(doc_file, True)
             fileptr.write(self.picture.getvalue())
             fileptr.close()
         except Exception:
             first = _('Cannot save image:')
             msg = "%s\n'%s'." % (first, doc_file) + '\n'
             msg += _('Please check file name and write permissions')
             dialogs.error_dialog(self.app.mw, self.app.appdata.app_name,
                                  msg)
             return
         self.config.save_dir = str(os.path.dirname(doc_file))
         self.save_config()
         events.emit(events.APP_STATUS, _('Image is successfully saved'))
Esempio n. 6
0
    def _action(self, objs):
        doc = self.app.current_doc
        paths = self.get_paths_list(objs)
        doc.canvas.set_temp_mode(modes.WAIT_MODE)
        try:
            result = self.do_action(paths)
        except:
            doc.canvas.restore_mode()
            result = []
            msg = _('Error occurred during this operation.')
            msg += '\n' + _(
                'Perhaps this was due to the imperfection of the algorithm.')
            error_dialog(self.app.mw, self.app.appdata.app_name, msg)
            return

        doc.canvas.restore_mode()
        if result:
            style = deepcopy(objs[0].style)
            doc.api.create_curve(result, style)
        elif not result and self.pid == INTERSECTION_MODE:
            msg = _('Selected objects cannot be intersected.')
            msg_dialog(self.app.mw, self.app.appdata.app_name, msg)
            return

        if self.del_check.get_value():
            objs_list = []
            for obj in objs:
                index = obj.parent.childs.index(obj)
                objs_list.append([obj, obj.parent, index])
            doc.api.delete_objects(objs_list)
Esempio n. 7
0
 def convert_stroke_to_curve(self):
     doc = self.app.current_doc
     selection = self.app.current_doc.selection
     doc.canvas.set_mode(modes.WAIT_MODE)
     try:
         objs = []
         for obj in selection.objs:
             if obj.is_primitive and not obj.is_pixmap and obj.style[1] \
                     and obj.style[1][1]:
                 pths = libgeom.apply_trafo_to_paths(obj.get_initial_paths(),
                                                     obj.trafo)
                 style = [
                     [sk2const.FILL_EVENODD,
                      sk2const.FILL_SOLID,
                      deepcopy(obj.style[1][2])],
                     [], [], []]
                 pths = libgeom.stroke_to_curve(pths, obj.style[1])
                 objs.append(doc.api.create_curve(pths, style))
                 if obj.cache_arrows:
                     for pair in obj.cache_arrows:
                         [objs.append(doc.api.create_curve(
                             libcairo.get_path_from_cpath(item), style))
                             for item in pair if item]
         selection.set(objs)
         if len(objs) > 1:
             doc.api.group_selected()
     except Exception as e:
         LOG.error('Error in convert_stroke_to_curve(), %s', e)
         doc.canvas.set_mode()
         msg = _('Error occurred during this operation.')
         msg += '\n' + _(
             'Perhaps this was due to the imperfection of the algorithm.')
         error_dialog(self.app.mw, self.app.appdata.app_name, msg)
     doc.canvas.set_mode()
Esempio n. 8
0
	def save_as(self):
		doc_file = '' + self.current_doc.doc_file
		if not doc_file:
			doc_file = '' + self.current_doc.doc_name
		if not os.path.splitext(doc_file)[1] == "." + \
					uc2const.FORMAT_EXTENSION[uc2const.SK2][0]:
			doc_file = os.path.splitext(doc_file)[0] + "." + \
					uc2const.FORMAT_EXTENSION[uc2const.SK2][0]
		if not os.path.lexists(os.path.dirname(doc_file)):
			doc_file = os.path.join(config.save_dir,
								os.path.basename(doc_file))
		doc_file = dialogs.get_save_file_name(self.mw, self, doc_file)[0]
		if doc_file:
			old_file = self.current_doc.doc_file
			old_name = self.current_doc.doc_name
			self.current_doc.set_doc_file(doc_file)
			try:
				self.make_backup(doc_file)
				self.current_doc.save()
			except:
				self.current_doc.set_doc_file(old_file, old_name)
				first = _('Cannot save document')
				msg = ("%s '%s'.") % (first, self.current_doc.doc_name) + '\n'
				msg += _('Please check file name and write permissions')
				dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
				self.print_stacktrace()
				return False
			config.save_dir = str(os.path.dirname(doc_file))
			self.history.add_entry(doc_file, appconst.SAVED)
			events.emit(events.DOC_SAVED, self.current_doc)
			events.emit(events.APP_STATUS, _('Document saved'))
			return True
		else:
			return False
Esempio n. 9
0
 def save_selected(self):
     doc_file = '' + self.current_doc.doc_file
     if not doc_file:
         doc_file = '' + self.current_doc.doc_name
     if not os.path.splitext(doc_file)[1] == "." + \
        uc2const.FORMAT_EXTENSION[uc2const.SK2][0]:
         doc_file = os.path.splitext(doc_file)[0] + "." + \
           uc2const.FORMAT_EXTENSION[uc2const.SK2][0]
     if not os.path.lexists(os.path.dirname(doc_file)):
         doc_file = os.path.join(config.save_dir,
                                 os.path.basename(doc_file))
     doc_file = dialogs.get_save_file_name(
         self.mw,
         self,
         doc_file,
         _('Save selected objects only as...'),
         path_only=True)
     if doc_file:
         try:
             self.make_backup(doc_file)
             self.current_doc.save_selected(doc_file)
             self.history.add_entry(doc_file, appconst.SAVED)
         except:
             first = _('Cannot save document:')
             msg = ("%s\n'%s'.") % (first, doc_file) + '\n'
             msg += _(
                 'Please check requested file format and write permissions')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             self.print_stacktrace()
Esempio n. 10
0
 def export_as(self):
     doc_file = self.current_doc.doc_file
     doc_file = doc_file or self.current_doc.doc_name
     doc_file = os.path.splitext(doc_file)[0]
     doc_file = os.path.join(config.export_dir, os.path.basename(doc_file))
     ftype = uc2const.SAVER_FORMATS[1:]
     doc_file = dialogs.get_save_file_name(self.mw,
                                           doc_file,
                                           _('Export document As...'),
                                           file_types=ftype,
                                           path_only=True)
     if doc_file:
         try:
             self.make_backup(doc_file, True)
             self.current_doc.export_as(doc_file)
         except Exception as e:
             first = _('Cannot save document:')
             msg = "%s\n'%s'." % (first, self.current_doc.doc_name) + '\n'
             msg += _('Please check file name and write permissions')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             LOG.warn('Cannot save file <%s>', doc_file, e)
             return
         config.export_dir = str(os.path.dirname(doc_file))
         msg = _('Document is successfully exported')
         events.emit(events.APP_STATUS, msg)
Esempio n. 11
0
    def open(self, doc_file='', silent=False):
        if not doc_file:
            doc_file = dialogs.get_open_file_name(self.mw, self,
                                                  config.open_dir)
        if os.path.lexists(doc_file) and os.path.isfile(doc_file):
            try:
                doc = PD_Presenter(self, doc_file, silent)

            except RuntimeError:
                msg = _('Cannot open file:')
                msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                msg += _('The file contains newer SK2 format.\n')
                msg += _(
                    'Try updating sK1 application from http://www.sk1project.net'
                )
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                self.print_stacktrace()
                return
            except:
                msg = _('Cannot open file:')
                msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                msg += _('The file may be corrupted or not supported format')
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                self.print_stacktrace()
                return
            self.docs.append(doc)
            config.open_dir = str(os.path.dirname(doc_file))
            self.history.add_entry(doc_file)
            self.set_current_doc(doc)
            events.emit(events.APP_STATUS, _('Document opened'))
Esempio n. 12
0
    def import_palette(self, parent=None):
        parent = parent or self.mw
        file_types = uc2const.PALETTE_LOADERS
        doc_file = dialogs.get_open_file_name(parent,
                                              config.import_dir,
                                              _('Select palette to import'),
                                              file_types=file_types)
        if fsutils.lexists(doc_file) and fsutils.isfile(doc_file):

            pd = dialogs.ProgressDialog(_('Opening file...'), parent)
            try:
                loader = get_loader(doc_file)
                if not loader:
                    raise IOError(_('Loader is not found for <%s>') % doc_file)
                palette = pd.run(loader,
                                 [self.appdata, doc_file, None, False, True])
                if not palette:
                    raise IOError(_('Error while opening'), doc_file)
                self.palettes.add_palette(palette)
                config.import_dir = str(os.path.dirname(doc_file))
                msg = _('Palette is successfully imported')
                events.emit(events.APP_STATUS, msg)
                return palette.model.name
            except Exception as e:
                msg = _('Cannot import file:')
                msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                msg += _('The file may be corrupted or not supported format.')
                msg += '\n'
                msg += _('Details see in application logs.')
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                LOG.error('Cannot import file <%s> %s', doc_file, e)
            finally:
                pd.destroy()
Esempio n. 13
0
 def save_as(self):
     doc_file = self.current_doc.doc_file
     doc_file = doc_file or self.current_doc.doc_name
     if os.path.splitext(doc_file)[1] != "." + \
             uc2const.FORMAT_EXTENSION[uc2const.SK2][0]:
         doc_file = os.path.splitext(doc_file)[0] + "." + \
                    uc2const.FORMAT_EXTENSION[uc2const.SK2][0]
     if not fsutils.lexists(os.path.dirname(doc_file)):
         doc_file = os.path.join(config.save_dir,
                                 os.path.basename(doc_file))
     doc_file = dialogs.get_save_file_name(self.mw,
                                           doc_file,
                                           path_only=True)
     if doc_file:
         old_file = self.current_doc.doc_file
         old_name = self.current_doc.doc_name
         self.current_doc.set_doc_file(doc_file)
         try:
             self.make_backup(doc_file)
             self.current_doc.save()
         except Exception as e:
             self.current_doc.set_doc_file(old_file, old_name)
             first = _('Cannot save document:')
             msg = "%s\n'%s'." % (first, self.current_doc.doc_name) + '\n'
             msg += _('Please check file name and write permissions')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             LOG.error('Cannot save file <%s> %s', doc_file, e)
             return False
         config.save_dir = str(os.path.dirname(doc_file))
         self.history.add_entry(doc_file, appconst.SAVED)
         events.emit(events.DOC_SAVED, self.current_doc)
         events.emit(events.APP_STATUS, _('Document saved'))
         return True
     else:
         return False
Esempio n. 14
0
 def save_selected(self):
     doc_file = self.current_doc.doc_file
     doc_file = doc_file or self.current_doc.doc_name
     if os.path.splitext(doc_file)[1] != "." + \
             uc2const.FORMAT_EXTENSION[uc2const.SK2][0]:
         doc_file = os.path.splitext(doc_file)[0] + "." + \
                    uc2const.FORMAT_EXTENSION[uc2const.SK2][0]
     if not fsutils.lexists(os.path.dirname(doc_file)):
         doc_file = os.path.join(config.save_dir,
                                 os.path.basename(doc_file))
     msg = _('Save selected objects only as...')
     doc_file = dialogs.get_save_file_name(self.mw,
                                           doc_file,
                                           msg,
                                           path_only=True)
     if doc_file:
         try:
             self.make_backup(doc_file)
             self.current_doc.save_selected(doc_file)
             self.history.add_entry(doc_file, appconst.SAVED)
         except Exception as e:
             first = _('Cannot save document:')
             msg = "%s\n'%s'." % (first, doc_file) + '\n'
             msg += _('Please check requested file format '
                      'and write permissions')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             LOG.error('Cannot save file <%s> %s', doc_file, e)
Esempio n. 15
0
 def export_as(self):
     doc_file = '' + self.current_doc.doc_file
     if not doc_file:
         doc_file = '' + self.current_doc.doc_name
     doc_file = os.path.splitext(doc_file)[0]
     doc_file = os.path.join(config.export_dir, os.path.basename(doc_file))
     doc_file = dialogs.get_save_file_name(self.mw,
                                           self,
                                           doc_file,
                                           _('Export document As...'),
                                           file_types=SAVER_FORMATS[1:],
                                           path_only=True)
     if doc_file:
         try:
             self.make_backup(doc_file, True)
             self.current_doc.export_as(doc_file)
         except:
             first = _('Cannot save document:')
             msg = ("%s\n'%s'.") % (first, self.current_doc.doc_name) + '\n'
             msg += _('Please check file name and write permissions')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             self.print_stacktrace()
             return
         config.export_dir = str(os.path.dirname(doc_file))
         events.emit(events.APP_STATUS,
                     _('Document is successfully exported'))
Esempio n. 16
0
    def open(self, doc_file='', silent=False):
        doc_file = doc_file or \
                   dialogs.get_open_file_name(self.mw, config.open_dir)
        if doc_file and fsutils.lexists(doc_file) and fsutils.isfile(doc_file):
            try:
                doc = SK1Presenter(self, doc_file, silent)

            except RuntimeError:
                msg = _('Cannot open file:')
                msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                msg += _('The file contains newer SK2 format.\n')
                msg += _('Try updating sK1 application from '
                         'http://www.sk1project.net')
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                LOG.error('Cannot open file <%s>: newer SK2 format.', doc_file)
                return
            except Exception as e:
                msg = _('Cannot open file:')
                msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                msg += _('The file may be corrupted or not supported format.')
                msg += '\n'
                msg += _('Details see in application logs.')
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                LOG.error('Cannot open file <%s> %s', doc_file, e)
                return
            self.docs.append(doc)
            config.open_dir = str(os.path.dirname(doc_file))
            self.history.add_entry(doc_file)
            self.set_current_doc(doc)
            events.emit(events.APP_STATUS, _('Document opened'))
Esempio n. 17
0
    def save(self, doc=''):
        if not doc:
            doc = self.current_doc
        if not doc.doc_file:
            return self.save_as()
        ext = os.path.splitext(self.current_doc.doc_file)[1]
        if not ext == "." + uc2const.FORMAT_EXTENSION[uc2const.SK2][0]:
            return self.save_as()
        if not os.path.lexists(os.path.dirname(self.current_doc.doc_file)):
            return self.save_as()

        try:
            self.make_backup(self.current_doc.doc_file)
            doc.save()
            self.history.add_entry(self.current_doc.doc_file, appconst.SAVED)
            events.emit(events.DOC_SAVED, doc)
        except:
            msg = _('Cannot save file:')
            msg = "%s\n'%s'" % (msg, self.current_doc.doc_file) + '\n'
            msg += _('Please check file write permissions')
            dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
            self.print_stacktrace()
            return False
        events.emit(events.APP_STATUS, _('Document saved'))
        return True
Esempio n. 18
0
	def save(self, doc=''):
		if not doc:
			doc = self.current_doc
		if not doc.doc_file:
			return self.save_as()
		ext = os.path.splitext(self.current_doc.doc_file)[1]
		if not ext == "." + uc2const.FORMAT_EXTENSION[uc2const.SK2][0]:
			return self.save_as()
		if not os.path.lexists(os.path.dirname(self.current_doc.doc_file)):
			return self.save_as()

		try:
			self.make_backup(self.current_doc.doc_file)
			doc.save()
			self.history.add_entry(self.current_doc.doc_file, appconst.SAVED)
			events.emit(events.DOC_SAVED, doc)
		except:
			msg = _('Cannot save file')
			msg = "%s '%s'" % (msg, self.current_doc.doc_file) + '\n'
			msg += _('Please check file write permissions')
			dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
			self.print_stacktrace()
			return False
		events.emit(events.APP_STATUS, _('Document saved'))
		return True
Esempio n. 19
0
    def import_file(self, doc_file=None, point=None):
        msg = _('Select file to import')
        if not doc_file:
            doc_file = dialogs.get_open_file_name(self.mw,
                                                  config.import_dir, msg)
        if doc_file and fsutils.isfile(doc_file):
            try:
                ret = self.current_doc.import_file(doc_file)
                if not ret:
                    msg = _('Cannot import graphics from file:')
                    msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                    msg += _('It seems the document is empty or '
                             'contains unsupported objects.')
                    dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                    LOG.warn('Cannot import graphics from file <%s>', doc_file)
                elif point and self.current_doc.selection.bbox:
                    x0, y0 = self.current_doc.canvas.win_to_doc(point)
                    x1 = self.current_doc.selection.bbox[0]
                    y1 = self.current_doc.selection.bbox[-1]
                    dx = x0 - x1
                    dy = y0 - y1
                    self.current_doc.api.move_selected(dx, dy)

                config.import_dir = str(os.path.dirname(doc_file))
            except Exception as e:
                msg = _('Cannot import file:')
                msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                msg += _('The file may be corrupted or not supported format')
                msg += '\n'
                msg += _('Details see in application logs.')
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                LOG.warn('Cannot import file <%s>', doc_file, e)
Esempio n. 20
0
	def export_as(self):
		doc_file = '' + self.current_doc.doc_file
		if not doc_file:
			doc_file = '' + self.current_doc.doc_name
		if os.path.splitext(doc_file)[1] == "." + \
					uc2const.FORMAT_EXTENSION[uc2const.SK2][0]:
			doc_file = os.path.splitext(doc_file)[0] + "." + \
					uc2const.FORMAT_EXTENSION[uc2const.PNG][0]
		doc_file = os.path.join(config.export_dir,
								os.path.basename(doc_file))
		doc_file = dialogs.get_save_file_name(self.mw, self, doc_file,
							_('Export document As...'),
							file_types=data.SAVER_FORMATS[1:])[0]
		if doc_file:
			try:
				self.make_backup(doc_file, True)
				self.current_doc.export_as(doc_file)
			except:
				first = _('Cannot save document')
				msg = ("%s '%s'.") % (first, self.current_doc.doc_name) + '\n'
				msg += _('Please check file name and write permissions')
				dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
				self.print_stacktrace()
				return
			config.export_dir = str(os.path.dirname(doc_file))
			events.emit(events.APP_STATUS, _('Document is successfully exported'))
Esempio n. 21
0
 def convert_stroke_to_curve(self):
     doc = self.app.current_doc
     selection = self.app.current_doc.selection
     doc.canvas.set_mode(modes.WAIT_MODE)
     try:
         objs = []
         for obj in selection.objs:
             if obj.is_primitive() and not obj.is_pixmap() and obj.style[1] \
             and obj.style[1][1]:
                 pths = apply_trafo_to_paths(obj.get_initial_paths(),
                                             obj.trafo)
                 style = doc.model.get_def_style()
                 style[0] = [
                     sk2_const.FILL_SOLID,
                     deepcopy(obj.style[1][2])
                 ]
                 pths = stroke_to_curve(pths, obj.style[1])
                 objs.append(doc.api.create_curve(pths, style))
         selection.set(objs)
     except:
         doc.canvas.set_mode()
         msg = _('Error occurred during this operation.')
         msg += '\n' + _(
             'Perhaps this was due to the imperfection of the algorithm.')
         error_dialog(self.app.mw, self.app.appdata.app_name, msg)
     doc.canvas.set_mode()
Esempio n. 22
0
    def __init__(self, path, cfgdir):

        self.path = path

        wal.Application.__init__(self)
        UCApplication.__init__(self, path, cfgdir, False)

        if wal.IS_WINXP:
            msg = _('WindowsXP platform is obsolete and not supported!')
            dialogs.error_dialog(self.mw, 'sK1', msg)
            sys.exit()

        self.appdata = AppData(self, cfgdir)
        log_level = config.log_level
        self.log_filepath = os.path.join(self.appdata.app_config_dir,
                                         'sk1.log')
        mixutils.config_logging(fsutils.get_sys_path(self.log_filepath),
                                log_level)
        sys.stderr = StreamLogger()
        LOG.info('Logging started')

        wal.SPIN['overlay'] = config.spin_overlay
        wal.SPIN['sep'] = config.spin_sep

        plg_dir = os.path.join(self.path, 'share', 'pd_plugins')
        custom_plg_dir = self.appdata.plugin_dir
        config.plugin_dirs = [plg_dir, custom_plg_dir]
        sys.path.insert(1, fsutils.get_sys_path(self.appdata.app_config_dir))
        sys.path.insert(1,
                        fsutils.get_sys_path(os.path.join(self.path, 'share')))
        config.app = self
        LOG.info('Config is updated')

        self.history = AppHistoryManager(self)

        self.artprovider = create_artprovider()
        self.cursors = modes.get_cursors()

        self.proxy = AppProxy(self)
        self.insp = AppInspector(self)
        self.plugins = app_plugins.scan_plugins(self)
        self.actions = app_actions.create_actions(self)

        self.default_cms = AppColorManager(self)
        self.palettes = AppPaletteManager(self)
        self.clipboard = AppClipboard(self)

        self.mw = AppMainWindow(self)
        self.mw.set_global_shortcuts(self.actions)

        self.proxy.update()
        self.insp.update()
        LOG.info('Application is initialized')
        uc2.events.connect(uc2.events.MESSAGES, self.uc2_event_logging)
        events.connect(events.APP_STATUS, self.sk1_event_logging)
        self.fsw = AppFileWatcher(self, self.mw)

        if wal.IS_WX2:
            events.emit(events.NO_DOCS)
Esempio n. 23
0
    def __init__(self, path, cfgdir='~'):

        self.path = path

        wal.Application.__init__(self)
        UCApplication.__init__(self, path, cfgdir)

        if wal.IS_WINXP:
            msg = _('WindowsXP platform is obsolete and not supported!')
            dialogs.error_dialog(self.mw, 'sK1', msg)
            sys.exit()

        self.appdata = AppData(self, cfgdir)
        config.load(self.appdata.app_config)
        config.resource_dir = os.path.join(path_unicode(self.path), 'share')
        log_level = config.log_level
        self.log_filepath = os.path.join(self.appdata.app_config_dir,
                                         'sk1.log')
        config_logging(self.log_filepath, log_level)
        sys.stderr = StreamLogger()
        LOG.info('Logging started')

        self.update_wal()
        plg_dir = os.path.join(self.path, 'share', 'pd_plugins')
        custom_plg_dir = self.appdata.plugin_dir
        config.plugin_dirs = [plg_dir, custom_plg_dir]
        sys.path.insert(1, self.appdata.app_config)
        sys.path.insert(1, os.path.join(self.path, 'share'))
        config.app = self
        LOG.info('Config is updated')

        self.history = AppHistoryManager(self)

        self.artprovider = create_artprovider()
        self.cursors = modes.get_cursors()

        self.proxy = AppProxy(self)
        self.insp = AppInspector(self)
        self.plugins = app_plugins.scan_plugins(self)
        self.actions = app_actions.create_actions(self)

        self.default_cms = AppColorManager(self)
        self.palettes = AppPaletteManager(self)
        self.clipboard = AppClipboard(self)

        self.mw = AppMainWindow(self)
        self.mw.set_global_shortcuts(self.actions)

        self.proxy.update()
        self.insp.update()
        LOG.info('Application is initialized')
        uc2.events.connect(uc2.events.MESSAGES, self.uc2_event_logging)
        events.connect(events.APP_STATUS, self.sk1_event_logging)

        if wal.IS_WX2:
            events.emit(events.NO_DOCS)
        if config.make_font_cache_on_start:
            generate_fcache()
Esempio n. 24
0
	def run_printdlg(self, win, printout):
		pd = ProgressDialog(_('Printing...'), win)
		ret = pd.run(self.printing, [printout, ], save_result=False)
		pd.destroy()
		if not ret:
			msg = _('Error while printing!')
			error_dialog(win, win.app.appdata.app_name, msg)
			return False
		return True
Esempio n. 25
0
 def run_printdlg(self, win, printout):
     pd = ProgressDialog(_('Printing...'), win)
     ret = pd.run(self.printing, [
         printout,
     ], save_result=False)
     pd.destroy()
     if not ret:
         msg = _('Error while printing!')
         error_dialog(win, win.app.appdata.app_name, msg)
         return False
     return True
Esempio n. 26
0
 def run_printdlg(self, win, printout):
     pd = ProgressDialog(_('Printing...'), win)
     try:
         pd.run(self.printing, [printout, ])
         pd.listener(_('Done'), 1.0)
     except Exception:
         msg = _('Error while printing!')
         error_dialog(win, win.app.appdata.app_name, msg)
         return False
     finally:
         pd.destroy()
     return True
Esempio n. 27
0
 def print_calibration(self, app, win, path, media=''):
     pd = ProgressDialog(_('Loading calibration page...'), win)
     try:
         loader = get_loader(path)
         doc_presenter = pd.run(loader, [app.appdata, path])
         self.run_printdlg(win, Printout(doc_presenter))
     except Exception:
         txt = _('Error while printing of calibration page!')
         txt += '\n' + _('Check your printer status and connection.')
         error_dialog(win, app.appdata.app_name, txt)
     finally:
         pd.destroy()
Esempio n. 28
0
 def new_from_template(self):
     msg = _('Select Template')
     doc_file = dialogs.get_open_file_name(self.mw, config.template_dir, msg)
     if fsutils.isfile(doc_file):
         try:
             doc = SK1Presenter(self, doc_file, template=True)
         except Exception as e:
             msg = _('Cannot parse file:')
             msg = "%s\n'%s'" % (msg, doc_file) + '\n'
             msg += _('The file may be corrupted or not supported format')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             LOG.error('Cannot parse file <%s> %s', doc_file, e)
             return
         self.docs.append(doc)
         config.template_dir = str(os.path.dirname(doc_file))
         self.set_current_doc(doc)
         events.emit(events.APP_STATUS, _('New document from template'))
Esempio n. 29
0
	def import_file(self):
		doc_file = dialogs.get_open_file_name(self.mw, self, config.import_dir,
											_('Select file to import'))
		if os.path.lexists(doc_file) and os.path.isfile(doc_file):
			try:
				ret = self.current_doc.import_file(doc_file)
				if not ret:
					msg = _('Cannot import graphics from file:')
					msg = "%s\n'%s'" % (msg, doc_file) + '\n'
					msg += _('It seems the document is empty or contains unsupported objects.')
					dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
				config.import_dir = str(os.path.dirname(doc_file))
			except:
				msg = _('Cannot import file')
				msg = "%s '%s'" % (msg, doc_file) + '\n'
				msg += _('The file may be corrupted or not supported format')
				dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
				self.print_stacktrace()
Esempio n. 30
0
 def new_from_template(self):
     msg = _('Select Template')
     doc_file = dialogs.get_open_file_name(self.mw, self,
                                           config.template_dir, msg)
     if os.path.lexists(doc_file) and os.path.isfile(doc_file):
         try:
             doc = PD_Presenter(self, doc_file, template=True)
         except:
             msg = _('Cannot parse file:')
             msg = "%s\n'%s'" % (msg, doc_file) + '\n'
             msg += _('The file may be corrupted or not supported format')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             self.print_stacktrace()
             return
         self.docs.append(doc)
         config.template_dir = str(os.path.dirname(doc_file))
         self.set_current_doc(doc)
         events.emit(events.APP_STATUS, _('New document from template'))
Esempio n. 31
0
	def new_from_template(self):
		msg = _('Select Template')
		doc_file = dialogs.get_open_file_name(self.mw, self,
								config.template_dir, msg)
		if os.path.lexists(doc_file) and os.path.isfile(doc_file):
			try:
				doc = PD_Presenter(self, doc_file, template=True)
			except:
				msg = _('Cannot parse file')
				msg = "%s '%s'" % (msg, doc_file) + '\n'
				msg += _('The file may be corrupted or not supported format')
				dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
				self.print_stacktrace()
				return
			self.docs.append(doc)
			config.template_dir = str(os.path.dirname(doc_file))
			self.set_current_doc(doc)
			events.emit(events.APP_STATUS, _('New document from template'))
Esempio n. 32
0
    def __init__(self, path, cfgdir='~'):

        self.path = path

        wal.Application.__init__(self)
        UCApplication.__init__(self, path, cfgdir)

        if wal.is_winxp():
            msg = _('WindowsXP platform is obsolete and not supported!')
            dialogs.error_dialog(self.mw, 'sK1', msg)
            sys.exit()

        self.appdata = AppData(self, cfgdir)
        config.load(self.appdata.app_config)
        config.resource_dir = os.path.join(path_unicode(self.path), 'share')
        self.update_wal()
        plg_dir = os.path.join(self.path, 'share', 'pd_plugins')
        custom_plg_dir = self.appdata.plugin_dir
        config.plugin_dirs = [plg_dir, custom_plg_dir]
        sys.path.insert(1, self.appdata.app_config)
        sys.path.insert(1, os.path.join(self.path, 'share'))
        config.app = self

        self.history = AppHistoryManager(self)

        self.artprovider = create_artprovider()
        self.cursors = modes.get_cursors()

        self.proxy = AppProxy(self)
        self.insp = AppInspector(self)
        self.plugins = app_plugins.scan_plugins(self)
        self.actions = app_actions.create_actions(self)

        self.default_cms = AppColorManager(self)
        self.palettes = AppPaletteManager(self)
        self.clipboard = AppClipboard(self)

        self.mw = AppMainWindow(self)
        self.mw.set_global_shortcuts(self.actions)

        self.proxy.update()
        self.insp.update()
        if wal.is_wx2(): events.emit(events.NO_DOCS)
        if config.make_font_cache_on_start: generate_fcache()
Esempio n. 33
0
	def __init__(self, path, cfgdir='~'):

		self.path = path

		wal.Application.__init__(self)
		UCApplication.__init__(self, path, cfgdir)

		if wal.is_winxp():
			msg = _('WindowsXP platform is obsolete and not supported!')
			dialogs.error_dialog(self.mw, 'sK1', msg)
			sys.exit()

		self.appdata = AppData(self, cfgdir)
		config.load(self.appdata.app_config)
		config.resource_dir = os.path.join(path_unicode(self.path), 'share')
		plg_dir = os.path.join(self.path, 'share', 'pd_plugins')
		custom_plg_dir = self.appdata.plugin_dir
		config.plugin_dirs = [plg_dir, custom_plg_dir]
		sys.path.insert(1, self.appdata.app_config)
		sys.path.insert(1, os.path.join(self.path, 'share'))
		config.app = self

		self.history = AppHistoryManager(self)

		self.artprovider = create_artprovider()
		self.cursors = modes.get_cursors()

		self.proxy = AppProxy(self)
		self.insp = AppInspector(self)
		self.plugins = app_plugins.scan_plugins(self)
		self.actions = app_actions.create_actions(self)

		self.default_cms = AppColorManager(self)
		self.palettes = AppPaletteManager(self)
		self.clipboard = AppClipboard(self)

		self.mw = AppMainWindow(self)
		self.mw.set_global_shortcuts(self.actions)

		self.proxy.update()
		self.insp.update()
		if wal.is_wx2(): events.emit(events.NO_DOCS)
		if config.make_font_cache_on_start: generate_fcache()
Esempio n. 34
0
	def extract_bitmap(self):
		doc_file = 'image.tiff'
		doc_file = os.path.join(config.save_dir, doc_file)
		doc_file = dialogs.get_save_file_name(self.mw, self, doc_file,
							_('Extract selected bitmap as...'),
							file_types=[data.TIF])[0]
		if doc_file:
			try:
				pixmap = self.current_doc.selection.objs[0]
				libimg.extract_bitmap(pixmap, doc_file)
			except:
				first = _('Cannot save document')
				msg = ("%s '%s'.") % (first, self.current_doc.doc_name) + '\n'
				msg += _('Please check file name and write permissions')
				dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
				self.print_stacktrace()
				return
			config.save_dir = str(os.path.dirname(doc_file))
			events.emit(events.APP_STATUS, _('Bitmap is successfully extracted'))
Esempio n. 35
0
    def export_palette(self, palette, parent=None):
        if not parent:
            parent = self.mw
        doc_file = palette.model.name
        doc_file = os.path.splitext(doc_file)[0]
        doc_file = os.path.join(config.export_dir, os.path.basename(doc_file))
        ret = dialogs.get_save_file_name(parent,
                                         doc_file,
                                         _('Export palette as...'),
                                         file_types=uc2const.PALETTE_SAVERS)
        if not ret:
            return
        doc_file, index = ret
        saver_id = uc2const.PALETTE_SAVERS[index]

        if doc_file:
            if not os.path.splitext(doc_file)[1] == "." + \
                   uc2const.FORMAT_EXTENSION[saver_id][0]:
                doc_file = os.path.splitext(doc_file)[0] + "." + \
                           uc2const.FORMAT_EXTENSION[saver_id][0]

            pd = dialogs.ProgressDialog(_('Exporting...'), parent)
            try:
                saver = get_saver_by_id(saver_id)
                if saver is None:
                    msg = _('Unknown file format is requested for export <%s>')
                    raise IOError(msg % doc_file)
                self.make_backup(doc_file, True)
                pd.run(saver, [palette, doc_file, None, False, True])
            except Exception as e:
                msg = _('Cannot export palette:')
                msg = "%s\n'%s'." % (msg, doc_file) + '\n'
                msg += _('Please check file name and write permissions')
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                LOG.error('Cannot save bitmap in <%s>', doc_file, e)
                return
            finally:
                pd.destroy()

            config.export_dir = str(os.path.dirname(doc_file))
            msg = _('Palette is successfully exported')
            events.emit(events.APP_STATUS, msg)
Esempio n. 36
0
 def import_file(self):
     doc_file = dialogs.get_open_file_name(self.mw, self, config.import_dir,
                                           _('Select file to import'))
     if os.path.lexists(doc_file) and os.path.isfile(doc_file):
         try:
             ret = self.current_doc.import_file(doc_file)
             if not ret:
                 msg = _('Cannot import graphics from file:')
                 msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                 msg += _(
                     'It seems the document is empty or contains unsupported objects.'
                 )
                 dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             config.import_dir = str(os.path.dirname(doc_file))
         except:
             msg = _('Cannot import file:')
             msg = "%s\n'%s'" % (msg, doc_file) + '\n'
             msg += _('The file may be corrupted or not supported format')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             self.print_stacktrace()
Esempio n. 37
0
	def import_pattern(self, parent=None):
		if not parent: parent = self.mw
		img_file = dialogs.get_open_file_name(parent, self, config.import_dir,
				_('Select pattern to load'), file_types=data.PATTERN_FORMATS)
		if os.path.lexists(img_file) and os.path.isfile(img_file):
			first = _('Cannot load pattern for')
			msg = ("%s '%s'.") % (first, self.current_doc.doc_name) + '\n'
			msg += _('The file may be corrupted or not supported format')
			try:
				if libimg.check_image(img_file):
					config.import_dir = str(os.path.dirname(img_file))
					return img_file
				else:
					dialogs.error_dialog(parent, self.appdata.app_name, msg)
					self.print_stacktrace()
			except:
				dialogs.error_dialog(parent, self.appdata.app_name, msg)
				self.print_stacktrace()

		return None
Esempio n. 38
0
	def extract_pattern(self, parent, pattern, eps=False):
		img_file = 'image'
		img_file = os.path.join(config.save_dir, img_file)
		file_types = [data.TIF]
		if eps: file_types = [data.EPS]
		img_file = dialogs.get_save_file_name(parent, self, img_file,
							_('Save pattern as...'),
							file_types=file_types, path_only=True)
		if img_file:
			try:
				fobj = open(img_file, 'wb')
				fobj.write(b64decode(pattern))
				fobj.close()
			except:
				first = _('Cannot save pattern from:')
				msg = ("%s\n'%s'.") % (first, self.current_doc.doc_name) + '\n'
				msg += _('Please check file name and write permissions')
				dialogs.error_dialog(parent, self.appdata.app_name, msg)
				self.print_stacktrace()
				return
			config.save_dir = str(os.path.dirname(img_file))
Esempio n. 39
0
 def apply_action(self):
     if not self.picture:
         return
     doc_file = "image"
     doc_file = os.path.join(config.save_dir, doc_file)
     doc_file = dialogs.get_save_file_name(
         self.app.mw, self.app, doc_file, _("Save image as..."), file_types=[data.PNG], path_only=True
     )
     if doc_file:
         try:
             fileptr = open(doc_file, "wb")
             fileptr.write(self.picture.getvalue())
             fileptr.close()
         except:
             first = _("Cannot save image:")
             msg = ("%s\n'%s'.") % (first, doc_file) + "\n"
             msg += _("Please check file name and write permissions")
             dialogs.error_dialog(self.app.mw, self.app.appdata.app_name, msg)
             return
         config.save_dir = str(os.path.dirname(doc_file))
         events.emit(events.APP_STATUS, _("Image is successfully saved"))
Esempio n. 40
0
 def import_pattern(self, parent=None):
     parent = parent or self.mw
     file_types = uc2const.PATTERN_FORMATS
     img_file = dialogs.get_open_file_name(parent,
                                           config.import_dir,
                                           _('Select pattern to load'),
                                           file_types=file_types)
     if os.path.lexists(img_file) and os.path.isfile(img_file):
         first = _('Cannot load pattern for:')
         msg = "%s\n'%s'." % (first, self.current_doc.doc_name) + '\n'
         msg += _('The file may be corrupted or not supported format')
         try:
             if libimg.check_image(img_file):
                 config.import_dir = str(os.path.dirname(img_file))
                 return img_file
             else:
                 dialogs.error_dialog(parent, self.appdata.app_name, msg)
                 LOG.error('Cannot load pattern <%s>', img_file)
         except Exception as e:
             dialogs.error_dialog(parent, self.appdata.app_name, msg)
             LOG.error('Cannot load pattern <%s> %s', img_file, e)
Esempio n. 41
0
    def print_calibration(self, app, win, path, media=''):
        doc_presenter = None
        loader = get_loader(path)

        pd = ProgressDialog(_('Loading calibration page...'), win)
        ret = pd.run(loader, [app.appdata, path])
        if ret and pd.result is not None:
            doc_presenter = pd.result

        if doc_presenter:
            try:
                self.printing(Printout(doc_presenter), media)
            except:
                doc_presenter = None

        pd.destroy()

        if not doc_presenter:
            txt = _('Error while printing of calibration page!')
            txt += '\n' + _('Check your printer status and connection.')
            error_dialog(win, app.appdata.app_name, txt)
Esempio n. 42
0
	def convert_stroke_to_curve(self):
		doc = self.app.current_doc
		selection = self.app.current_doc.selection
		doc.canvas.set_mode(modes.WAIT_MODE)
		try:
			objs = []
			for obj in selection.objs:
				if obj.is_primitive() and not obj.is_pixmap() and obj.style[1] \
				and obj.style[1][1]:
					pths = apply_trafo_to_paths(obj.get_initial_paths(), obj.trafo)
					style = doc.model.get_def_style()
					style[0] = [sk2_const.FILL_SOLID, deepcopy(obj.style[1][2])]
					pths = stroke_to_curve(pths, obj.style[1])
					objs.append(doc.api.create_curve(pths, style))
			selection.set(objs)
		except:
			doc.canvas.set_mode()
			msg = _('Error occurred during this operation.')
			msg += '\n' + _('Perhaps this was due to the imperfection of the algorithm.')
			error_dialog(self.app.mw, self.app.appdata.app_name, msg)
		doc.canvas.set_mode()
Esempio n. 43
0
	def print_calibration(self, app, win, path, media=''):
		doc_presenter = None
		loader = get_loader(path)

		pd = ProgressDialog(_('Loading calibration page...'), win)
		ret = pd.run(loader, [app.appdata, path])
		if ret and not pd.result is None:
			doc_presenter = pd.result

		pd.destroy()

		if doc_presenter:
			try:
				self.run_printdlg(win, Printout(doc_presenter))
			except:
				doc_presenter = None

		if not doc_presenter:
			txt = _('Error while printing of calibration page!')
			txt += '\n' + _('Check your printer status and connection.')
			error_dialog(win, app.appdata.app_name, txt)
Esempio n. 44
0
 def extract_bitmap(self):
     doc_file = 'image'
     doc_file = os.path.join(config.save_dir, doc_file)
     msg = _('Extract selected bitmap as...')
     doc_file = dialogs.get_save_file_name(self.mw, doc_file, msg,
                                           file_types=[uc2const.PNG],
                                           path_only=True)
     if doc_file:
         try:
             pixmap = self.current_doc.selection.objs[0]
             pixmap.handler.extract_bitmap(doc_file)
         except Exception as e:
             first = _('Cannot save bitmap:')
             msg = "%s\n'%s'." % (first, doc_file) + '\n'
             msg += _('Please check file name and write permissions')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             LOG.warn('Cannot save bitmap in <%s>', doc_file, e)
             return
         config.save_dir = str(os.path.dirname(doc_file))
         events.emit(events.APP_STATUS,
                     _('Bitmap is successfully extracted'))
Esempio n. 45
0
 def extract_pattern(self, parent, pattern, eps=False):
     img_file = 'image'
     img_file = os.path.join(config.save_dir, img_file)
     file_types = [uc2const.EPS] if eps else [uc2const.TIF]
     img_file = dialogs.get_save_file_name(parent, img_file,
                                           _('Save pattern as...'),
                                           file_types=file_types,
                                           path_only=True)
     if img_file:
         try:
             fobj = fsutils.get_fileptr(img_file, True)
             fobj.write(b64decode(pattern))
             fobj.close()
         except Exception as e:
             first = _('Cannot save pattern from:')
             msg = "%s\n'%s'." % (first, self.current_doc.doc_name) + '\n'
             msg += _('Please check file name and write permissions')
             dialogs.error_dialog(parent, self.appdata.app_name, msg)
             LOG.error('Cannot save pattern in <%s> %s', img_file, e)
             return
         config.save_dir = str(os.path.dirname(img_file))
Esempio n. 46
0
    def import_palette(self, parent=None):
        if not parent: parent = self.mw
        doc_file = dialogs.get_open_file_name(parent,
                                              self,
                                              config.import_dir,
                                              _('Select palette to import'),
                                              file_types=PALETTE_LOADERS)
        if os.path.lexists(doc_file) and os.path.isfile(doc_file):
            try:
                palette = None
                loader = get_loader(doc_file)
                pd = dialogs.ProgressDialog(_('Opening file...'), parent)
                ret = pd.run(loader,
                             [self.appdata, doc_file, None, False, True])
                if ret:
                    if pd.result is None:
                        pd.destroy()
                        raise IOError(*pd.error_info)

                    palette = pd.result
                    ret = True
                    pd.destroy()
                else:
                    pd.destroy()
                    raise IOError(_('Error while opening'), doc_file)

                if palette:
                    self.palettes.add_palette(palette)
                    config.import_dir = str(os.path.dirname(doc_file))
                    msg = _('Palette is successfully imported')
                    events.emit(events.APP_STATUS, msg)
                    return palette.model.name

            except:
                msg = _('Cannot import file:')
                msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                msg += _('The file may be corrupted or not supported format')
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                self.print_stacktrace()
        return None
Esempio n. 47
0
	def import_palette(self, parent=None):
		if not parent: parent = self.mw
		doc_file = dialogs.get_open_file_name(parent, self, config.import_dir,
											_('Select palette to import'),
											file_types=data.PALETTE_LOADERS)
		if os.path.lexists(doc_file) and os.path.isfile(doc_file):
			try:
				palette = None
				loader = get_loader(doc_file)
				pd = dialogs.ProgressDialog(_('Opening file...'), parent)
				ret = pd.run(loader, [self.appdata, doc_file, None, False, True])
				if ret:
					if pd.result is None:
						pd.destroy()
						raise IOError(*pd.error_info)

					palette = pd.result
					ret = True
					pd.destroy()
				else:
					pd.destroy()
					raise IOError(_('Error while opening'), doc_file)

				if palette:
					self.palettes.add_palette(palette)
					config.import_dir = str(os.path.dirname(doc_file))
					msg = _('Palette is successfully imported')
					events.emit(events.APP_STATUS, msg)
					return palette.model.name

			except:
				msg = _('Cannot import file')
				msg = "%s '%s'" % (msg, doc_file) + '\n'
				msg += _('The file may be corrupted or not supported format')
				dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
				self.print_stacktrace()
		return None