| 1 |
ninoborges |
8 |
## testPrint
|
| 2 |
|
|
|
| 3 |
|
|
|
| 4 |
|
|
|
| 5 |
|
|
from wxPython.wx import *
|
| 6 |
|
|
from Printer2 import MyPrintout
|
| 7 |
|
|
|
| 8 |
|
|
|
| 9 |
|
|
ID_ABOUT = 101
|
| 10 |
|
|
ID_EXIT = 102
|
| 11 |
|
|
ID_NEW = 103
|
| 12 |
|
|
ID_PRINT = 104
|
| 13 |
|
|
ID_PRINT_SETUP = 105
|
| 14 |
|
|
ID_PRINT_PREVIEW = 106
|
| 15 |
|
|
|
| 16 |
|
|
class MyFrame(wxFrame):
|
| 17 |
|
|
def __init__(self, parent, ID, title):
|
| 18 |
|
|
wxFrame.__init__(self, parent, ID, title,
|
| 19 |
|
|
wxDefaultPosition, wxSize(600, 500))
|
| 20 |
|
|
self.CreateStatusBar()
|
| 21 |
|
|
self.SetStatusText("Ready.")
|
| 22 |
|
|
# Create the File Menu <Start>
|
| 23 |
|
|
fileMenu = wxMenu()
|
| 24 |
|
|
fileMenu.Append(ID_NEW, "&New Project...",
|
| 25 |
|
|
"Create a new project.")
|
| 26 |
|
|
fileMenu.Append(ID_PRINT, "&Print", "Print Something")
|
| 27 |
|
|
fileMenu.Append(ID_PRINT_SETUP, "Print &Setup", "Printer Setup")
|
| 28 |
|
|
fileMenu.Append(ID_PRINT_PREVIEW, "Print Preview","Print preview")
|
| 29 |
|
|
fileMenu.AppendSeparator()
|
| 30 |
|
|
fileMenu.Append(ID_EXIT, "E&xit", "Terminate the program")
|
| 31 |
|
|
|
| 32 |
|
|
mainMenuBar = wxMenuBar()
|
| 33 |
|
|
mainMenuBar.Append(fileMenu, "&File");
|
| 34 |
|
|
# File Menu <End>
|
| 35 |
|
|
|
| 36 |
|
|
# Creat Help Menu <Start>
|
| 37 |
|
|
helpMenu = wxMenu()
|
| 38 |
|
|
helpMenu.Append(ID_ABOUT, "&About",
|
| 39 |
|
|
"More information about this program")
|
| 40 |
|
|
#helpMenuBar = wxMenuBar()
|
| 41 |
|
|
mainMenuBar.Append(helpMenu, "&Help");
|
| 42 |
|
|
|
| 43 |
|
|
# Help Menu <End>
|
| 44 |
|
|
self.SetMenuBar(mainMenuBar)
|
| 45 |
|
|
|
| 46 |
|
|
EVT_MENU(self,ID_NEW, self.TimeToQuit)
|
| 47 |
|
|
EVT_MENU(self, ID_ABOUT, self.OnAbout)
|
| 48 |
|
|
EVT_MENU(self, ID_EXIT, self.TimeToQuit)
|
| 49 |
|
|
EVT_MENU(self, ID_PRINT, self.OnDoPrint)
|
| 50 |
|
|
EVT_MENU(self, ID_PRINT_SETUP, self.OnPrintSetup)
|
| 51 |
|
|
EVT_MENU(self, ID_PRINT_PREVIEW, self.OnPrintPreview)
|
| 52 |
|
|
#self.printer = Printer(self)
|
| 53 |
|
|
test = wxImage(self)
|
| 54 |
|
|
self.canvas = test.LoadFile(self,'c:\\test_dir\\test.bmp',wxBITMAP_TYPE_BMP)
|
| 55 |
|
|
self.printData = wxPrintData()
|
| 56 |
|
|
self.printData.SetPaperId(wxPAPER_LETTER)
|
| 57 |
|
|
|
| 58 |
|
|
|
| 59 |
|
|
|
| 60 |
|
|
def OnPrintSetup(self, event):
|
| 61 |
|
|
printerDialog = wxPrintDialog(self)
|
| 62 |
|
|
printerDialog.GetPrintDialogData().SetPrintData(self.printData)
|
| 63 |
|
|
printerDialog.GetPrintDialogData().SetSetupDialog(True)
|
| 64 |
|
|
printerDialog.ShowModal();
|
| 65 |
|
|
self.printData = printerDialog.GetPrintDialogData().GetPrintData()
|
| 66 |
|
|
printerDialog.Destroy()
|
| 67 |
|
|
|
| 68 |
|
|
def OnPrintPreview(self, event):
|
| 69 |
|
|
#self.log.WriteText("OnPrintPreview\n")
|
| 70 |
|
|
printout = MyPrintout(self.canvas)
|
| 71 |
|
|
printout2 = MyPrintout(self.canvas)
|
| 72 |
|
|
self.preview = wxPrintPreview(printout, printout2, self.printData)
|
| 73 |
|
|
if not self.preview.Ok():
|
| 74 |
|
|
self.log.WriteText("Houston, we have a problem...\n")
|
| 75 |
|
|
return
|
| 76 |
|
|
|
| 77 |
|
|
frame = wxPreviewFrame(self.preview, self, "This is a print preview")
|
| 78 |
|
|
|
| 79 |
|
|
frame.Initialize()
|
| 80 |
|
|
frame.SetPosition(self.GetPosition())
|
| 81 |
|
|
frame.SetSize(self.GetSize())
|
| 82 |
|
|
frame.Show(True)
|
| 83 |
|
|
|
| 84 |
|
|
def OnDoPrint(self, event):
|
| 85 |
|
|
pdd = wxPrintDialogData()
|
| 86 |
|
|
pdd.SetPrintData(self.printData)
|
| 87 |
|
|
printer = wxPrinter(pdd)
|
| 88 |
|
|
printout = MyPrintout(self.canvas)
|
| 89 |
|
|
if not printer.Print(self, printout):
|
| 90 |
|
|
wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK)
|
| 91 |
|
|
else:
|
| 92 |
|
|
self.printData = printer.GetPrintDialogData().GetPrintData()
|
| 93 |
|
|
printout.Destroy()
|
| 94 |
|
|
|
| 95 |
|
|
def OnAbout(self, event):
|
| 96 |
|
|
dlg = wxMessageDialog(self, "This program allows you to do\n"
|
| 97 |
|
|
"various things that extend Summaion.\n"
|
| 98 |
|
|
"For questions about this program please\n"
|
| 99 |
|
|
"please call x1606",
|
| 100 |
|
|
"About MW Summation Extensions", wxOK | wxICON_INFORMATION)
|
| 101 |
|
|
dlg.ShowModal()
|
| 102 |
|
|
dlg.Destroy()
|
| 103 |
|
|
|
| 104 |
|
|
|
| 105 |
|
|
def TimeToQuit(self, event):
|
| 106 |
|
|
self.Close(true)
|
| 107 |
|
|
|
| 108 |
|
|
|
| 109 |
|
|
|
| 110 |
|
|
class MyApp(wxApp):
|
| 111 |
|
|
def OnInit(self):
|
| 112 |
|
|
frame = MyFrame(NULL, -1, "MW Summation Extension")
|
| 113 |
|
|
frame.Show(true)
|
| 114 |
|
|
self.SetTopWindow(frame)
|
| 115 |
|
|
return true
|
| 116 |
|
|
|
| 117 |
|
|
app = MyApp(0)
|
| 118 |
|
|
app.MainLoop() |