[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7189 - in trunk/gnue-reports/src/adapters: destinations/printer
From: |
btami |
Subject: |
[gnue] r7189 - in trunk/gnue-reports/src/adapters: destinations/printer filters/Char/etc/printdef filters/Char/universal filters/Char/universal/CHObjects |
Date: |
Sat, 12 Mar 2005 05:58:30 -0600 (CST) |
Author: btami
Date: 2005-03-12 05:58:29 -0600 (Sat, 12 Mar 2005)
New Revision: 7189
Added:
trunk/gnue-reports/src/adapters/destinations/printer/gdi.py
trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/xml.grp
Modified:
trunk/gnue-reports/src/adapters/destinations/printer/__init__.py
trunk/gnue-reports/src/adapters/destinations/printer/bsd.py
trunk/gnue-reports/src/adapters/destinations/printer/win32raw.py
trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/escp.grp
trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/html.grp
trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/lineprinter.grp
trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/pcl5.grp
trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/ps2-letter.grp
trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/test.grp
trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/text-dos.grp
trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/text.grp
trunk/gnue-reports/src/adapters/filters/Char/universal/Adapter.py
trunk/gnue-reports/src/adapters/filters/Char/universal/CHObjects/CHTitlePage.py
trunk/gnue-reports/src/adapters/filters/Char/universal/Writer.py
Log:
New xml printdef for gdi printer driver
Property changes on:
trunk/gnue-reports/src/adapters/destinations/printer/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/gnue-reports/src/adapters/destinations/printer/bsd.py
===================================================================
--- trunk/gnue-reports/src/adapters/destinations/printer/bsd.py 2005-03-12
11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/destinations/printer/bsd.py 2005-03-12
11:58:29 UTC (rev 7189)
@@ -18,16 +18,12 @@
#
# Copyright 2002-2005 Free Software Foundation
#
-# FILE:
-# printer/bsd.py
-#
-# DESCRIPTION:
-# Basic destination adapter for writing to BSD lpr
-#
-# NOTES:
-#
+# $Id$
+
+"""
+Basic destination adapter for writing to BSD lpr
+"""
-
from gnue.reports import VERSION
from gnue.reports.base.GROutputAdapter import DestinationAdapter as Base
from gnue.common.apps import GDebug
Property changes on: trunk/gnue-reports/src/adapters/destinations/printer/bsd.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-reports/src/adapters/destinations/printer/gdi.py
===================================================================
--- trunk/gnue-reports/src/adapters/destinations/printer/gdi.py 2005-03-12
11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/destinations/printer/gdi.py 2005-03-12
11:58:29 UTC (rev 7189)
@@ -0,0 +1,195 @@
+#
+# Copyright 2002-2005 Free Software Foundation
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+"""
+Basic destination adapter for writing xml data
+based on Char layout to win32 GDI printers
+"""
+
+import xml.sax
+import win32ui, win32con
+import math, string, sys, os
+from pywin.mfc import window, dialog
+
+from gnue.reports.base.GROutputAdapter import DestinationAdapter as Base
+from gnue.common.apps import GDebug
+
+PRINTDLGORD = 1538
+PRINTER = 1139
+
+
+class PrintDialog(dialog.Dialog):
+ def __init__(self, dlgID, dllid=None):
+ printSetupOnly = 0
+ flags=(win32ui.PD_ALLPAGES|
+ win32ui.PD_USEDEVMODECOPIES|
+ win32ui.PD_NOPAGENUMS|
+ win32ui.PD_HIDEPRINTTOFILE|
+ win32ui.PD_NOSELECTION)
+
+ parent=None
+ dlg = win32ui.CreatePrintDialog(dlgID, printSetupOnly, flags, parent,
dllid)
+ window.Wnd.__init__(self, dlg)
+ self.HookCommands()
+ self.bHaveInit = None
+
+ def OnOK(self):
+ self._obj_.OnOK()
+ self['deviceName'] = self.GetDlgItem(PRINTER).GetWindowText()
+
+
+class DestinationAdapter(Base, xml.sax.ContentHandler):
+
+ #
+ # Typically, a transform adapter will call EITHER
+ # getOutputHandle or getOutputFile, not both.
+ #
+ # return a stream handle for outut by
+ # the transform adapter
+ #
+ def getOutputHandle(self):
+ self.usingHandle = 1
+ self.input, self.tempfile = self.createTempFile()
+ return self.input
+
+ #
+ # return a file name for outut by the
+ # transform adapter
+ #
+ def getOutputFile(self):
+ self.usingHandle = 0
+ self.input, self.tempfile = self.createTempFile()
+ self.input.close()
+ return self.tempfile
+
+ #
+ # Wrap up
+ #
+ def close(self, mimetype='plain/text'):
+
+ if self.usingHandle:
+ self.input.close()
+
+ file = self.tempfile
+
+ print_to = string.replace(string.replace(self.destination, "`",""),';','')
+ if print_to == '-':
+ pDialog = PrintDialog(PRINTDLGORD)
+ pDialog.DoModal()
+ try:
+ # OK selected
+ print_to = pDialog['deviceName']
+ except KeyError:
+ # Cancel selected
+ self.deleteTempFile(self.tempfile)
+ return
+
+ self.setup(print_to)
+
+ infile = open(file, 'r')
+
+ # Create a parser
+ parser = xml.sax.make_parser()
+
+ # Tell the parser to use our handler
+ parser.setContentHandler(self)
+ parser.parse(infile)
+
+ infile.close()
+
+ self.deleteTempFile(self.tempfile)
+
+
+ # XML handling stuff
+ def startElement(self, name, attrs):
+ if name == "report":
+ self.dc.StartDoc(name)
+
+ elif name == "page":
+ self.dc.StartPage()
+
+ elif name == "label":
+ self._attrs = attrs
+ self.dc.SelectObject(FONTS['normal'])
+
+ elif name == "b":
+ self.dc.SelectObject(FONTS['bold'])
+
+ elif name == "i":
+ self.dc.SelectObject(FONTS['italic'])
+
+ self._text = ''
+
+
+ def characters(self, text):
+ self._text += text
+
+
+ def endElement(self, name):
+ if name == "report":
+ self.dc.EndDoc()
+
+ elif name == "page":
+ self.dc.EndPage()
+
+ elif name == "label":
+ h = self.metrics['height']
+ w = self.metrics['width']
+ self.dc.TextOut(int(w * int(self._attrs['x'])),
+ int( - h * 1.3 * int(self._attrs['y'])),
+ self._text)
+
+ def setup(self, printer):
+ self.dc = win32ui.CreateDC()
+ self.dc.CreatePrinterDC(printer)
+ self.dc.SetMapMode(win32con.MM_TWIPS)
+
+ self.dc.SelectObject(FONTS['normal'])
+ m = self.dc.GetTextMetrics()
+
+ self.metrics = {}
+ self.metrics['width'] = m['tmMaxCharWidth']
+ self.metrics['height'] = m['tmHeight']
+
+
+def createFonts():
+ fonts = {}
+ font_specs = {
+ 'normal' : {
+ 'name': 'Courier New',
+ 'size': 12,
+ 'weight': 400},
+ 'bold' : {
+ 'name': 'Courier New',
+ 'size': 12,
+ 'weight': 800},
+ 'italic' : {
+ 'name': 'Courier New',
+ 'size': 12,
+ 'weight': 400,
+ 'italic': 1}
+ }
+ for spec in ['normal', 'bold', 'italic']:
+ fonts[spec] = win32ui.CreateFont(font_specs[spec])
+ return fonts
+
+FONTS = createFonts()
Property changes on: trunk/gnue-reports/src/adapters/destinations/printer/gdi.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/gnue-reports/src/adapters/destinations/printer/win32raw.py
===================================================================
--- trunk/gnue-reports/src/adapters/destinations/printer/win32raw.py
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/destinations/printer/win32raw.py
2005-03-12 11:58:29 UTC (rev 7189)
@@ -1,4 +1,6 @@
#
+# Copyright 2002-2005 Free Software Foundation
+#
# This file is part of GNU Enterprise.
#
# GNU Enterprise is free software; you can redistribute it
@@ -16,17 +18,12 @@
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# Copyright 2002-2005 Free Software Foundation
-#
-# FILE:
-# printer/win32raw.py
-#
-# DESCRIPTION:
-# Basic destination adapter for writing raw data (text/ps/pcl/esc-p) to win32
printer
-#
-# NOTES:
-#
+# $Id$
+"""
+Basic destination adapter for writing raw data
+(text/ps/pcl/esc-p) to win32 printers
+"""
from gnue.reports import VERSION
from gnue.reports.base.GROutputAdapter import DestinationAdapter as Base
Property changes on:
trunk/gnue-reports/src/adapters/destinations/printer/win32raw.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/escp.grp
===================================================================
--- trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/escp.grp
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/escp.grp
2005-03-12 11:58:29 UTC (rev 7189)
@@ -18,6 +18,8 @@
graphics_end=
line_begin=
line_end=\r\n
+label_begin=
+label_end=
underline_begin=\x1B-1
underline_end=\x1B-0
condensed_begin=\x0F
Modified: trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/html.grp
===================================================================
--- trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/html.grp
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/html.grp
2005-03-12 11:58:29 UTC (rev 7189)
@@ -22,6 +22,8 @@
graphics_end=
line_begin=
line_end=<br/>
+label_begin=
+label_end=
underline_begin=<u>
underline_end=</u>
condensed_begin=<font size="-2">
Modified:
trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/lineprinter.grp
===================================================================
--- trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/lineprinter.grp
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/lineprinter.grp
2005-03-12 11:58:29 UTC (rev 7189)
@@ -17,6 +17,8 @@
graphics_end=
line_begin=
line_end=\r\n
+label_begin=
+label_end=
underline_begin=
underline_end=
condensed_begin=
Modified: trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/pcl5.grp
===================================================================
--- trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/pcl5.grp
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/pcl5.grp
2005-03-12 11:58:29 UTC (rev 7189)
@@ -17,6 +17,8 @@
graphics_end=
line_begin=
line_end=\r\n
+label_begin=
+label_end=
underline_begin=\x1B&d1D
underline_end=\x1B&d@
condensed_begin=\x1B(s16.67H
Modified:
trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/ps2-letter.grp
===================================================================
--- trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/ps2-letter.grp
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/ps2-letter.grp
2005-03-12 11:58:29 UTC (rev 7189)
@@ -25,6 +25,8 @@
graphics_end=
line_begin=
line_end=
+label_begin=
+label_end=
underline_begin=
underline_end=
condensed_begin=
Modified: trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/test.grp
===================================================================
--- trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/test.grp
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/test.grp
2005-03-12 11:58:29 UTC (rev 7189)
@@ -18,6 +18,8 @@
graphics_end={egraphics}
line_begin={bline}
line_end={eline}\n
+label_begin={blabel}
+label_end={elabel}
underline_begin={buline}
underline_end={euline}
condensed_begin={bcond}
Modified: trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/text-dos.grp
===================================================================
--- trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/text-dos.grp
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/text-dos.grp
2005-03-12 11:58:29 UTC (rev 7189)
@@ -17,6 +17,8 @@
graphics_end=
line_begin=
line_end=\r\n
+label_begin=
+label_end=
underline_begin=
underline_end=
condensed_begin=
Modified: trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/text.grp
===================================================================
--- trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/text.grp
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/text.grp
2005-03-12 11:58:29 UTC (rev 7189)
@@ -17,6 +17,8 @@
graphics_end=
line_begin=
line_end=\n
+label_begin=
+label_end=
underline_begin=
underline_end=
condensed_begin=
Added: trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/xml.grp
===================================================================
--- trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/xml.grp
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/filters/Char/etc/printdef/xml.grp
2005-03-12 11:58:29 UTC (rev 7189)
@@ -0,0 +1,38 @@
+description=Plain Text
+mime_type=text/plain
+
+default_lines=66
+default_columns=80
+graphics_format=none
+
+# Escape sequences
+escape_map=
+escape_map=>>
+escape_map=<<
+escape_map=&&
+
+# Various escape sequences
+job_begin=<?xml version="1.0" encoding="%s"?>\n
+job_begin+=<report>\n
+job_end=</report>
+page_begin=<page>
+page_end=</page>
+graphics_begin=
+graphics_end=
+line_begin=
+line_end=
+label_begin=<label x="%s" y="%s">
+label_end=</label>
+underline_begin=<u>
+underline_end=</u>
+condensed_begin=<c>
+condensed_end=</c>
+bold_begin=<b>
+bold_end=</b>
+italic_begin=<i>
+italic_end=</i>
+doublewide_begin=
+doublewide_end=
+doubleheight_begin=
+doubleheight_end=
+
Modified: trunk/gnue-reports/src/adapters/filters/Char/universal/Adapter.py
===================================================================
--- trunk/gnue-reports/src/adapters/filters/Char/universal/Adapter.py
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/filters/Char/universal/Adapter.py
2005-03-12 11:58:29 UTC (rev 7189)
@@ -19,26 +19,21 @@
# Copyright 2003-2004 Free Software Foundation
#
# $Id: Adapter.py 6763 2004-11-30 23:36:21Z jcater $
-#
-# DESCRIPTION:
+
"""
Class that contains the base filter adapter for GNUe Reports'
"Char" markup.
"""
-# NOTES:
-#
from gnue.reports.base.GROutputAdapter import TransformAdapter as Base
from CHParser import loadFile
-from PrinterDef import PrinterDefinition
from Writer import Writer
class TransformAdapter(Base):
def __init__(self, *args, **parms):
Base.__init__(self, *args, **parms)
- self.writer = Writer(
- PrinterDefinition(self.parameters.get('formatter','text')))
+ self.writer = Writer(self.parameters.get('formatter','text'))
def open(self):
# We need a temp file
Modified:
trunk/gnue-reports/src/adapters/filters/Char/universal/CHObjects/CHTitlePage.py
===================================================================
---
trunk/gnue-reports/src/adapters/filters/Char/universal/CHObjects/CHTitlePage.py
2005-03-12 11:45:05 UTC (rev 7188)
+++
trunk/gnue-reports/src/adapters/filters/Char/universal/CHObjects/CHTitlePage.py
2005-03-12 11:58:29 UTC (rev 7189)
@@ -41,6 +41,7 @@
def process(self, writer):
+ writer.newPage()
writer.pageHeaderDone = True
writer.pageFooterDone = True
Modified: trunk/gnue-reports/src/adapters/filters/Char/universal/Writer.py
===================================================================
--- trunk/gnue-reports/src/adapters/filters/Char/universal/Writer.py
2005-03-12 11:45:05 UTC (rev 7188)
+++ trunk/gnue-reports/src/adapters/filters/Char/universal/Writer.py
2005-03-12 11:58:29 UTC (rev 7189)
@@ -19,22 +19,19 @@
# Copyright 2003-2004 Free Software Foundation
#
# $Id: Writer.py 6764 2004-12-01 00:34:26Z jcater $
-#
-# DESCRIPTION:
-#
-# NOTES:
-#
__all__ = ['Writer']
import string
+from PrinterDef import PrinterDefinition
class Writer:
- def __init__(self, printdef):
- self.printdef = printdef
+ def __init__(self, formatter):
+ self.formatter = formatter
+ self.printdef = PrinterDefinition(formatter)
def initialize(self, report):
self.reportHeight = report.height
@@ -46,7 +43,10 @@
self.pageHeaderDone = False
self.pageFooterDone = False
- self.output.write(self.printdef['job_begin'])
+ if self.formatter == "xml":
+ self.output.write(self.printdef['job_begin'] % gConfig('textEncoding'))
+ else:
+ self.output.write(self.printdef['job_begin'])
def finalize(self):
@@ -69,8 +69,12 @@
text = text[:line[i+1][0] - x]
# Move us to correct X position
if cx < x:
- outputLine += self.printdef.escape(' '*(x-cx))
+ if self.formatter != "xml":
+ outputLine += self.printdef.escape(' '*(x-cx))
cx = x
+
+ if self.formatter == "xml" and prefix[:6] == '<label':
+ prefix = prefix % (cx, self.currLine)
outputLine += prefix + \
self.printdef.escape(text).encode(_encoding,'replace') +
\
@@ -90,7 +94,7 @@
except:
curline = band.buffer[y] = []
- prefix = postfix = ""
+ prefix = self.printdef['label_begin']
# start style
if condensed:
prefix += self.printdef['condensed_begin']
@@ -104,6 +108,7 @@
# end style... these should be the
# reverse of the "Start" lines above.
+ postfix = ""
if underline:
postfix += self.printdef['underline_end']
if italic:
@@ -112,6 +117,8 @@
postfix += self.printdef['bold_end']
if condensed:
postfix += self.printdef['condensed_end']
+
+ postfix += self.printdef['label_end']
curline.append((x, _alignFunc[align](object[:width], width), prefix,
postfix))
@@ -145,7 +152,10 @@
def printLines(self, lines, bandtype):
for line in lines:
- self.printLine(line, bandtype)
+ if self.formatter == "xml":
+ self.currLine += 1
+ else:
+ self.printLine(line, bandtype)
_alignFunc = {'left' : lambda obj, width: string.ljust(obj, width),
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7189 - in trunk/gnue-reports/src/adapters: destinations/printer filters/Char/etc/printdef filters/Char/universal filters/Char/universal/CHObjects,
btami <=