diff --git a/gourmet/plugins/import_export/pdf_plugin/__init__.py b/gourmet/plugins/import_export/pdf_plugin/__init__.py index a5d09b824..0c916e56d 100644 --- a/gourmet/plugins/import_export/pdf_plugin/__init__.py +++ b/gourmet/plugins/import_export/pdf_plugin/__init__.py @@ -1,10 +1,3 @@ -import sys - -import pdf_exporter_plugin -plugins = [pdf_exporter_plugin.PdfExporterPlugin] - -# pypoppler -- the python bindings for our PDF display library, -# which we require for printing -- doesn't work under Windows. -if sys.platform == "win32": - import print_plugin - plugins.append(print_plugin.PDFPrintPlugin) \ No newline at end of file +import pdf_exporter_plugin, print_plugin +plugins = [pdf_exporter_plugin.PdfExporterPlugin, + print_plugin.PDFPrintPlugin] diff --git a/gourmet/plugins/import_export/pdf_plugin/print_plugin.py b/gourmet/plugins/import_export/pdf_plugin/print_plugin.py index 9e6ded775..2e3477131 100644 --- a/gourmet/plugins/import_export/pdf_plugin/print_plugin.py +++ b/gourmet/plugins/import_export/pdf_plugin/print_plugin.py @@ -1,5 +1,7 @@ import gtk -import poppler +import sys +if sys.platform != "win32": + import poppler import os.path import pdf_exporter import tempfile @@ -16,6 +18,35 @@ tuple([int(round(s)) for s in pagesizes.A3]):gtk.PAPER_NAME_A3, } +class WindowsPDFPrinter: + + def setup_printer (self, parent=None): + self.args = pdf_exporter.get_pdf_prefs() + self.begin_print(None, None) + + def set_document (self, filename, operation,context): + try: + from subprocess import Popen + import _winreg + regPathKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, + "Software\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe") + regPathValue, regPathType = _winreg.QueryValueEx(regPathKey, "") + if regPathType != _winreg.REG_SZ: + raise TypeError + except: + from gourmet.gtk_extras.dialog_extras import show_message + show_message(label=_("Could not find Adobe Reader on your system.\n\n"), + sublabel=_("This version of Gourmet Recipe Manager " + "requires Adobe Reader " + "to be able to print; other PDF viewers will not work.\n" + "Please install Adobe Reader from http://get.adobe.com/reader/. \n" + "Alternatively, export your recipe(s) to PDF " + "and print it with another PDF viewer.")) + else: + # Launch a new instance (/n) of Adobe Reader with our temporary + # PDF to display the print dialog (/p). + Popen(regPathValue + " /n /p" + os.path.realpath(filename)) + class PDFPrinter: def setup_printer (self, parent=None): @@ -70,6 +101,9 @@ def create_custom_widget (self, operation): def custom_widget_apply (self, operation, widget): self.args = self.ppt.get_args_from_opts(self.opts) +if sys.platform == "win32": + PDFPrinter = WindowsPDFPrinter + def record_args (func): def _ (self, *args, **kwargs): @@ -77,7 +111,7 @@ def _ (self, *args, **kwargs): (func.__name__,args,kwargs) ) return _ - + class PDFSimpleWriter (PDFPrinter): def __init__ (self, dialog_parent=None):