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
def save_selected(self, doc_file): doc = SK2_Presenter(self.app.appdata) origin = self.doc_presenter.model.doc_origin doc.methods.set_doc_origin(origin) doc_units = self.doc_presenter.model.doc_units doc.methods.set_doc_units(doc_units) page = doc.methods.get_page() page_format = deepcopy(self.active_page.page_format) doc.methods.set_page_format(page, page_format) objs = [] for item in self.selection.objs: objs.append(item.copy()) layer = doc.methods.get_layer(page) layer.childs = objs saver = get_saver(doc_file) if saver is None: doc.close() raise IOError(_('Unknown file format is requested for saving!'), doc_file) pd = ProgressDialog(_('Saving file...'), self.app.mw) ret = pd.run(saver, [doc, doc_file], False) if ret: if pd.error_info is not None: pd.destroy() doc.close() raise IOError(*pd.error_info) pd.destroy() doc.close() else: pd.destroy() doc.close() raise IOError(_('Error while saving'), doc_file)
def __init__(self, app, doc_file='', silent=False): self.app = app self.eventloop = EventLoop(self) self.selection = Selection(self) if doc_file: loader = get_loader(doc_file) if loader is None: raise IOError(_('Unknown file format'), doc_file) if silent: self.doc_presenter = loader(app.appdata, doc_file) else: pd = ProgressDialog(_('Opening file...'), self.app.mw) ret = pd.run(loader, [app.appdata, doc_file]) if ret == gtk.RESPONSE_OK: if pd.result is None: pd.destroy() raise IOError(*pd.error_info) self.doc_presenter = pd.result pd.destroy() else: pd.destroy() raise IOError(_('Error while opening'), doc_file) self.doc_file = self.doc_presenter.doc_file self.doc_name = os.path.basename(self.doc_file) self.doc_name = change_file_extension( self.doc_name, uc2const.FORMAT_EXTENSION[uc2const.SK1][0]) else: self.doc_presenter = SK1_Presenter(app.appdata) self.doc_name = self.app.get_new_docname() self.methods = self.doc_presenter.methods self.model = self.doc_presenter.model self.set_active_page() self.cms = self.app.default_cms self.api = PresenterAPI(self) self.docarea = DocArea(self.app, self) self.canvas = self.docarea.canvas self.api.view = self.canvas self.app.mw.add_tab(self.docarea) self.eventloop.connect(self.eventloop.DOC_MODIFIED, self.modified) self.snap = SnapManager(self) self.traced_objects = [ self.doc_presenter, self.eventloop, self.api, self.docarea.hruler, self.docarea.vruler, self.docarea.corner, self.docarea, self.canvas.renderer, self.canvas, self.selection, self.snap, ]
def save(self): try: if config.make_backup: if os.path.lexists(self.doc_file): if os.path.lexists(self.doc_file + '~'): os.remove(self.doc_file + '~') os.rename(self.doc_file, self.doc_file + '~') saver = get_saver(self.doc_file) if saver is None: raise IOError( _('Unknown file format is requested for saving!'), self.doc_file) pd = ProgressDialog(_('Saving file...'), self.app.mw) ret = pd.run(saver, [self.doc_presenter, self.doc_file]) 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'), self.doc_file) except IOError: raise IOError(*sys.exc_info()) self.reflect_saving()
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
def __init__(self, app, doc_file='', silent=False, template=False): self.app = app self.eventloop = EventLoop(self) self.selection = Selection(self) loader = None if doc_file: loader = get_loader(doc_file) if not loader: raise IOError(_('Loader is not found for <%s>') % doc_file) if loader and silent: self.doc_presenter = loader(app.appdata, doc_file) elif doc_file and not silent: pd = ProgressDialog(_('Opening file...'), self.app.mw) try: self.doc_presenter = pd.run(loader, [app.appdata, doc_file]) if not self.doc_presenter: LOG.error('Cannot load <%s>', doc_file) raise IOError(_('Cannot load <%s>') % doc_file) except Exception: raise finally: pd.destroy() if not template: self.doc_file = self.doc_presenter.doc_file self.doc_name = os.path.basename(self.doc_file) ext = uc2const.FORMAT_EXTENSION[uc2const.SK2][0] self.doc_name = change_file_extension(self.doc_name, ext) else: self.doc_name = self.app.get_new_docname() self.doc_presenter.doc_file = '' else: self.doc_presenter = SK2_Presenter(app.appdata) self.doc_name = self.app.get_new_docname() self.methods = self.doc_presenter.methods self.model = self.doc_presenter.model self.set_active_page() self.cms = self.doc_presenter.cms # self.app.default_cms.registry_cm(self.cms) self.api = PresenterAPI(self) self.corner = RulerCorner(self) self.hruler = Ruler(self, vertical=False) self.vruler = Ruler(self) self.canvas = AppCanvas(self) self.canvas.set_mode() self.eventloop.connect(self.eventloop.DOC_MODIFIED, self.modified) self.snap = SnapManager(self)
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()
def save_selected(self, doc_file): doc = SK2_Presenter(self.app.appdata) origin = self.doc_presenter.model.doc_origin doc.methods.set_doc_origin(origin) doc_units = self.doc_presenter.model.doc_units doc.methods.set_doc_units(doc_units) page = doc.methods.get_page() page_format = deepcopy(self.active_page.page_format) doc.methods.set_page_format(page, page_format) objs = [] for item in self.selection.objs: objs.append(item.copy()) layer = doc.methods.get_layer(page) layer.childs = objs saver = get_saver(doc_file) if saver is None: doc.close() raise IOError(_('Unknown file format is requested for saving!'), doc_file) pd = ProgressDialog(_('Saving file...'), self.app.mw) ret = pd.run(saver, [doc, doc_file], False) if ret: if not pd.error_info is None: pd.destroy() doc.close() raise IOError(*pd.error_info) pd.destroy() doc.close() else: pd.destroy() doc.close() raise IOError(_('Error while saving'), doc_file)
def save(self): try: if config.make_backup: if os.path.lexists(self.doc_file): if os.path.lexists(self.doc_file + '~'): os.remove(self.doc_file + '~') os.rename(self.doc_file, self.doc_file + '~') saver = get_saver(self.doc_file) if saver is None: raise IOError(_('Unknown file format is requested for saving!'), self.doc_file) pd = ProgressDialog(_('Saving file...'), self.app.mw) ret = pd.run(saver, [self.doc_presenter, self.doc_file]) 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'), self.doc_file) except IOError: raise IOError(*sys.exc_info()) self.reflect_saving()
def __init__(self, app, doc_file='', silent=False, template=False): self.app = app self.eventloop = EventLoop(self) self.selection = Selection(self) if doc_file: loader = get_loader(doc_file) if silent: self.doc_presenter = loader(app.appdata, doc_file) else: pd = ProgressDialog(_('Opening file...'), self.app.mw) ret = pd.run(loader, [self.app.appdata, doc_file]) if ret: if pd.result is None: pd.destroy() raise IOError(*pd.error_info) self.doc_presenter = pd.result pd.destroy() else: pd.destroy() raise IOError(_('Error while opening'), doc_file) if not template: self.doc_file = self.doc_presenter.doc_file self.doc_name = os.path.basename(self.doc_file) self.doc_name = change_file_extension(self.doc_name, uc2const.FORMAT_EXTENSION[ uc2const.SK2][0]) else: self.doc_name = self.app.get_new_docname() self.doc_presenter.doc_file = '' else: self.doc_presenter = SK2_Presenter(app.appdata) self.doc_name = self.app.get_new_docname() self.methods = self.doc_presenter.methods self.model = self.doc_presenter.model self.set_active_page() self.cms = self.doc_presenter.cms # self.app.default_cms.registry_cm(self.cms) self.api = PresenterAPI(self) self.docarea = self.app.mdi.create_docarea(self) self.canvas = self.docarea.canvas self.canvas.set_mode() self.eventloop.connect(self.eventloop.DOC_MODIFIED, self.modified) self.snap = SnapManager(self) self.set_title()
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
def __init__(self, app, doc_file='', silent=False, template=False): self.app = app self.eventloop = EventLoop(self) self.selection = Selection(self) if doc_file: loader = get_loader(doc_file) if silent: self.doc_presenter = loader(app.appdata, doc_file) else: pd = ProgressDialog(_('Opening file...'), self.app.mw) ret = pd.run(loader, [self.app.appdata, doc_file]) if ret: if pd.result is None: pd.destroy() raise IOError(*pd.error_info) self.doc_presenter = pd.result pd.destroy() else: pd.destroy() raise IOError(_('Error while opening'), doc_file) if not template: self.doc_file = self.doc_presenter.doc_file self.doc_name = os.path.basename(self.doc_file) self.doc_name = change_file_extension(self.doc_name, uc2const.FORMAT_EXTENSION[uc2const.SK2][0]) else: self.doc_name = self.app.get_new_docname() self.doc_presenter.doc_file = '' else: self.doc_presenter = SK2_Presenter(app.appdata) self.doc_name = self.app.get_new_docname() self.methods = self.doc_presenter.methods self.model = self.doc_presenter.model self.set_active_page() self.cms = self.doc_presenter.cms #self.app.default_cms.registry_cm(self.cms) self.api = PresenterAPI(self) self.docarea = self.app.mdi.create_docarea(self) self.canvas = self.docarea.canvas self.canvas.set_mode() self.eventloop.connect(self.eventloop.DOC_MODIFIED, self.modified) self.snap = SnapManager(self) self.set_title()
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)
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)
def save_selected(self, doc_file): doc = SK2_Presenter(self.app.appdata) origin = self.doc_presenter.model.doc_origin doc.methods.set_doc_origin(origin) doc_units = self.doc_presenter.model.doc_units doc.methods.set_doc_units(doc_units) page = doc.methods.get_page() page_format = deepcopy(self.active_page.page_format) doc.methods.set_page_format(page, page_format) objs = [] for item in self.selection.objs: objs.append(item.copy()) layer = doc.methods.get_layer(page) layer.childs = objs pd = ProgressDialog(_('Saving file...'), self.app.mw) try: saver = get_saver(doc_file) if saver is None: msg = _('Unknown file format is requested for saving <%s>') raise IOError(msg % doc_file) pd.run(saver, [doc, doc_file]) except Exception: raise finally: pd.destroy() doc.close()
def import_file(self, doc_file): retval = True pd = ProgressDialog(_('Importing...'), self.app.mw) try: loader = get_loader(doc_file) if not loader: raise IOError(_('Loader is not found for <%s>') % doc_file) doc_presenter = pd.run(loader, [self.app.appdata, doc_file]) if not doc_presenter: LOG.error('Cannot load <%s>', doc_file) raise IOError(_('Cannot load <%s>') % doc_file) except Exception: raise finally: pd.destroy() pages = doc_presenter.methods.get_pages() if len(pages) == 1: page = doc_presenter.methods.get_page() objs = [] for layer in page.childs: for child in layer.childs: objs.append(child) layer.childs = [] if objs: self.api.paste_selected(objs) else: retval = False else: pages = doc_presenter.methods.get_pages() pages_obj = doc_presenter.methods.get_pages_obj() pages_obj.childs = [] if pages: self.api.add_pages(pages) else: retval = False doc_presenter.close() return retval
def export_as(self, doc_file): try: saver = get_saver(doc_file) if saver is None: raise IOError(_('Unknown file format is requested for export!'), doc_file) pd = ProgressDialog(_('Exporting...'), self.app.mw) ret = pd.run(saver, [self.doc_presenter, doc_file], False) if ret: if pd.error_info is not None: pd.destroy() raise IOError(*pd.error_info) pd.destroy() else: pd.destroy() raise IOError(_('Error while exporting'), doc_file) except IOError: raise IOError(*sys.exc_info())
def save(self): try: saver = get_saver(self.doc_file) if saver is None: raise IOError(_('Unknown file format is requested for saving!'), self.doc_file) pd = ProgressDialog(_('Saving file...'), self.app.mw) ret = pd.run(saver, [self.doc_presenter, self.doc_file], False) if ret: if pd.error_info is not None: pd.destroy() raise IOError(*pd.error_info) pd.destroy() else: pd.destroy() raise IOError(_('Error while saving'), self.doc_file) except IOError: raise IOError(*sys.exc_info()) self.reflect_saving()
def export_as(self, doc_file): pd = ProgressDialog(_('Exporting...'), self.app.mw) try: saver = get_saver(doc_file) if saver is None: msg = _('Unknown file format is requested for export <%s>') raise IOError(msg % doc_file) pd.run(saver, [self.doc_presenter, doc_file]) except Exception: raise finally: pd.destroy()
def import_file(self, doc_file): retval = True loader = get_loader(doc_file) pd = ProgressDialog(_('Opening file...'), self.app.mw) ret = pd.run(loader, [self.app.appdata, doc_file]) if ret: if pd.result is None: pd.destroy() raise IOError(*pd.error_info) doc_presenter = pd.result pd.destroy() else: pd.destroy() raise IOError(_('Error while opening'), doc_file) pages = doc_presenter.methods.get_pages() if len(pages) == 1: page = doc_presenter.methods.get_page() objs = [] for layer in page.childs: for child in layer.childs: objs.append(child) layer.childs = [] if objs: self.api.paste_selected(objs) else: retval = False else: pages = doc_presenter.methods.get_pages() pages_obj = doc_presenter.methods.get_pages_obj() pages_obj.childs = [] if pages: self.api.add_pages(pages) else: retval = False doc_presenter.close() return retval
def save(self): pd = ProgressDialog(_('Saving file...'), self.app.mw) try: saver = get_saver(self.doc_file) if saver is None: msg = _('Unknown file format is requested for saving! <%s>') raise IOError(msg % self.doc_file) pd.run(saver, [self.doc_presenter, self.doc_file]) except Exception: raise finally: pd.destroy() self.reflect_saving()
def export_as(self, doc_file): try: saver = get_saver(doc_file) if saver is None: raise IOError(_('Unknown file format is requested for export!'), doc_file) pd = ProgressDialog(_('Exporting...'), self.app.mw) ret = pd.run(saver, [self.doc_presenter, doc_file], False) if ret: if not pd.error_info is None: pd.destroy() raise IOError(*pd.error_info) pd.destroy() else: pd.destroy() raise IOError(_('Error while exporting'), doc_file) except IOError: raise IOError(*sys.exc_info())
def save(self): try: saver = get_saver(self.doc_file) if saver is None: raise IOError(_('Unknown file format is requested for saving!'), self.doc_file) pd = ProgressDialog(_('Saving file...'), self.app.mw) ret = pd.run(saver, [self.doc_presenter, self.doc_file], False) if ret: if not pd.error_info is None: pd.destroy() raise IOError(*pd.error_info) pd.destroy() else: pd.destroy() raise IOError(_('Error while saving'), self.doc_file) except IOError: raise IOError(*sys.exc_info()) self.reflect_saving()
def import_file(self, doc_file): retval = True loader = get_loader(doc_file) pd = ProgressDialog(_('Opening file...'), self.app.mw) ret = pd.run(loader, [self.app.appdata, doc_file]) if ret: if pd.result is None: pd.destroy() raise IOError(*pd.error_info) doc_presenter = pd.result pd.destroy() else: pd.destroy() raise IOError(_('Error while opening'), doc_file) pages = doc_presenter.methods.get_pages() if len(pages) == 1: page = doc_presenter.methods.get_page() objs = [] for layer in page.childs: for child in layer.childs: objs.append(child) layer.childs = [] if objs: self.api.paste_selected(objs) else: retval = False else: pages = doc_presenter.methods.get_pages() pages_obj = doc_presenter.methods.get_pages_obj() pages_obj.childs = [] if pages: self.api.add_pages(pages) else: retval = False doc_presenter.close() return retval
def __init__(self, app, doc_file='', silent=False): self.app = app self.eventloop = EventLoop(self) self.selection = Selection(self) if doc_file: loader = get_loader(doc_file) if loader is None: raise IOError(_('Unknown file format'), doc_file) if silent: self.doc_presenter = loader(app.appdata, doc_file) else: pd = ProgressDialog(_('Opening file...'), self.app.mw) ret = pd.run(loader, [app.appdata, doc_file]) if ret == gtk.RESPONSE_OK: if pd.result is None: pd.destroy() raise IOError(*pd.error_info) self.doc_presenter = pd.result pd.destroy() else: pd.destroy() raise IOError(_('Error while opening'), doc_file) self.doc_file = self.doc_presenter.doc_file self.doc_name = os.path.basename(self.doc_file) self.doc_name = change_file_extension(self.doc_name, uc2const.FORMAT_EXTENSION[uc2const.SK1][0]) else: self.doc_presenter = SK1_Presenter(app.appdata) self.doc_name = self.app.get_new_docname() self.methods = self.doc_presenter.methods self.model = self.doc_presenter.model self.set_active_page() self.cms = self.app.default_cms self.api = PresenterAPI(self) self.docarea = DocArea(self.app, self) self.canvas = self.docarea.canvas self.api.view = self.canvas self.app.mw.add_tab(self.docarea) self.eventloop.connect(self.eventloop.DOC_MODIFIED, self.modified) self.snap = SnapManager(self) self.traced_objects = [ self.doc_presenter, self.eventloop, self.api, self.docarea.hruler, self.docarea.vruler, self.docarea.corner, self.docarea, self.canvas.renderer, self.canvas, self.selection, self.snap, ]