Exemple #1
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)
Exemple #2
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()
Exemple #3
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'))
Exemple #4
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'))
Exemple #5
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'))
Exemple #6
0
	def import_image(self, image_file=''):
		if not image_file:
			image_file = get_open_file_name(self.mw, self, config.import_dir, True)
		if os.path.lexists(image_file) and os.path.isfile(image_file):
			try:
				print image_file
			except:
				details = sys.exc_info()[1].__str__() + sys.exc_info()[2].__str__()
				msg = _('Cannot import image')
				msg = "%s '%s'" % (msg, image_file)
				sec = _('The file may be corrupted or not supported format')
				wal.error_dialog(self.mw, self.appdata.app_name, msg, sec, details)
				return
			config.import_dir = os.path.dirname(image_file)
			events.emit(events.APP_STATUS, _('Image is imported'))
Exemple #7
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'))
Exemple #8
0
	def open(self, doc_file='', silent=False):
		if not doc_file:
			doc_file = get_open_file_name(self.mw, self, config.open_dir)
		if os.path.lexists(doc_file) and os.path.isfile(doc_file):
			try:
				doc = DocPresenter(self, doc_file, silent)
			except:
				details = sys.exc_info()[1].__str__() + sys.exc_info()[2].__str__()
				msg = _('Cannot open file')
				msg = "%s '%s'" % (msg, doc_file)
				sec = _('The file may be corrupted or not supported format')
				wal.error_dialog(self.mw, self.appdata.app_name, msg, sec, details)
				return
			self.docs.append(doc)
			self.set_current_doc(doc)
			config.open_dir = os.path.dirname(doc_file)
			events.emit(events.APP_STATUS, _('Document opened'))
 def import_image(self, image_file=''):
     if not image_file:
         image_file = get_open_file_name(self.mw, self, config.import_dir,
                                         True)
     if os.path.lexists(image_file) and os.path.isfile(image_file):
         try:
             print image_file
         except:
             details = sys.exc_info()[1].__str__() + sys.exc_info(
             )[2].__str__()
             msg = _('Cannot import image')
             msg = "%s '%s'" % (msg, image_file)
             sec = _('The file may be corrupted or not supported format')
             wal.error_dialog(self.mw, self.appdata.app_name, msg, sec,
                              details)
             return
         config.import_dir = os.path.dirname(image_file)
         events.emit(events.APP_STATUS, _('Image is imported'))
Exemple #10
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'))
Exemple #11
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()
Exemple #12
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'))
 def open(self, doc_file='', silent=False):
     if not doc_file:
         doc_file = get_open_file_name(self.mw, self, config.open_dir)
     if os.path.lexists(doc_file) and os.path.isfile(doc_file):
         try:
             doc = DocPresenter(self, doc_file, silent)
         except:
             details = sys.exc_info()[1].__str__() + sys.exc_info(
             )[2].__str__()
             msg = _('Cannot open file')
             msg = "%s '%s'" % (msg, doc_file)
             sec = _('The file may be corrupted or not supported format')
             wal.error_dialog(self.mw, self.appdata.app_name, msg, sec,
                              details)
             return
         self.docs.append(doc)
         self.set_current_doc(doc)
         config.open_dir = os.path.dirname(doc_file)
         events.emit(events.APP_STATUS, _('Document opened'))
Exemple #14
0
 def import_profile(self):
     src = dialogs.get_open_file_name(self,
                                      config.profile_import_dir,
                                      _('Select profile to import'),
                                      file_types=[ICC, ICM])
     if not src:
         return
     name = get_profile_name(src)
     title = self.app.appdata.app_name
     if name is None:
         msg = _('Cannot open profile')
         msg = "%s '%s'" % (msg, src)
         sec = _('The profile may be corrupted or in an unsupported format')
         wal.error_dialog(self, title, msg + '\n' + sec)
         return
     if name in self.pf_list:
         msg = _('Selected profile cannot be added to profile list:')
         msg = "%s '%s'" % (msg, name)
         sec = _('It seems like you have already imported this profile')
         wal.error_dialog(self, title, msg + '\n' + sec)
         return
     filename = os.path.basename(src)
     dst_dir = self.app.appdata.app_color_profile_dir
     dst = os.path.join(dst_dir, filename)
     if fsutils.exists(dst):
         msg = _('Selected file has been added to profile pool')
         msg = "%s '%s'" % (msg, src)
         sec = _('If you still wish to import the file, try renaming it')
         wal.error_dialog(self, title, msg + '\n' + sec)
         return
     try:
         shutil.copy(fsutils.get_sys_path(src), fsutils.get_sys_path(dst))
     except Exception:
         msg = _('Cannot copy file')
         msg = "%s '%s'" % (msg, src)
         sec = _('Please check write permissions for config directory:')
         sec += '\n%s' % dst_dir
         wal.error_dialog(self, title, msg + '\n' + sec)
         return
     config.profile_import_dir = os.path.dirname(src)
     self.profiles[name] = filename
     self.apply_changes()
     self.viewer.set_active(self.pf_list.index(name))
Exemple #15
0
	def import_profile(self):
		src = dialogs.get_open_file_name(self, self,
									config.profile_import_dir,
									_('Select profile to import'),
									file_types=[ICC, ICM])
		if not src: return
		name = get_profile_name(src)
		title = self.app.appdata.app_name
		if name is None:
			msg = _('Cannot open profile')
			msg = "%s '%s'" % (msg, src)
			sec = _('The profile may be corrupted or not supported format')
			wal.error_dialog(self, title, msg + '\n' + sec)
			return
		if name in self.pf_list:
			msg = _('Selected profile cannot be added to profile list:')
			msg = "%s '%s'" % (msg, name)
			sec = _('It seems you have imported this profile')
			wal.error_dialog(self, title, msg + '\n' + sec)
			return
		filename = os.path.basename(src)
		dst_dir = self.app.appdata.app_color_profile_dir
		dst = os.path.join(dst_dir, filename)
		if os.path.lexists(dst):
			msg = _('Selected file has been added to profile pool')
			msg = "%s '%s'" % (msg, src)
			sec = _('If you sure to import the file try renaming it')
			wal.error_dialog(self, title, msg + '\n' + sec)
			return
		try:
			shutil.copy(src, dst)
		except:
			msg = _('Cannot copy file')
			msg = "%s '%s'" % (msg, src)
			sec = _('Please check writing permissions for config directory:')
			sec += '\n%s' % dst_dir
			wal.error_dialog(self, title, msg + '\n' + sec)
			return
		config.profile_import_dir = os.path.dirname(src)
		self.profiles[name] = filename
		self.apply_changes()
		self.viewer.set_active(self.pf_list.index(name))
Exemple #16
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
Exemple #17
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()
Exemple #18
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)
Exemple #19
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
Exemple #20
0
 def import_file(self):
     doc_file = dialogs.get_open_file_name(self.mw, config.import_dir,
                                           _('Select file to import'))
     if fsutils.lexists(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)
             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)
Exemple #21
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=PATTERN_FORMATS)
        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)
                    self.print_stacktrace()
            except:
                dialogs.error_dialog(parent, self.appdata.app_name, msg)
                self.print_stacktrace()

        return None
Exemple #22
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