Пример #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.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)
		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:
				msg = _('Model saving for') + ' "%s" ' % (doc_file)
				uc2.events.emit(uc2.events.MESSAGES, uc2.msgconst.JOB, msg)

				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)

				uc2.events.emit(uc2.events.MESSAGES, uc2.msgconst.STOP, msg)

				dialogs.msg_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
Пример #2
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.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)
		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:
				msg = _('Model saving for') + ' "%s" ' % (doc_file)
				uc2.events.emit(uc2.events.MESSAGES, uc2.msgconst.JOB, msg)

				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)

				uc2.events.emit(uc2.events.MESSAGES, uc2.msgconst.STOP, msg)

				dialogs.msg_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
Пример #3
0
 def save_chunk(self, *args):
     selected = self.app.current_doc.selection.selected
     if selected and hasattr(selected[0], 'chunk'):
         obj = selected[0]
         doc_file = os.path.join(config.save_dir, 'chunk')
         doc_file = dialogs.get_save_file_name(self.mw, self.app, doc_file)
         if doc_file:
             res = dialogs.chunk_range_dlg(self.mw)
             if res:
                 start, end = res
                 chunk = obj.chunk[start:len(obj.chunk) - end]
                 with open(doc_file, 'wb') as fp:
                     fp.write(chunk)