Beispiel #1
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.PDXF][0]:
			doc_file = os.path.splitext(doc_file)[0] + "." + \
					uc2const.FORMAT_EXTENSION[uc2const.PDXF][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 = get_save_file_name(self.mw, self, doc_file)
		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.current_doc.save()
			except IOError:
				self.current_doc.set_doc_file(old_file, old_name)
				details = sys.exc_info()[1].__str__() + sys.exc_info()[2].__str__()
				first = _('Cannot save document')
				sec = _('Please check file name and write permissions')
				msg = ("%s '%s'.") % (first, self.current_doc.doc_name)

				wal.error_dialog(self.mw, self.appdata.app_name, msg, sec, details)

				return False
			config.save_dir = os.path.dirname(doc_file)
			events.emit(events.APP_STATUS, _('Document saved'))
			return True
		else:
			return False
Beispiel #2
0
    def _get_doc_form_file(self, filepath=None, win=None, title=None):
        doc = None
        wnd = win or self.wins[0]

        if wnd and not filepath:
            filepath = dialogs.get_open_file_name(
                wnd, config.open_dir, title, uc2const.PALETTE_LOADERS)
        if not filepath:
            return

        if os.path.isfile(filepath):
            try:
                loader = get_loader(filepath)
                if not loader:
                    raise LookupError('Cannot find loader for %s' % filepath)
                doc = loader(self.appdata, filepath, convert=True)
                self._normalize_colors(doc)
                config.open_dir = str(os.path.dirname(filepath))
            except Exception as e:
                msg = _('Cannot parse file:')
                msg = "%s\n'%s'" % (msg, filepath) + '\n'
                msg2 = _('The file may be corrupted or not supported format')
                wal.error_dialog(wnd, self.appdata.app_name, msg, msg2)
                LOG.exception('Cannot parse file <%s>' % filepath, e)
        return doc
    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.PDXF][0]:
            doc_file = os.path.splitext(doc_file)[0] + "." + \
              uc2const.FORMAT_EXTENSION[uc2const.PDXF][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 = get_save_file_name(self.mw, self, doc_file)
        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.current_doc.save()
            except IOError:
                self.current_doc.set_doc_file(old_file, old_name)
                details = sys.exc_info()[1].__str__() + sys.exc_info(
                )[2].__str__()
                first = _('Cannot save document')
                sec = _('Please check file name and write permissions')
                msg = ("%s '%s'.") % (first, self.current_doc.doc_name)

                wal.error_dialog(self.mw, self.appdata.app_name, msg, sec,
                                 details)

                return False
            config.save_dir = os.path.dirname(doc_file)
            events.emit(events.APP_STATUS, _('Document saved'))
            return True
        else:
            return False
Beispiel #4
0
 def save_as_doc(self, doc, win=None):
     wnd = win or self.wins[0]
     doc_file = doc.doc_file
     doc_file = doc_file or doc.model.name
     if os.path.splitext(doc_file)[1] != "." + \
             uc2const.FORMAT_EXTENSION[uc2const.SKP][0]:
         doc_file = os.path.splitext(doc_file)[0] + "." + \
                    uc2const.FORMAT_EXTENSION[uc2const.SKP][0]
     if not os.path.exists(os.path.dirname(doc_file)):
         doc_file = os.path.join(config.save_dir,
                                 os.path.basename(doc_file))
     ret = dialogs.get_save_file_name(
         wnd, doc_file, file_types=uc2const.PALETTE_SAVERS)
     if ret and len(ret) == 2:
         try:
             doc_file, saver_id = ret
             saver = get_saver_by_id(saver_id)
             saver(doc, doc_file, translate=False, convert=True)
             LOG.info('Palette saved to %s', doc_file)
             return True
         except Exception as e:
             msg = _('Cannot save file:')
             msg = "%s\n'%s'" % (msg, doc_file) + '\n'
             msg2 = _('Details see in logs')
             wal.error_dialog(wnd, self.appdata.app_name, msg, msg2)
             LOG.exception('Cannot save file <%s>' % doc_file, e)
     return False
Beispiel #5
0
 def on_ok(self, *args):
     path = self.lc.get_selected()[2]
     if fsutils.isfile(path):
         self.ret = path
         self.end_modal(wal.BUTTON_OK)
     else:
         txt = "%s '%s' %s" % (_('File'), path, _('is not found.'))
         wal.error_dialog(self, _('File not found'), txt)
Beispiel #6
0
	def on_ok(self, *args):
		path = self.lc.get_selected()[2].encode(sys.getfilesystemencoding())
		if os.path.isfile(path):
			self.ret = path
			self.end_modal(wal.BUTTON_OK)
		else:
			txt = "%s '%s' %s" % (_('File'), path, _('is not found.'))
			wal.error_dialog(self, _('File not found'), txt)
Beispiel #7
0
	def on_ok(self, *args):
		path = self.lc.get_selected()[2].encode(sys.getfilesystemencoding())
		if os.path.isfile(path):
			self.ret = path
			self.end_modal(wal.BUTTON_OK)
		else:
			txt = "%s '%s' %s" % (_('File'), path, _('is not found.'))
			wal.error_dialog(self, _('File not found'), txt)
	def callback5(self, *args):
		title = 'Error'
		first = 'Oops! Sorry!'
		second = 'Jobs are impossible.'
		details = ('Error stacktrace', 'Note that the static function signatures \
		have changed with respect to their button parameters, which are now used \
		to set the standard buttons and the default button.')
		wal.error_dialog(self, title, first, second, details)
Beispiel #9
0
 def set_color_hexvalue(self, index, hexvalue):
     try:
         clr = uc2.cms.hexcolor_to_rgb(hexvalue)
     except Exception:
         wal.error_dialog(self.canvas.mw, _('Wrong value'),
                          _('Wrong color value: ') + hexvalue,
                          _('Fix it and try again'))
         return
     cell = self.cells[index]
     color = deepcopy(self.cells[index].color)
     color[1] = clr
     api.change_color(self.canvas, cell, color)
 def on_load(self, *args):
     self._timer.Stop()
     self.data = self.stub.get_palette_list()
     if self.data:
         self.stub.hide()
         self.viewer.show()
     else:
         msg = _('Cannot connect to server!')
         msg += '\n' + _('Please check Internet connection')
         msg += '\n' + _('and access to https://sk1project.net')
         wal.error_dialog(self, self.app.appdata.app_name, msg)
         self.on_cancel()
Beispiel #11
0
	def on_load(self, *args):
		self._timer.Stop()
		self.data = self.stub.get_palette_list()
		if self.data:
			self.stub.hide()
			self.viewer.show()
		else:
			msg = _('Cannot connect to server!')
			msg += '\n' + _('Please check Internet connection')
			msg += '\n' + _('and access to http://sk1project.net')
			wal.error_dialog(self, self.app.appdata.app_name, msg)
			self.on_cancel()
Beispiel #12
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'))
Beispiel #13
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'))
 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 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.PDXF][0]:
            return self.save_as()
        if not os.path.lexists(os.path.dirname(self.current_doc.doc_file)):
            return self.save_as()

        try:
            doc.save()
        except:
            details = sys.exc_info()[1].__str__() + sys.exc_info()[2].__str__()
            msg = _('Cannot save file')
            msg = "%s '%s'" % (msg, self.current_doc.doc_file)
            sec = _('Please check file write permissions')
            wal.error_dialog(self.mw, self.appdata.app_name, msg, sec, details)
            return False
        events.emit(events.APP_STATUS, _('Document saved'))
        return True
Beispiel #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.PDXF][0]:
			return self.save_as()
		if not os.path.lexists(os.path.dirname(self.current_doc.doc_file)):
			return self.save_as()

		try:
			doc.save()
		except:
			details = sys.exc_info()[1].__str__() + sys.exc_info()[2].__str__()
			msg = _('Cannot save file')
			msg = "%s '%s'" % (msg, self.current_doc.doc_file)
			sec = _('Please check file write permissions')
			wal.error_dialog(self.mw, self.appdata.app_name, msg, sec, details)
			return False
		events.emit(events.APP_STATUS, _('Document saved'))
		return True
Beispiel #18
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))
Beispiel #19
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))
Beispiel #20
0
 def import_profile(self, *args):
     src = get_profile_import_dialog(self.dlg, self.app,
                                     config.profile_import_dir)
     if not src: return
     name = get_profile_name(src)
     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.dlg, self.app.appdata.app_name, msg, 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.dlg, self.app.appdata.app_name, msg, 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.dlg, self.app.appdata.app_name, msg, 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:\n%s' %
             dst_dir)
         wal.error_dialog(self.dlg, self.app.appdata.app_name, msg, sec)
         return
     config.profile_import_dir = os.path.dirname(src)
     self.profiles[name] = filename
     self.apply_changes()
Beispiel #21
0
	def import_profile(self, *args):
		src = get_profile_import_dialog(self.dlg, self.app, config.profile_import_dir)
		if not src: return
		name = get_profile_name(src)
		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.dlg, self.app.appdata.app_name, msg, 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.dlg, self.app.appdata.app_name, msg, 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.dlg, self.app.appdata.app_name, msg, 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:\n%s' % dst_dir)
			wal.error_dialog(self.dlg, self.app.appdata.app_name, msg, sec)
			return
		config.profile_import_dir = os.path.dirname(src)
		self.profiles[name] = filename
		self.apply_changes()
	def callback2(self, *args):
		title = 'Error'
		first = 'Oops! Sorry!'
		second = 'Jobs are impossible.'
		wal.error_dialog(self, title, first, second)