]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/PrintFramework.py
Added GetResourcesDir and GetLocalizedResourcesDir to
[wxWidgets.git] / wxPython / demo / PrintFramework.py
index ce6c1ff603ceeb33107b2d74ff34288e72cc0c01..6aa0b5700f809c926ca76572b0c8d347fa3d7fae 100644 (file)
@@ -1,12 +1,6 @@
-# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
-#
-# o Updated for wx namespace
-# o Got rid of static buton IDs
-# o Took at a stab at a lucid overview string.
-#
 
 import  wx
 
 import  wx
-import  wxScrolledWindow
+import  ScrolledWindow
 
 #----------------------------------------------------------------------
 
 
 #----------------------------------------------------------------------
 
@@ -21,38 +15,38 @@ class MyPrintout(wx.Printout):
         self.log = log
 
     def OnBeginDocument(self, start, end):
         self.log = log
 
     def OnBeginDocument(self, start, end):
-        self.log.WriteText("wx.Printout.OnBeginDocument\n")
-        return self.base_OnBeginDocument(start, end)
+        self.log.WriteText("MyPrintout.OnBeginDocument\n")
+        return super(MyPrintout, self).OnBeginDocument(start, end)
 
     def OnEndDocument(self):
 
     def OnEndDocument(self):
-        self.log.WriteText("wx.Printout.OnEndDocument\n")
-        self.base_OnEndDocument()
+        self.log.WriteText("MyPrintout.OnEndDocument\n")
+        super(MyPrintout, self).OnEndDocument()
 
     def OnBeginPrinting(self):
 
     def OnBeginPrinting(self):
-        self.log.WriteText("wx.Printout.OnBeginPrinting\n")
-        self.base_OnBeginPrinting()
+        self.log.WriteText("MyPrintout.OnBeginPrinting\n")
+        super(MyPrintout, self).OnBeginPrinting()
 
     def OnEndPrinting(self):
 
     def OnEndPrinting(self):
-        self.log.WriteText("wx.Printout.OnEndPrinting\n")
-        self.base_OnEndPrinting()
+        self.log.WriteText("MyPrintout.OnEndPrinting\n")
+        super(MyPrintout, self).OnEndPrinting()
 
     def OnPreparePrinting(self):
 
     def OnPreparePrinting(self):
-        self.log.WriteText("wx.Printout.OnPreparePrinting\n")
-        self.base_OnPreparePrinting()
+        self.log.WriteText("MyPrintout.OnPreparePrinting\n")
+        super(MyPrintout, self).OnPreparePrinting()
 
     def HasPage(self, page):
 
     def HasPage(self, page):
-        self.log.WriteText("wx.Printout.HasPage: %d\n" % page)
+        self.log.WriteText("MyPrintout.HasPage: %d\n" % page)
         if page <= 2:
             return True
         else:
             return False
 
     def GetPageInfo(self):
         if page <= 2:
             return True
         else:
             return False
 
     def GetPageInfo(self):
-        self.log.WriteText("wx.Printout.GetPageInfo\n")
+        self.log.WriteText("MyPrintout.GetPageInfo\n")
         return (1, 2, 1, 2)
 
     def OnPrintPage(self, page):
         return (1, 2, 1, 2)
 
     def OnPrintPage(self, page):
-        self.log.WriteText("wx.Printout.OnPrintPage: %d\n" % page)
+        self.log.WriteText("MyPrintout.OnPrintPage: %d\n" % page)
         dc = self.GetDC()
 
         #-------------------------------------------
         dc = self.GetDC()
 
         #-------------------------------------------
@@ -90,7 +84,7 @@ class MyPrintout(wx.Printout):
         #-------------------------------------------
 
         self.canvas.DoDrawing(dc, True)
         #-------------------------------------------
 
         self.canvas.DoDrawing(dc, True)
-        dc.DrawText("Page: %d" % page, (marginX/2, maxY-marginY))
+        dc.DrawText("Page: %d" % page, marginX/2, maxY-marginY)
 
         return True
 
 
         return True
 
@@ -106,22 +100,23 @@ class TestPrintPanel(wx.Panel):
 
         self.printData = wx.PrintData()
         self.printData.SetPaperId(wx.PAPER_LETTER)
 
         self.printData = wx.PrintData()
         self.printData.SetPaperId(wx.PAPER_LETTER)
-
+        self.printData.SetPrintMode(wx.PRINT_MODE_PRINTER)
+        
         self.box = wx.BoxSizer(wx.VERTICAL)
         self.box = wx.BoxSizer(wx.VERTICAL)
-        self.canvas = wxScrolledWindow.MyCanvas(self)
+        self.canvas = ScrolledWindow.MyCanvas(self)
         self.box.Add(self.canvas, 1, wx.GROW)
 
         subbox = wx.BoxSizer(wx.HORIZONTAL)
         btn = wx.Button(self, ID_Setup, "Print Setup")
         self.box.Add(self.canvas, 1, wx.GROW)
 
         subbox = wx.BoxSizer(wx.HORIZONTAL)
         btn = wx.Button(self, ID_Setup, "Print Setup")
-        self.Bind(wx.EVT_BUTTON, self.OnPrintSetup, id=ID_Setup)
+        self.Bind(wx.EVT_BUTTON, self.OnPrintSetup, btn)
         subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
 
         btn = wx.Button(self, ID_Preview, "Print Preview")
         subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
 
         btn = wx.Button(self, ID_Preview, "Print Preview")
-        self.Bind(wx.EVT_BUTTON, self.OnPrintPreview, id=ID_Preview)
+        self.Bind(wx.EVT_BUTTON, self.OnPrintPreview, btn)
         subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
 
         btn = wx.Button(self, ID_Print, "Print")
         subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
 
         btn = wx.Button(self, ID_Print, "Print")
-        self.Bind(wx.EVT_BUTTON, self.OnDoPrint, id=ID_Print)
+        self.Bind(wx.EVT_BUTTON, self.OnDoPrint, btn)
         subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
 
         self.box.Add(subbox, 0, wx.GROW)
         subbox.Add(btn, 1, wx.GROW | wx.ALL, 2)
 
         self.box.Add(subbox, 0, wx.GROW)
@@ -131,19 +126,25 @@ class TestPrintPanel(wx.Panel):
 
 
     def OnPrintSetup(self, event):
 
 
     def OnPrintSetup(self, event):
-        printerDialog = wx.PrintDialog(self)
-        printerDialog.GetPrintDialogData().SetPrintData(self.printData)
-        printerDialog.GetPrintDialogData().SetSetupDialog(True)
+        data = wx.PrintDialogData(self.printData)
+        printerDialog = wx.PrintDialog(self, data)
+        #printerDialog.GetPrintDialogData().SetSetupDialog(True)
         printerDialog.ShowModal();
         printerDialog.ShowModal();
-        self.printData = printerDialog.GetPrintDialogData().GetPrintData()
+
+        # this makes a copy of the wx.PrintData instead of just saving
+        # a reference to the one inside the PrintDialogData that will
+        # be destroyed when the dialog is destroyed
+        self.printData = wx.PrintData( printerDialog.GetPrintDialogData().GetPrintData() )
+        
         printerDialog.Destroy()
 
 
     def OnPrintPreview(self, event):
         self.log.WriteText("OnPrintPreview\n")
         printerDialog.Destroy()
 
 
     def OnPrintPreview(self, event):
         self.log.WriteText("OnPrintPreview\n")
+        data = wx.PrintDialogData(self.printData)
         printout = MyPrintout(self.canvas, self.log)
         printout2 = MyPrintout(self.canvas, self.log)
         printout = MyPrintout(self.canvas, self.log)
         printout2 = MyPrintout(self.canvas, self.log)
-        self.preview = wx.PrintPreview(printout, printout2, self.printData)
+        self.preview = wx.PrintPreview(printout, printout2, data)
 
         if not self.preview.Ok():
             self.log.WriteText("Houston, we have a problem...\n")
 
         if not self.preview.Ok():
             self.log.WriteText("Houston, we have a problem...\n")
@@ -159,15 +160,15 @@ class TestPrintPanel(wx.Panel):
 
 
     def OnDoPrint(self, event):
 
 
     def OnDoPrint(self, event):
-        pdd = wx.PrintDialogData()
-        pdd.SetPrintData(self.printData)
+        pdd = wx.PrintDialogData(self.printData)
+        pdd.SetToPage(2)
         printer = wx.Printer(pdd)
         printout = MyPrintout(self.canvas, self.log)
 
         printer = wx.Printer(pdd)
         printout = MyPrintout(self.canvas, self.log)
 
-        if not printer.Print(self.frame, printout):
+        if not printer.Print(self.frame, printout, True):
             wx.MessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wx.OK)
         else:
             wx.MessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wx.OK)
         else:
-            self.printData = printer.GetPrintDialogData().GetPrintData()
+            self.printData = wx.PrintData( printer.GetPrintDialogData().GetPrintData() )
         printout.Destroy()
 
 
         printout.Destroy()
 
 
@@ -230,5 +231,5 @@ framework in wxPython.
 if __name__ == '__main__':
     import sys,os
     import run
 if __name__ == '__main__':
     import sys,os
     import run
-    run.main(['', os.path.basename(sys.argv[0])])
+    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])