Example #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 = 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:
                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)

                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
Example #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.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 = 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:
				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)

				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
Example #3
0
    def do_cutting(self):
        cut_bbox = None
        ret = get_cut_dialog(self.app)
        if ret == gtk.RESPONSE_ACCEPT:
            #Collect all objects

            page = self.doc_presenter.methods.get_pages()[-1]
            objs = []
            for layer in page.childs:
                for obj in layer.childs:
                    objs.append(obj)

            if not objs:
                first = _('Cannot cutting in file')
                sec = _('There are no objects in document.')
                msg = ("%s '%s'.") % (first, config.output_file)
                msg_dialog(self.app.mw, self.app.appdata.app_name, msg, sec)
                return

            try:
                saver = get_saver('file.plt')

                if config.cut_bbox:
                    bbox = []
                    bbox += objs[0].cache_bbox
                    for obj in objs:
                        bbox = libgeom.sum_bbox(bbox, obj.cache_bbox)

                    layer = page.childs[-1]
                    cut_bbox = model.Rectangle(layer.config, layer, bbox)
                    layer.childs.append(cut_bbox)
                    cut_bbox.update()

                pd = ProgressDialog(_('Cutting...'), self.app.mw)
                ret = pd.run(saver, [
                    self.doc_presenter, config.output_file, True, {
                        'tolerance': config.tolerance
                    }
                ])
                if ret == gtk.RESPONSE_OK:
                    if not pd.error_info is None:
                        pd.destroy()
                        raise IOError(*pd.error_info)
                    pd.destroy()
                else:
                    pd.destroy()
                    raise IOError(_('Error while saving'), config.output_file)

            except IOError:
                details = sys.exc_info()[1].__str__() + sys.exc_info(
                )[2].__str__()
                first = _('Cannot cutting!')
                sec = _('Please check file name and write permissions')
                msg = ("%s '%s'.") % (first, config.output_file)

                msg_dialog(self.app.mw, self.app.appdata.app_name, msg, sec,
                           details)
        if not cut_bbox is None:
            self.doc_presenter.methods.delete_object(cut_bbox)
Example #4
0
	def do_cutting(self):
		cut_bbox = None
		ret = get_cut_dialog(self.app)
		if ret == gtk.RESPONSE_ACCEPT:
			#Collect all objects

			page = self.doc_presenter.methods.get_pages()[-1]
			objs = []
			for layer in page.childs:
				for obj in layer.childs:
					objs.append(obj)

			if not objs:
				first = _('Cannot cutting in file')
				sec = _('There are no objects in document.')
				msg = ("%s '%s'.") % (first, config.output_file)
				msg_dialog(self.app.mw, self.app.appdata.app_name, msg, sec)
				return

			try:
				saver = get_saver('file.plt')

				if config.cut_bbox:
					bbox = []
					bbox += objs[0].cache_bbox
					for obj in objs:
						bbox = libgeom.sum_bbox(bbox, obj.cache_bbox)

					layer = page.childs[-1]
					cut_bbox = model.Rectangle(layer.config, layer, bbox)
					layer.childs.append(cut_bbox)
					cut_bbox.update()

				pd = ProgressDialog(_('Cutting...'), self.app.mw)
				ret = pd.run(saver, [self.doc_presenter,
									config.output_file,
									True,
									{'tolerance':config.tolerance}])
				if ret == gtk.RESPONSE_OK:
					if not pd.error_info is None:
						pd.destroy()
						raise IOError(*pd.error_info)
					pd.destroy()
				else:
					pd.destroy()
					raise IOError(_('Error while saving'), config.output_file)

			except IOError:
				details = sys.exc_info()[1].__str__() + sys.exc_info()[2].__str__()
				first = _('Cannot cutting!')
				sec = _('Please check file name and write permissions')
				msg = ("%s '%s'.") % (first, config.output_file)

				msg_dialog(self.app.mw, self.app.appdata.app_name, msg, sec, details)
		if not cut_bbox is None:
			self.doc_presenter.methods.delete_object(cut_bbox)
Example #5
0
	def insert_doc(self):
		doc_file = dialogs.get_open_file_name(self.mw, self, config.import_dir,
											_('Import file...'))
		if os.path.lexists(doc_file) and os.path.isfile(doc_file):
			try:
				self.current_doc.insert_doc(doc_file)
			except:
				details = sys.exc_info()[1].__str__() + sys.exc_info()[2].__str__()
				msg = _('Cannot import file')
				msg = "%s '%s'" % (msg, doc_file)
				sec = _('The file may be corrupted or not supported format')
				dialogs.msg_dialog(self.mw, self.appdata.app_name, msg, sec, details)
				return

			config.import_dir = os.path.dirname(doc_file)
Example #6
0
    def insert_doc(self):
        doc_file = dialogs.get_open_file_name(self.mw, self, config.import_dir,
                                              _('Import file...'))
        if os.path.lexists(doc_file) and os.path.isfile(doc_file):
            try:
                self.current_doc.insert_doc(doc_file)
            except:
                details = sys.exc_info()[1].__str__() + sys.exc_info(
                )[2].__str__()
                msg = _('Cannot import file')
                msg = "%s '%s'" % (msg, doc_file)
                sec = _('The file may be corrupted or not supported format')
                dialogs.msg_dialog(self.mw, self.appdata.app_name, msg, sec,
                                   details)
                return

            config.import_dir = os.path.dirname(doc_file)
Example #7
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:
				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')
				dialogs.msg_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'))
Example #8
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:
             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')
             dialogs.msg_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'))
Example #9
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()
			events.emit(events.DOC_SAVED, doc)
		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')
			dialogs.msg_dialog(self.mw, self.appdata.app_name, msg, sec, details)
			return False
		events.emit(events.APP_STATUS, _('Document saved'))
		return True
Example #10
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()
            events.emit(events.DOC_SAVED, doc)
        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')
            dialogs.msg_dialog(self.mw, self.appdata.app_name, msg, sec,
                               details)
            return False
        events.emit(events.APP_STATUS, _('Document saved'))
        return True