From e047ea7abace19529e532a1b7aecefcd8fa3725b Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 1 Jan 2004 18:17:47 +0000 Subject: [PATCH] * src/docgen/PdfDoc.py: add the ability to open the document in the default viewer * src/docgen/AbiWord2Doc.py: add the ability to open the document in AbiWord * src/docgen/OpenOfficeDoc.py: fixed the search for default viewer * src/docgen/RTFDoc.py: add the ability to open the document in the default viewer * src/docgen/HtmlDoc.py: add the ability to open the document in the default viewer * src/docgen/KwordDoc.py: add comment svn: r2575 --- gramps2/src/docgen/AbiWord2Doc.py | 27 ++++++++++++++++++++++++++- gramps2/src/docgen/HtmlDoc.py | 27 ++++++++++++++++++++++++++- gramps2/src/docgen/KwordDoc.py | 6 ++++++ gramps2/src/docgen/OpenOfficeDoc.py | 17 +++++++++++------ gramps2/src/docgen/PdfDoc.py | 26 +++++++++++++++++++++++--- gramps2/src/docgen/RTFDoc.py | 27 ++++++++++++++++++++++++++- 6 files changed, 118 insertions(+), 12 deletions(-) diff --git a/gramps2/src/docgen/AbiWord2Doc.py b/gramps2/src/docgen/AbiWord2Doc.py index e99236991..c6a34eec3 100644 --- a/gramps2/src/docgen/AbiWord2Doc.py +++ b/gramps2/src/docgen/AbiWord2Doc.py @@ -31,6 +31,7 @@ Provides a BaseDoc based interface to the AbiWord document format. #------------------------------------------------------------------------- import base64 import string +import os import BaseDoc import Errors @@ -175,6 +176,14 @@ class AbiWordDoc(BaseDoc.BaseDoc): self.f.write('\n') self.f.close() + if self.print_req: + import grampslib + + apptype = 'application/x-abiword' + prog = grampslib.default_application_command(apptype) + os.environ["FILE"] = self.filename + os.system ('%s "$FILE" &' % prog) + def add_photo(self,name,pos,x_cm,y_cm): try: @@ -297,4 +306,20 @@ class AbiWordDoc(BaseDoc.BaseDoc): def end_cell(self): self.f.write('\n') -Plugins.register_text_doc(_("AbiWord"),AbiWordDoc,1,1,1,".abw") +#-------------------------------------------------------------------------- +# +# Register plugins +# +#-------------------------------------------------------------------------- + +try: + import grampslib + import Utils + + prog = grampslib.default_application_command("application/x-abiword") + if Utils.search_for(prog): + print_label=_("Open in AbiWord") +except: + print_label = None + +Plugins.register_text_doc(_("AbiWord"),AbiWordDoc,1,1,1,".abw", print_label) diff --git a/gramps2/src/docgen/HtmlDoc.py b/gramps2/src/docgen/HtmlDoc.py index 6ba2be74e..0596d03c4 100644 --- a/gramps2/src/docgen/HtmlDoc.py +++ b/gramps2/src/docgen/HtmlDoc.py @@ -333,6 +333,14 @@ class HtmlDoc(BaseDoc.BaseDoc): self.f.close() self.write_support_files() + if self.print_req: + import grampslib + + apptype = 'text/html' + prog = grampslib.default_application_command(apptype) + os.environ["FILE"] = self.filename + os.system ('%s "$FILE" &' % prog) + def write_support_files(self): if self.map: for name in self.map.keys(): @@ -457,4 +465,21 @@ class HtmlDoc(BaseDoc.BaseDoc): self.empty = 0 self.f.write(text) -Plugins.register_text_doc(_("HTML"),HtmlDoc,1,0,1,".html") +#------------------------------------------------------------------------ +# +# Register the document generator with the GRAMPS plugin system +# +#------------------------------------------------------------------------ + +try: + import grampslib + import Utils + + prog = grampslib.default_application_command("text/html") + desc = grampslib.default_application_name("text/html") + if Utils.search_for(prog): + print_label=_("Open in %s") % desc +except: + print_label = None + +Plugins.register_text_doc(_("HTML"),HtmlDoc,1,0,1,".html", print_label) diff --git a/gramps2/src/docgen/KwordDoc.py b/gramps2/src/docgen/KwordDoc.py index 82ba48e96..661bf0591 100644 --- a/gramps2/src/docgen/KwordDoc.py +++ b/gramps2/src/docgen/KwordDoc.py @@ -476,4 +476,10 @@ class KwordDoc(BaseDoc.BaseDoc): self.text = self.text + text +#------------------------------------------------------------------------ +# +# Register the document generator with the GRAMPS plugin system +# +#------------------------------------------------------------------------ + Plugins.register_text_doc(_("KWord"),KwordDoc,1,1,1,".kwd") diff --git a/gramps2/src/docgen/OpenOfficeDoc.py b/gramps2/src/docgen/OpenOfficeDoc.py index a425ced71..3718290a1 100644 --- a/gramps2/src/docgen/OpenOfficeDoc.py +++ b/gramps2/src/docgen/OpenOfficeDoc.py @@ -967,16 +967,21 @@ class OpenOfficeDoc(BaseDoc.BaseDoc): # #-------------------------------------------------------------------------- print_label = None -if os.access ("/usr/bin/oowriter", os.X_OK): - print_label = _("Open in OpenOffice.org") +try: + import grampslib + import Utils + + apptype = 'application/vnd.sun.xml.writer' + prog = grampslib.default_application_command(apptype) + + if Utils.search_for(prog): + print_label = _("Open in OpenOffice.org") +except: + pass Plugins.register_text_doc(_("OpenOffice.org Writer"),OpenOfficeDoc,1,1,1, ".sxw",print_label) Plugins.register_book_doc(_("OpenOffice.org Writer"),OpenOfficeDoc,1,1,1,".sxw") -print_label = None -if os.access ("/usr/bin/oodraw", os.X_OK): - print_label = _("Open in OpenOffice.org") - Plugins.register_draw_doc(_("OpenOffice.org Draw"),OpenOfficeDoc,1,1,".sxd", print_label); diff --git a/gramps2/src/docgen/PdfDoc.py b/gramps2/src/docgen/PdfDoc.py index 2ccf89982..c7c2ec0f0 100644 --- a/gramps2/src/docgen/PdfDoc.py +++ b/gramps2/src/docgen/PdfDoc.py @@ -175,7 +175,14 @@ class PdfDoc(BaseDoc.BaseDoc): except: import DisplayTrace DisplayTrace.DisplayTrace() -# raise Errors.ReportError(_("Could not create %s") % self.filename) + + if self.print_req: + import grampslib + + apptype = 'application/pdf' + prog = grampslib.default_application_command(apptype) + os.environ["FILE"] = self.filename + os.system ('%s "$FILE" &' % prog) def page_break(self): self.story.append(PageBreak()) @@ -565,12 +572,24 @@ def make_color(c): # #------------------------------------------------------------------------ +try: + import grampslib + import Utils + + prog = grampslib.default_application_command("application/pdf") + desc = grampslib.default_application_name("application/pdf") + if Utils.search_for(prog): + print_label=_("Open in %s") % desc +except: + print_label = None + Plugins.register_draw_doc( _("PDF"), PdfDoc, 1, 1, - ".pdf" + ".pdf", + print_label ) Plugins.register_text_doc( @@ -579,7 +598,8 @@ Plugins.register_text_doc( table=1, paper=1, style=1, - ext=".pdf" + ext=".pdf", + print_report_label=print_label ) Plugins.register_book_doc( diff --git a/gramps2/src/docgen/RTFDoc.py b/gramps2/src/docgen/RTFDoc.py index 67bec7f79..6557c5ef4 100644 --- a/gramps2/src/docgen/RTFDoc.py +++ b/gramps2/src/docgen/RTFDoc.py @@ -26,6 +26,7 @@ # #------------------------------------------------------------------------ import string +import os #------------------------------------------------------------------------ # @@ -124,6 +125,14 @@ class RTFDoc(BaseDoc.BaseDoc): self.f.write('}\n') self.f.close() + if self.print_req: + import grampslib + + apptype = 'application/rtf' + prog = grampslib.default_application_command(apptype) + os.environ["FILE"] = self.filename + os.system ('%s "$FILE" &' % prog) + #-------------------------------------------------------------------- # # Force a section page break @@ -402,4 +411,20 @@ class RTFDoc(BaseDoc.BaseDoc): self.text = self.text.replace('','{{\*\updnprop5801}\up10 ') self.text = self.text.replace('','}') -Plugins.register_text_doc(_("Rich Text Format (RTF)"),RTFDoc,1,1,1,".rtf") +#------------------------------------------------------------------------ +# +# Register the document generator with the GRAMPS plugin system +# +#------------------------------------------------------------------------ +try: + import grampslib + import Utils + + prog = grampslib.default_application_command("application/rtf") + desc = grampslib.default_application_name("application/rtf") + if Utils.search_for(prog): + print_label=_("Open in %s") % desc +except: + print_label = None + +Plugins.register_text_doc(_("Rich Text Format (RTF)"),RTFDoc,1,1,1,".rtf", print_label)