]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/TablePrint.py
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
16 import wx
.lib
.printout
as printout
18 #---------------------------------------------------------------------------
21 814 : ('PreviewWide', 'Preview print of a wide table'),
22 815 : ('PreviewNarrow', 'Preview print of a narrow table with color highlights'),
23 818 : ('OnPreviewMatrix', 'Preview print of a narrow column grid without a table header'),
24 817 : ('PreviewLine', 'Preview print to demonstrate the use of line breaks'),
25 819 : ('PrintWide', 'Direct print (no preview) of a wide table'),
29 class TablePanel(wx
.Panel
):
30 def __init__(self
, parent
, log
, frame
):
31 wx
.Panel
.__init
__(self
, parent
, -1)
35 box
= wx
.BoxSizer(wx
.VERTICAL
)
37 keys
= buttonDefs
.keys()
41 text
= buttonDefs
[k
][1]
42 btn
= wx
.Button(self
, k
, text
)
43 box
.Add(btn
, 0, wx
.ALIGN_CENTER|wx
.ALL
, 15)
44 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, btn
)
46 self
.SetAutoLayout(True)
49 def OnButton(self
, evt
):
50 funct
= buttonDefs
[evt
.GetId()][0]
51 code
= 'self.' + funct
+ '()'
55 test_file
= "./data/testtable.txt"
56 file = open(test_file
,'r',1)
61 text
= file.readline()
66 list_val
= text
.split('\t')
73 def PreviewWide(self
):
75 prt
= printout
.PrintTable(self
.frame
)
78 prt
.set_column
= [1.0, 1.0, 1.0, 1.5, 1.0, 3.0]
79 prt
.label
= self
.header
82 prt
.SetColumnLineSize(2, 3)
83 prt
.SetColumnLineColour(3, wx
.NamedColour('RED'))
85 prt
.SetRowLineSize(1, 3)
86 prt
.SetRowLineColour(5, wx
.NamedColour('RED'))
88 prt
.SetHeader("wx.Windows Applications")
90 prt
.SetFooter("Date: ", type = "Date", align
=wx
.ALIGN_RIGHT
, indent
= -2, colour
= wx
.NamedColour('RED'))
93 def PreviewNarrow(self
):
97 new_data
.append([val
[0], val
[1], val
[2], val
[4], val
[5]])
100 new_header
= [val
[0], val
[1], val
[2], val
[4], val
[5]]
102 prt
= printout
.PrintTable(self
.frame
)
104 prt
.set_column
= [ 1, 1, 1, 1, 2]
105 prt
.label
= new_header
106 prt
.SetColAlignment(1, wx
.ALIGN_CENTRE
)
107 prt
.SetColBackgroundColour(0, wx
.NamedColour('RED'))
108 prt
.SetColTextColour(0, wx
.NamedColour('WHITE'))
109 prt
.SetCellColour(4, 0, wx
.NamedColour('LIGHT BLUE'))
110 prt
.SetCellColour(4, 1, wx
.NamedColour('LIGHT BLUE'))
111 prt
.SetCellColour(17, 1, wx
.NamedColour('LIGHT BLUE'))
113 prt
.SetColBackgroundColour(2, wx
.NamedColour('LIGHT BLUE'))
114 prt
.SetCellText(4, 2, wx
.NamedColour('RED'))
116 prt
.SetColTextColour(3, wx
.NamedColour('RED'))
117 prt
.label_font_colour
= wx
.NamedColour('WHITE')
118 prt
.SetHeader("wxWindows Applications", colour
= wx
.NamedColour('RED'))
120 prt
.SetHeader("Printed: ", type = "Date & Time", align
=wx
.ALIGN_RIGHT
, indent
= -2, colour
= wx
.NamedColour('BLUE'))
121 prt
.SetFooter("Page No", colour
= wx
.NamedColour('RED'), type ="Num")
124 def OnPreviewMatrix(self
):
133 for val
in range(total_col
):
134 columns
.append(hsize
)
136 prt
= printout
.PrintTable(self
.frame
)
138 for row
in range(total_row
):
140 for col
in range(total_col
):
141 value
.append(str(col
))
144 for col
in range(total_col
):
145 prt
.SetColAlignment(col
, wx
.ALIGN_CENTRE
)
148 prt
.text_font_size
= 8
149 prt
.cell_left_margin
= 0
152 prt
.set_column
= columns
153 prt
.SetHeader("Test of Small Grid Size")
156 def PreviewLine(self
):
157 prt
= printout
.PrintTable(self
.frame
)
158 prt
.label
= ["Header 1", "Header 2", "Header 3"]
160 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"]]
166 prt
= printout
.PrintTable(self
.frame
)
169 prt
.left_margin
= 0.5
170 prt
.set_columns
= [ 1, 1, 1, 1, 2, 1, 3 ]
171 prt
.label
= self
.header
176 #---------------------------------------------------------------------------
178 def runTest(frame
, nb
, log
):
179 win
= TablePanel(nb
, log
, frame
)
182 #---------------------------------------------------------------------------
190 <h2>Table Printing</h2>
192 This demo shows various ways of using the <b><i>new
193 </i></b> PrintOut class. To understand the class you need to examine the demo examples
194 and the library <a href="%s">printout.py</a> module classes.
196 The initial class primarily contains a Table preview/printing class. There is a lot of flexibility
197 in manipulating the placement, sizing, colours, alignment of the table text and cell background colors.
198 There are also a number of options for printing Header and Footer information on the page.
200 There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout.
202 The data is printed from a list object containing the column and row values. The label or table header
203 can be defined and will be repeated for all pages.
205 The correct "Total Page" does get calculated and used in the print out Footer.
207 There is still problems with the print framework to properly get the total pages in the preview unless
208 the program knows it before trying to parse through the available pages. This will be fixed
209 when the framework allows for it.
212 """ % os
.path
.join(os
.path
.dirname(printout
.__file
__), "printout.py")
218 if __name__
== '__main__':
221 run
.main(['', os
.path
.basename(sys
.argv
[0])])