]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/TablePrint.py
2 from wxPython
.wx
import *
3 from wxPython
.lib
.printout
import PrintTable
7 #---------------------------------------------------------------------------
10 814 : ('PreviewWide', 'Preview print of a wide table'),
11 815 : ('PreviewNarrow', 'Preview print of a narrow table with color highlights'),
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(wxPanel
):
19 def __init__(self
, parent
, log
, frame
):
20 wxPanel
.__init
__(self
, parent
, -1)
24 box
= wxBoxSizer(wxVERTICAL
)
26 keys
= buttonDefs
.keys()
29 text
= buttonDefs
[k
][1]
30 btn
= wxButton(self
, k
, text
)
31 box
.Add(btn
, 0, wxALIGN_CENTER|wxALL
, 15)
32 EVT_BUTTON(self
, k
, self
.OnButton
)
34 self
.SetAutoLayout(true
)
37 def OnButton(self
, evt
):
38 funct
= buttonDefs
[evt
.GetId()][0]
39 code
= 'self.' + funct
+ '()'
43 test_file
= "TestTable.txt"
44 file = open(test_file
,'r',1)
49 text
= file.readline()
50 text
= string
.strip(text
)
54 list_val
= string
.splitfields(text
,'\t')
61 def PreviewWide(self
):
63 prt
= PrintTable(self
.frame
)
66 prt
.set_column
= [1.0, 1.0, 1.0, 1.5, 1.0, 3.0]
67 prt
.label
= self
.header
70 prt
.SetColumnLineSize(2, 3)
71 prt
.SetColumnLineColour(3, wxNamedColour('RED'))
73 prt
.SetRowLineSize(1, 3)
74 prt
.SetRowLineColour(5, wxNamedColour('RED'))
76 prt
.SetHeader("wxWindows Applications")
80 def PreviewNarrow(self
):
84 new_data
.append([val
[0], val
[1], val
[2], val
[4], val
[5]])
87 new_header
= [val
[0], val
[1], val
[2], val
[4], val
[5]]
89 prt
= PrintTable(self
.frame
)
91 prt
.set_column
= [ 1, 1, 1, 1, 2]
92 prt
.label
= new_header
93 prt
.SetColAlignment(1, wxALIGN_CENTRE
)
94 prt
.SetColBackgroundColour(0, wxNamedColour('RED'))
95 prt
.SetColTextColour(0, wxNamedColour('WHITE'))
96 prt
.SetCellColour(4, 0, wxNamedColour('LIGHT BLUE'))
97 prt
.SetCellColour(4, 1, wxNamedColour('LIGHT BLUE'))
98 prt
.SetCellColour(17, 1, wxNamedColour('LIGHT BLUE'))
100 prt
.SetColBackgroundColour(2, wxNamedColour('LIGHT BLUE'))
101 prt
.SetCellText(4, 2, wxNamedColour('RED'))
103 prt
.SetColTextColour(3, wxNamedColour('RED'))
104 prt
.label_font_colour
= wxNamedColour('WHITE')
105 prt
.SetHeader("wxWindows Applications", colour
= wxNamedColour('RED'))
107 prt
.SetHeader("Date", align
=wxALIGN_RIGHT
, indent
= -2, colour
= wxNamedColour('BLUE'))
108 prt
.SetFooter("Page No", colour
= wxNamedColour('RED'), type ="Num")
111 def OnPreviewMatrix(self
):
120 for val
in range(total_col
):
121 columns
.append(hsize
)
123 prt
= PrintTable(self
.frame
)
125 for row
in range(total_row
):
127 for col
in range(total_col
):
128 value
.append(str(col
))
131 for col
in range(total_col
):
132 prt
.SetColAlignment(col
, wxALIGN_CENTRE
)
135 prt
.text_font_size
= 8
136 prt
.cell_left_margin
= 0
139 prt
.set_column
= columns
140 prt
.SetHeader("Test of Small Grid Size")
143 def PreviewLine(self
):
144 prt
= PrintTable(self
.frame
)
145 prt
.label
= ["Header 1", "Header 2", "Header 3"]
147 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 prt
= PrintTable(self
.frame
)
156 prt
.left_margin
= 0.5
157 prt
.set_columns
= [ 1, 1, 1, 1, 2, 1, 3 ]
158 prt
.label
= self
.header
163 #---------------------------------------------------------------------------
165 def runTest(frame
, nb
, log
):
166 win
= TablePanel(nb
, log
, frame
)
169 #---------------------------------------------------------------------------
176 import wxPython
.lib
.printout
183 <h2>Table Printing</h2>
185 This demo shows various ways of using the <b><i>new
186 </i></b> PrintOut class. To understand the class you need to examine the demo examples
187 and the library <a href="%s">printout.py</a> module classes.
189 The initial class primarily contains a Table preview/printing class. There is alot of flexibility
190 in manipulating the placement, sizing, colours, alignment of the table text and cell background colors.
191 There are also a number of options for printing Header and Footer information on the page.
193 There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout.
195 The data is printed from a list object containing the column and row values. The label or table header
196 can be defined and will be repeated for all pages.
198 The correct "Total Page" does get calculated and used in the print out Footer.
200 There is still problems with the print framework to properly get the total pages in the preview unless
201 the program knows it before trying to parse through the available pages. This will be fixed
202 when the framework allows for it.
205 """ % os
.path
.join(os
.path
.dirname(wxPython
.lib
.printout
.__file
__), "printout.py")