def print_callback(self, arg): document = arg[0] from tempfile import NamedTemporaryFile pdffile = NamedTemporaryFile() fileformat = filters.guess_export_plugin(".pdf") ver = config.preferences.pdf_level pdf_ver = (int(ver[0]), int(ver[2])) saver = filters.find_export_plugin(fileformat) saver(document, pdffile.name, options={"pdf_version": pdf_ver}) icon = os.path.join(app.config.sk_share_dir, "images") icon = os.path.join(icon, "sk1-app-icon.png") execline = "" if sk1.LANG: execline += "export LANG=" + sk1.LANG + ";" execline += "python %s/gtk/print_dialog.py " % (PATH,) execline += ' filepath="' + pdffile.name + '"' execline += ' window-icon="' + icon + '"' self.mw.root.update() self.mw.canvas.ForceRedraw() return (execline, pdffile)
def ExportPNG(self, document): directory = config.preferences.dir_for_bitmap_export filename = document.meta.filename[:-4] + ".png" filename, pngfile = dialogman.getGenericSaveFilename( _("PNG export"), png_types, initialdir=directory, initialfile=filename ) if filename == "": return fileformat = filters.guess_export_plugin(".png") saver = filters.find_export_plugin(fileformat) saver(document, pngfile)
def ExportPNG(self, document): directory = config.preferences.dir_for_bitmap_export filename = document.meta.filename[:-4] + '.png' filename, pngfile = dialogman.getGenericSaveFilename( _("PNG export"), png_types, initialdir=directory, initialfile=filename) if filename == '': return fileformat = filters.guess_export_plugin('.png') saver = filters.find_export_plugin(fileformat) saver(document, pngfile)
def SaveToFile(self, document, filename, fileformat=None, compressed='', compressed_file=''): sysname = filename try: if not document.meta.backup_created: try: if compressed_file: fs.make_backup(compressed_file) else: fs.make_backup(sysname) except fs.BackupError, value: backupfile = value.filename strerror = value.strerror msg = (_("\nCannot create backup file %(filename)s:\n" "%(message)s\n\n" "Choose `continue' to try saving anyway,\n" "or `cancel' to cancel saving.") % { 'filename': ` backupfile `, 'message': strerror }) cancel = _("Cancel") result = msgDialog(self.mw.root, title=_("Save To File"), message=msg, buttons=(_("Continue"), cancel)) if result == cancel: return document.meta.backup_created = 1 if fileformat is None: fileformat = filters.NativeFormat try: saver = filters.find_export_plugin(fileformat) if compressed: # XXX there should be a plugin interface for this kind # of post-processing if compressed == "gzip": cmd = 'gzip -c -9 > ' + utils.sh_quote(compressed_file) elif compressed == "bzip2": cmd = 'bzip2 > ' + utils.sh_quote(compressed_file) file = os.popen(cmd, 'w') saver(document, filename, file=file) else: saver(document, sysname) finally: saver.UnloadPlugin()
def SaveToFile(self, document, filename, fileformat=None, compressed="", compressed_file=""): sysname = filename try: if not document.meta.backup_created: try: if compressed_file: fs.make_backup(compressed_file) else: fs.make_backup(sysname) except fs.BackupError, value: backupfile = value.filename strerror = value.strerror msg = _( "\nCannot create backup file %(filename)s:\n" "%(message)s\n\n" "Choose `continue' to try saving anyway,\n" "or `cancel' to cancel saving." ) % {"filename": ` backupfile `, "message": strerror} cancel = _("Cancel") result = msgDialog( self.mw.root, title=_("Save To File"), message=msg, buttons=(_("Continue"), cancel) ) if result == cancel: return document.meta.backup_created = 1 if fileformat is None: fileformat = filters.NativeFormat try: saver = filters.find_export_plugin(fileformat) if compressed: # XXX there should be a plugin interface for this kind # of post-processing if compressed == "gzip": cmd = "gzip -c -9 > " + utils.sh_quote(compressed_file) elif compressed == "bzip2": cmd = "bzip2 > " + utils.sh_quote(compressed_file) file = os.popen(cmd, "w") saver(document, filename, file=file) else: saver(document, sysname) finally: saver.UnloadPlugin()
def print_callback(self, arg): document = arg[0] from tempfile import NamedTemporaryFile pdffile = NamedTemporaryFile() fileformat = filters.guess_export_plugin('.pdf') ver = config.preferences.pdf_level pdf_ver = (int(ver[0]), int(ver[2])) saver = filters.find_export_plugin(fileformat) saver(document, pdffile.name, options={'pdf_version': pdf_ver}) icon = os.path.join(app.config.sk_share_dir, 'images') icon = os.path.join(icon, 'sk1-app-icon.png') execline = '' if sk1.LANG: execline += 'export LANG=' + sk1.LANG + ';' execline += 'python %s/gtk/print_dialog.py ' % (PATH, ) execline += ' filepath="' + pdffile.name + '"' execline += ' window-icon="' + icon + '"' self.mw.root.update() self.mw.canvas.ForceRedraw() return (execline, pdffile)