* 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
This commit is contained in:
Brian Matherly 2007-01-24 19:45:57 +00:00
parent 1c99ffb4c9
commit de6bc22670
4 changed files with 46 additions and 13 deletions

View File

@ -1,3 +1,8 @@
2007-01-24 Brian Matherly <brian@gramps-project.org>
* 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 <dblank@cs.brynmawr.edu>
* src/docgen/PdfDoc.py: 0000870: docgen/PdfDoc.py offset error,
and missing italics

View File

@ -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 )

View File

@ -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

View File

@ -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);