Printer & redirection follow-up

Albert Wagner alwagner at tcac.net
Mon Apr 17 09:03:50 EDT 2000


To all who replied to my posts, thanks again. Below is the result of my
hacking and your advice.  For you Windows guys:  This works under Linux;
will it work under Windows?

#
import sys
from DisplayFileList import *
try:
    queue = 'lpt'
    from win32pipe import popen
except ImportError:
    queue = 'lpr'
    from os import popen
        

class Paginator:

    def __init__(self):
        self.lineCount = 0
        self.linesMax = 50
        self.pageCount = 1
        
    def printList(self, rootDir, rootName):
        self.rootName = rootName
        self.displayer = DisplayFileList()
        sys.stdout = self       # Output of displayer redirected here
        self.printer = popen(queue, 'w')
        self.displayer.displayTree(rootDir) #prints to sys.stdout
        self.printer.close()
        sys.stdout = sys.__stdout__
        
    def write(self, aLine):     #Used by sys.stdout
        if self.lineCount == 0: #If first page then...
            self.pageHeader()   #print 1st page header 
        self.printer.write(aLine)
        if len(aLine) > 1:      #only count real lines, not \n only
lines
            self.lineCount = self.lineCount + 1
        if self.lineCount > self.linesMax:  #If end of page then...
            self.printer.write("\f")        #eject and print page header
            self.pageHeader()

    def pageHeader(self):
	<snip>

-- 
Small is Beautiful



More information about the Python-list mailing list