Printing Samples

Hi,
the whole story about the preview frame issue
(wxpy 2.4.0.n and 2.4.1.2)

Code:

···

#-----------------------------------------
# prev3.py
#------------------------------------------

from wxPython.wx import *
import time

#----------------------------------------

class MyPrintout(wxPrintout):

    def __init__(self):
        wxPrintout.__init__(self)

    def OnPrintPage(self, page):
        dc = self.GetDC()
        dc.BeginDrawing()
        dc.SetBrush(wxBrush(wxWHITE, wxSOLID))
        dc.SetPen(wxPen(wxRED, 1, wxSOLID))
        dc.DrawRectangle(10, 10, 200, 200)
        dc.EndDrawing()

    def GetPageInfo(self):
        return (1, 1, 1, 1)

#-----------------------------------------

def preview(parent):

        pd = wxPrintData()
        printout = MyPrintout()

        printpreview = wxPrintPreview(printout, None, pd)
        printpreview.SetZoom(50)
        if not printpreview.Ok():
            wxMessageBox("Preview problem...", "Preview",
wxOK | wxICON_ERROR)
            return

        previewframe = wxPreviewFrame(printpreview, parent,
'.: Print preview :.')
        previewframe.Initialize()
        previewframe.SetPosition(wxPoint(0, 0))
        previewframe.SetSize(wxSize(800, 500))
        previewframe.Show()

#--------------------------------------

class MyFrame(wxFrame):

    def __init__(self, parent, id):
        wxFrame.__init__(self, parent, id, 'preview',
wxPoint(720, 120), wxSize(200, 100))

        pa = wxPanel(self, -1, wxDefaultPosition,
wxDefaultSize)
        preview(self)
        #~ pprint(self)
        #~ self.OnCloseWindow(None)

        EVT_LEFT_DOWN(self, self.OnCloseWindow)
        EVT_CLOSE(self, self.OnCloseWindow)

    def OnCloseWindow(self, event):
        self.Destroy()

#--------------------------------------------

class MyApp(wxApp):

    def OnInit(self):
        frame = MyFrame(None, -1)
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

#----------------------------------------------

def main():
    app = MyApp(0)
    app.MainLoop()

#---------------------------------------------

if __name__ == "__main__" :
    print 'running...'
    main()

#eof---------------------------------------------

Error description:

1) Running the code, preview and main frame are displayed.
The main window is active. The preview is not modal!
Clicling on the [x] button or selecting sys.menu, close:
that's
make the preview active, then the run time error.
2) Like 1) but clicking on the close button of the
print preview toolbar. The preview frame closes smoothly.
3) If I FIRST make the preview active, by clicking on
it. Everything is working fine.

My interpretation: the preview frame should be modal.

Jean-Michel Fauth, Switzerland

Jean-Michel Fauth wrote:

My interpretation: the preview frame should be modal.

So call previewframe.MakeModal(True)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Jean-Michel Fauth wrote:
>
> My interpretation: the preview frame should be modal.

So call previewframe.MakeModal(True)

I am experiencing the same problems as Jean-Michel Fauth. I added
previewframe.MakeModal(True) but it changeed nothing. I am still getting the
run time error.
BTW: If I first make the preview active, by clicking on it, like Jean-Michel
Fauth suggeted it doesn't solve the problem (I am getting the run time error
again).

Running on WinXP pro, wxPython 2.4.0.7, Python 2.2.2.