1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
   |  
#! /usr/bin/env python
 
from wx import *
 
class MonPrintout(Printout):
	def __init__(self, titre,TblLignes):
		Printout.__init__(self, titre)
		self.TblLignes=TblLignes
 
	def HasPage(self,page):
		return page <= 1
 
	def GetPageInfo(self):
		return (1, 1, 1, 1)
 
	def OnPrintPage(self, page):
		dc = self.GetDC()
		dc.SetMapMode(MM_POINTS)
 
		for IndLgn in range(len(self.TblLignes)):
			dc.DrawText(self.TblLignes[IndLgn], 10, IndLgn*5)
		return True
 
class MainWindow(Frame):
	def __init__(self, parent, id, title):
		Frame.__init__(self, parent, -1, title, size=(500, 500))
		id_bouton = NewId()
		Button(self, id_bouton, 'Imprimer', Point(200, 200))
		EVT_BUTTON(self, id_bouton, self.OnPrintBouton)
 
		self.TblLignes=[]
		self.TblLignes.append("Ligne 1")
		self.TblLignes.append("Ligne 2")
		self.TblLignes.append("Ligne 3")
		self.TblLignes.append("Ligne 4")
 
	def OnPrintBouton(self, event):
		pd = PrintData()
		pd.SetPrinterName('')
		pd.SetOrientation(PORTRAIT)
		pd.SetPaperId(PAPER_A4)
		pd.SetQuality(PRINT_QUALITY_DRAFT)
		pd.SetColour(False) # impression noir et blanc
		pd.SetNoCopies(1)
		pd.SetCollate(True)
		pdd = PrintDialogData()
		pdd.SetPrintData(pd)
		pdd.SetMinPage(1)
		pdd.SetMaxPage(1)
		pdd.SetFromPage(1)
		pdd.SetToPage(1)
		pdd.SetPrintToFile(False)
		printer = Printer(pdd)
		monprintout = MonPrintout("mon objet d'impression",self.TblLignes)
		printer.Print(self, monprintout, False)
 
	def OnCloseWindow(self, event):
		self.Destroy()
 
class App(App):
	def OnInit(self):
		frame = MainWindow(None, -1, "Demo d'impression avec wxPython")
		self.SetTopWindow(frame)
		frame.Show(True)
		return True
 
app = App(0)
app.MainLoop() | 
Partager