]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/TablePrint.py
8d4de77e891114444316c21638895d4d6f9a0944
1 # 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
4 # o Color preview example generates deprecation warnings.
6 # 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
8 # o Note: wx.NamedColour must remain because printout.py requiress it.
9 # o printout.py is generating a snootful of errors all related to the
10 # requirement for tuples on the base DC calls now
12 # 12/10/2003 - Jeff Grimmett (grimmtooth@softhome.net)
20 import wx
.lib
.printout
as printout
22 #---------------------------------------------------------------------------
25 814 : ('PreviewWide', 'Preview print of a wide table'),
26 815 : ('PreviewNarrow', 'Preview print of a narrow table with color highlights'),
27 818 : ('OnPreviewMatrix', 'Preview print of a narrow column grid without a table header'),
28 817 : ('PreviewLine', 'Preview print to demonstrate the use of line breaks'),
29 819 : ('PrintWide', 'Direct print (no preview) of a wide table'),
33 class TablePanel(wx
.Panel
):
34 def __init__(self
, parent
, log
, frame
):
35 wx
.Panel
.__init
__(self
, parent
, -1)
39 box
= wx
.BoxSizer(wx
.VERTICAL
)
41 keys
= buttonDefs
.keys()
45 text
= buttonDefs
[k
][1]
46 btn
= wx
.Button(self
, k
, text
)
47 box
.Add(btn
, 0, wx
.ALIGN_CENTER|wx
.ALL
, 15)
48 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, btn
)
50 self
.SetAutoLayout(True)
53 def OnButton(self
, evt
):
54 funct
= buttonDefs
[evt
.GetId()][0]
55 code
= 'self.' + funct
+ '()'
59 test_file
= "./data/testtable.txt"
60 file = open(test_file
,'r',1)
65 text
= file.readline()
70 list_val
= text
.split('\t')
77 def PreviewWide(self
):
79 prt
= printout
.PrintTable(self
.frame
)
82 prt
.set_column
= [1.0, 1.0, 1.0, 1.5, 1.0, 3.0]
83 prt
.label
= self
.header
86 prt
.SetColumnLineSize(2, 3)
87 prt
.SetColumnLineColour(3, wx
.NamedColour('RED'))
89 prt
.SetRowLineSize(1, 3)
90 prt
.SetRowLineColour(5, wx
.NamedColour('RED'))
92 prt
.SetHeader("wx.Windows Applications")
94 prt
.SetFooter("Date: ", type = "Date", align
=wx
.ALIGN_RIGHT
, indent
= -2, colour
= wx
.NamedColour('RED'))
97 def PreviewNarrow(self
):
100 for val
in self
.data
:
101 new_data
.append([val
[0], val
[1], val
[2], val
[4], val
[5]])
104 new_header
= [val
[0], val
[1], val
[2], val
[4], val
[5]]
106 prt
= printout
.PrintTable(self
.frame
)
108 prt
.set_column
= [ 1, 1, 1, 1, 2]
109 prt
.label
= new_header
110 prt
.SetColAlignment(1, wx
.ALIGN_CENTRE
)
111 prt
.SetColBackgroundColour(0, wx
.NamedColour('RED'))
112 prt
.SetColTextColour(0, wx
.NamedColour('WHITE'))
113 prt
.SetCellColour(4, 0, wx
.NamedColour('LIGHT BLUE'))
114 prt
.SetCellColour(4, 1, wx
.NamedColour('LIGHT BLUE'))
115 prt
.SetCellColour(17, 1, wx
.NamedColour('LIGHT BLUE'))
117 prt
.SetColBackgroundColour(2, wx
.NamedColour('LIGHT BLUE'))
118 prt
.SetCellText(4, 2, wx
.NamedColour('RED'))
120 prt
.SetColTextColour(3, wx
.NamedColour('RED'))
121 prt
.label_font_colour
= wx
.NamedColour('WHITE')
122 prt
.SetHeader("wxWindows Applications", colour
= wx
.NamedColour('RED'))
124 prt
.SetHeader("Printed: ", type = "Date & Time", align
=wx
.ALIGN_RIGHT
, indent
= -2, colour
= wx
.NamedColour('BLUE'))
125 prt
.SetFooter("Page No", colour
= wx
.NamedColour('RED'), type ="Num")
128 def OnPreviewMatrix(self
):
137 for val
in range(total_col
):
138 columns
.append(hsize
)
140 prt
= printout
.PrintTable(self
.frame
)
142 for row
in range(total_row
):
144 for col
in range(total_col
):
145 value
.append(str(col
))
148 for col
in range(total_col
):
149 prt
.SetColAlignment(col
, wx
.ALIGN_CENTRE
)
152 prt
.text_font_size
= 8
153 prt
.cell_left_margin
= 0
156 prt
.set_column
= columns
157 prt
.SetHeader("Test of Small Grid Size")
160 def PreviewLine(self
):
161 prt
= printout
.PrintTable(self
.frame
)
162 prt
.label
= ["Header 1", "Header 2", "Header 3"]
164 prt
.data
= [["Row 1", "1", "2"], ["Row 2", "3", "4\nNew Line to see if it also can wrap around the cell region properly\nAnother new line"]]
170 prt
= printout
.PrintTable(self
.frame
)
173 prt
.left_margin
= 0.5
174 prt
.set_columns
= [ 1, 1, 1, 1, 2, 1, 3 ]
175 prt
.label
= self
.header
180 #---------------------------------------------------------------------------
182 def runTest(frame
, nb
, log
):
183 win
= TablePanel(nb
, log
, frame
)
186 #---------------------------------------------------------------------------
194 <h2>Table Printing</h2>
196 This demo shows various ways of using the <b><i>new
197 </i></b> PrintOut class. To understand the class you need to examine the demo examples
198 and the library <a href="%s">printout.py</a> module classes.
200 The initial class primarily contains a Table preview/printing class. There is a lot of flexibility
201 in manipulating the placement, sizing, colours, alignment of the table text and cell background colors.
202 There are also a number of options for printing Header and Footer information on the page.
204 There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout.
206 The data is printed from a list object containing the column and row values. The label or table header
207 can be defined and will be repeated for all pages.
209 The correct "Total Page" does get calculated and used in the print out Footer.
211 There is still problems with the print framework to properly get the total pages in the preview unless
212 the program knows it before trying to parse through the available pages. This will be fixed
213 when the framework allows for it.
216 """ % os
.path
.join(os
.path
.dirname(printout
.__file
__), "printout.py")
222 if __name__
== '__main__':
225 run
.main(['', os
.path
.basename(sys
.argv
[0])])