[wxPython] dc.SetUserScale() not working...

I'm posting this to this list because the code is Python, not C++. If it is better directed at the other list, please let me know.

I am writing a class which reads print commands from a "printer file". I haven't gotten very far. I'm testing the code using a wxPrintPreview, and I am not able to get the output to scale using SetUserScale(). This is my first attempt at writing printer code.

In fact, I've determined that SetUserScale() is having no effect. There may be other problems with the scaling code, but this is the problem that's preventing me from going further.

If someone could please review this code and let me know what I'm doing wrong, it would be greatly appreciated. I am using Python2.0, the wxPython download for that release, and Window NT 4.

Thank you very much,
- Jake

···

===

# This file declares a printout class which reads its instructions
# from a file (or string) of 'printer' commands

from wxPython.wx import *

class jbPrintout(wxPrintout):
    def __init__(self, filename = '', title = ''):
        wxPrintout.__init__(self, title)
        f = open(filename, 'r')
        self.commands = f.readlines()
        f.close()
    def GetPageInfo(self):
        return (1, 1, 1, 1)
    def HasPage(self, pageNo):
        return pageNo == 1
    def mm2ph(self, mm):
        mmax = self.GetPageSizeMM()[0]
        pmax = self.GetPageSizePixels()[0]
        return int(pmax * (1.0 * mm / mmax) + .05)
    def mm2pv(self, mm):
        mmax = self.GetPageSizeMM()[1]
        pmax = self.GetPageSizePixels()[1]
        return int(pmax * (1.0 * mm / mmax) + .05)
    def SetScale(self, dc):
        scalex = 1.0 * dc.GetSize().width / self.GetPageSizePixels()[0]
        scaley = 1.0 * dc.GetSize().height / self.GetPageSizePixels()[1]
        print scalex, scaley
        dc.SetUserScale(scalex, scaley) # Seemingly has no effect
        
    def OnPrintPage(self, pageNo):
        assert pageNo == 1
        dc = self.GetDC()
        self.SetScale(dc)
        dc.SetFont(wxNORMAL_FONT)
        self.pos = pos = [0, 0]
        for command in self.commands:
            command = command.strip()
            i = command.find(' ')
            if i == -1:
                continue
            cmds = [command[:i]]
            cmds.extend(command[i:].split(','))
            if cmds[0].upper() == 'TEXTL':
                s = cmds[1].strip()
                dc.DrawText(s, pos[0], pos[1])
                pos[0] = dc.GetTextExtent(cmds[1])[0]
        dc.StartPage()
        return 1

# Test code
class MyApp(wxApp):
    def OnInit(self):
        printout = jbPrintout('data/printer.txt')
        printout2 = jbPrintout('data/printer.txt')
        preview = wxPrintPreview(printout, printout2)
        frame = wxPreviewFrame(preview, None, "Hello world!")
        frame.Initialize()
        frame.Show(true)
        return true

app = MyApp(0)
app.MainLoop()

===

The example input file ("data/printer.txt") contains the single line:
TextL Hello World!

Using python 2.1.1 and wxPython 2.3.1 (on Windows 2000), it appears to work
fine.

···

On Thursday 23 August 2001 11:26, you wrote:

In fact, I've determined that SetUserScale() is having no effect. There may
be other problems with the scaling code, but this is the problem that's
preventing me from going further.

--
Cliff Wells
Software Engineer
Logiplex Corporation
(800) 735-0555