dabo Commit
Revision 7236
Date: 2012-08-28 11:33:44 -0700 (Tue, 28 Aug 2012)
Author: Paul
Trac: http://trac.dabodev.com/changeset/7236

Changed:
U   trunk/dabo/lib/reportUtils.py

Log:
Renamed printPDF() and previewPDF() to printReport() and previewReport(),
respectively, and added logic to handle plain-text reports such as you'd
send to a label printer.


Diff:
Modified: trunk/dabo/lib/reportUtils.py
===================================================================
--- trunk/dabo/lib/reportUtils.py       2012-08-25 20:19:22 UTC (rev 7235)
+++ trunk/dabo/lib/reportUtils.py       2012-08-28 18:33:44 UTC (rev 7236)
@@ -45,21 +45,27 @@
 getTempFile = tempFileHolder.getTempFile
 
 
-def previewPDF(path, modal=False):
-       """Preview the passed PDF file in the default PDF viewer."""
+def previewReport(path, modal=False):
+       """Preview the passed report (txt or pdf) file in the default viewer."""
        try:
-               # On Windows, use the default PDF viewer (probably Adobe 
Acrobat)
+               # On Windows, use the default viewer (probably Notepad or Adobe 
Acrobat)
                os.startfile(path)
        except AttributeError:
-               # On Mac, use the default PDF viewer (probably Preview.app)
+               # On Mac, use the default viewer (probably TextEdit.app or 
Preview.app)
                if sys.platform == "darwin":
                        os.system("open %s" % path)
                else:
                        # On Linux, try to find an installed viewer and just 
use the first one
                        # found. I just don't know how to reliably get the 
default viewer from
                        # the many distros.
-                       viewers = ("gpdf", "kpdf", "okular", "evince", 
"acroread", "xpdf", "firefox",
+                       reportType = path.split(".")[-1]
+                       if reportType == "txt":
+                               viewers = ("gedit", "kate", "firefox", 
"mozilla-firefox", "chromium")
+                       elif reportType == "pdf":
+                               viewers = ("gpdf", "kpdf", "okular", "evince", 
"acroread", "xpdf", "firefox",
                                        "mozilla-firefox")
+                       else:
+                               raise ValueError("Unknown report type '%s'." % 
reportType)
 
                        viewer = None
                        for v in viewers:
@@ -75,12 +81,17 @@
                                        subprocess.Popen((viewer, path))
 
 
-def printPDF(path, printerName=None, printerPort=None, copies=1):
-       """Print the passed PDF file to the default printer.
+def previewPDF(*args, **kwargs):
+       """Deprecated; use previewReport() instead."""
+       previewReport(*args, **kwargs)
 
+
+def printReport(path, printerName=None, printerPort=None, copies=1):
+       """Print the passed report (txt or pdf) to the default printer.
+
        If gsprint is installed and on the path:
-               1) printerName specifies which printer to output to. 
-               2) printerPort specifies which port to output to.
+               1) printerName specifies which printer to output to. (None: use 
default printer)
+               2) printerPort specifies which port to output to. (None: use 
default port)
                3) multiple copies are handled more efficiently.
 
        NOTE: gsprint   is part of gsview, and gsview depends on ghostscript.
@@ -105,6 +116,11 @@
                                subprocess.Popen(("lpr", path))
 
 
+def printPDF(*args, **kwargs):
+       """Deprecated; use printReport() instead."""
+       printReport(*args, **kwargs)
+
+
 def getTestCursorXmlFromDataSet(dataset):
        """Returns the xml for insertion into a .rfxml file from a dataset."""
        from dabo.lib.xmltodict import escape



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to