From de6bc226707adff941fcb4f6c3c18314b2f19f12 Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Wed, 24 Jan 2007 19:45:57 +0000 Subject: [PATCH] * src/docgen/PSDrawDoc.py: 0000869: PostScript print option will crash * src/ReportBase/__init__.py: 0000869: PostScript print option will crash * src/ReportBase/_PrintTools.py: 0000869: PostScript print option will crash svn: r7972 --- ChangeLog | 5 +++++ src/ReportBase/_PrintTools.py | 20 ++++++++++++-------- src/ReportBase/__init__.py | 2 +- src/docgen/PSDrawDoc.py | 32 ++++++++++++++++++++++++++++---- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 07f4231c4..198318629 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-01-24 Brian Matherly + * src/docgen/PSDrawDoc.py: 0000869: PostScript print option will crash + * src/ReportBase/__init__.py: 0000869: PostScript print option will crash + * src/ReportBase/_PrintTools.py: 0000869: PostScript print option will crash + 2007-01-24 Douglas Blank * src/docgen/PdfDoc.py: 0000870: docgen/PdfDoc.py offset error, and missing italics diff --git a/src/ReportBase/_PrintTools.py b/src/ReportBase/_PrintTools.py index 6f69ea3cf..1f33b4c31 100644 --- a/src/ReportBase/_PrintTools.py +++ b/src/ReportBase/_PrintTools.py @@ -37,15 +37,19 @@ import os def get_print_dialog_app (): """Return the name of a program which sends stdin (or the program's arguments) to the printer.""" - for printdialog in ["/usr/bin/kprinter --stdin", - "/usr/share/printconf/util/print.py"]: - if os.access (printdialog.split (' ')[0], os.X_OK): - return printdialog - - return "lpr" + if os.sys.platform != "win32": + for printdialog in ["/usr/bin/kprinter --stdin", + "/usr/share/printconf/util/print.py"]: + if os.access (printdialog.split (' ')[0], os.X_OK): + return printdialog + return "lpr" + else: + return None def run_print_dialog (filename): """Send file to the printer, possibly throwing up a dialog to ask which one etc.""" - os.environ["FILE"] = filename - return os.system ('cat "$FILE" | %s &' % get_print_dialog_app ()) + app = get_print_dialog_app() + if app: + os.environ["FILE"] = filename + return os.system ('cat "$FILE" | %s &' % app ) diff --git a/src/ReportBase/__init__.py b/src/ReportBase/__init__.py index 0a97f0b3e..c2ee897aa 100644 --- a/src/ReportBase/__init__.py +++ b/src/ReportBase/__init__.py @@ -38,4 +38,4 @@ from _TextReportDialog import TextReportDialog from _ReportOptions import ReportOptions import _ReportUtils as ReportUtils -from _PrintTools import run_print_dialog +from _PrintTools import run_print_dialog, get_print_dialog_app diff --git a/src/docgen/PSDrawDoc.py b/src/docgen/PSDrawDoc.py index 3316fbe14..cfb75ae9e 100644 --- a/src/docgen/PSDrawDoc.py +++ b/src/docgen/PSDrawDoc.py @@ -31,12 +31,14 @@ from gettext import gettext as _ #------------------------------------------------------------------------- #Gramps modules #------------------------------------------------------------------------- -from ReportBase import ReportUtils, Report +from ReportBase import ReportUtils, run_print_dialog, get_print_dialog_app from PluginUtils import register_draw_doc import BaseDoc import Errors from Utils import gformat +import Mime +import Utils def lrgb(grp): grp = ReportUtils.rgb_color(grp) @@ -44,6 +46,22 @@ def lrgb(grp): def coords(grp): return (gformat(grp[0]),gformat(grp[1])) + +_apptype = 'application/postscript' +print_label = None + +try: + # First try to find a viewer program + mprog = Mime.get_application(_apptype) + if Utils.search_for(mprog[0]): + print_label = _("Open in %(program_name)s") % {'program_name': mprog[1]} +except: + pass + +if print_label == None: + # Second, try to print directly + if get_print_dialog_app() != None: + print_label = _("Print a copy") #------------------------------------------------------------------------- # @@ -135,7 +153,14 @@ class PSDrawDoc(BaseDoc.BaseDoc): self.f.write('%%EOF\n') self.f.close() if self.print_req: - Report.run_print_dialog (self.filename) + if print_label == _("Print a copy"): + run_print_dialog (self.filename) + elif print_label: + app = Mime.get_application(_apptype) + Utils.launch(app[0],self.filename) + else: + # This should never happen + print "Invalid print request" def write_text(self,text,mark=None): pass @@ -419,5 +444,4 @@ class PSDrawDoc(BaseDoc.BaseDoc): self.f.write("(%s) show\n" % lines[i]) self.f.write('grestore\n') -register_draw_doc(_("PostScript"),PSDrawDoc,1,1,".ps", - _("Print a copy")); +register_draw_doc(_("PostScript"),PSDrawDoc,1,1,".ps", print_label);