#!/usr/bin/env python

from wxPython.wx import *

class StdPrintout(wxPrintout):

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

    def OnPrintPage(self, page):
        dc = self.GetDC()
        PrepareStdPrintout(dc)
        return True

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

class MyPanel(wxPanel):

    def __init__(self, parent):
        wxPanel.__init__(self, parent, -1, wxDefaultPosition, wxDefaultSize)
        self.parent = parent

        self.b1 = wxButton(self, 1001, 'std wxPreview', wxPoint(0,0), wxDefaultSize)
        EVT_BUTTON(self, 1001, self.OnBut1)


    #standard wxPreview
    def OnBut1(self, event):
        pd = wxPrintData()
        pd.SetOrientation(wxPORTRAIT)
        printout = StdPrintout()
        printpreview = wxPrintPreview(printout, None, pd)
        printpreview.SetZoom(50)
        pos, size = wxPoint(0, 0), wxSize(700, 600)
        previewframe = wxPreviewFrame(printpreview, None, 'Std preview', pos, size)
        previewframe.Initialize()
        previewframe.Show()
        #do not destroy the printout object!

class MyFrame(wxFrame):

    def __init__(self, parent, id):
        wxFrame.__init__(self, parent, id, "MyPrintPreview7", wxPoint(10,10), wxSize(400, 400))
        self.panel = MyPanel(self)

        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__" :
    main()
