]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/TablePrint.py
4 import wx
.lib
.printout
as printout
6 #---------------------------------------------------------------------------
9 814 : ('PreviewWide', 'Preview print of a wide table'),
10 815 : ('PreviewNarrow', 'Preview print of a narrow table with color highlights'),
11 816 : ('PreviewText', 'Preview print of a text file'),
12 818 : ('OnPreviewMatrix', 'Preview print of a narrow column grid without a table header'),
13 817 : ('PreviewLine', 'Preview print to demonstrate the use of line breaks'),
14 819 : ('PrintWide', 'Direct print (no preview) of a wide table'),
18 class TablePanel(wx
.Panel
):
19 def __init__(self
, parent
, log
, frame
):
20 wx
.Panel
.__init
__(self
, parent
, -1)
24 box
= wx
.BoxSizer(wx
.VERTICAL
)
26 keys
= buttonDefs
.keys()
30 text
= buttonDefs
[k
][1]
31 btn
= wx
.Button(self
, k
, text
)
32 box
.Add(btn
, 0, wx
.ALIGN_CENTER|wx
.ALL
, 15)
33 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, btn
)
35 self
.SetAutoLayout(True)
38 def OnButton(self
, evt
):
39 funct
= buttonDefs
[evt
.GetId()][0]
40 code
= 'self.' + funct
+ '()'
44 test_file
= "./data/testtable.txt"
45 file = open(test_file
,'r',1)
50 text
= file.readline()
55 list_val
= text
.split('\t')
62 def PreviewWide(self
):
64 prt
= printout
.PrintTable(self
.frame
)
67 prt
.set_column
= [1.0, 1.0, 1.0, 1.5, 1.0, 3.0]
68 prt
.label
= self
.header
71 prt
.SetColumnLineSize(2, 3)
72 prt
.SetColumnLineColour(3, wx
.NamedColour('RED'))
74 prt
.SetRowLineSize(1, 3)
75 prt
.SetRowLineColour(5, wx
.NamedColour('RED'))
77 prt
.SetHeader("wx.Windows Applications")
79 prt
.SetFooter("Date: ", type = "Date", align
=wx
.ALIGN_RIGHT
, indent
= -1, colour
= wx
.NamedColour('RED'))
82 def PreviewNarrow(self
):
86 new_data
.append([val
[0], val
[1], val
[2], val
[4], val
[5]])
89 new_header
= [val
[0], val
[1], val
[2], val
[4], val
[5]]
91 prt
= printout
.PrintTable(self
.frame
)
93 prt
.set_column
= [ 1, 1, 1, 1, 2]
94 prt
.label
= new_header
95 prt
.SetColAlignment(1, wx
.ALIGN_CENTRE
)
96 prt
.SetColBackgroundColour(0, wx
.NamedColour('RED'))
97 prt
.SetColTextColour(0, wx
.NamedColour('WHITE'))
98 prt
.SetCellColour(4, 0, wx
.NamedColour('LIGHT BLUE'))
99 prt
.SetCellColour(4, 1, wx
.NamedColour('LIGHT BLUE'))
100 prt
.SetCellColour(17, 1, wx
.NamedColour('LIGHT BLUE'))
102 prt
.SetColBackgroundColour(2, wx
.NamedColour('LIGHT BLUE'))
103 prt
.SetCellText(4, 2, wx
.NamedColour('RED'))
105 prt
.SetColTextColour(3, wx
.NamedColour('RED'))
106 prt
.label_font_colour
= wx
.NamedColour('WHITE')
107 prt
.SetHeader("wxWindows Applications", colour
= wx
.NamedColour('RED'))
109 prt
.SetHeader("Printed: ", type = "Date & Time", align
=wx
.ALIGN_RIGHT
, indent
= -1, colour
= wx
.NamedColour('BLUE'))
110 prt
.SetFooter("Page No", colour
= wx
.NamedColour('RED'), type ="Num")
113 def OnPreviewMatrix(self
):
122 for val
in range(total_col
):
123 columns
.append(hsize
)
125 prt
= printout
.PrintTable(self
.frame
)
127 for row
in range(total_row
):
129 for col
in range(total_col
):
130 value
.append(str(col
))
133 for col
in range(total_col
):
134 prt
.SetColAlignment(col
, wx
.ALIGN_CENTRE
)
137 prt
.text_font_size
= 8
138 prt
.cell_left_margin
= 0
141 prt
.set_column
= columns
142 prt
.SetHeader("Test of Small Grid Size")
145 def PreviewLine(self
):
146 prt
= printout
.PrintTable(self
.frame
)
147 prt
.label
= ["Header 1", "Header 2", "Header 3"]
149 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"]]
153 def PreviewText(self
):
154 prt
= printout
.PrintTable(self
.frame
)
155 prt
.SetHeader("PROCLAMATION")
156 file = open('data/proclamation.txt')
159 data
.append(txt
.strip())
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])] + sys
.argv
[1:])