]>
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
= "./data/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")
78 prt
.SetFooter("Date: ", type = "Date", align
=wxALIGN_RIGHT
, indent
= -2, colour
= wxNamedColour('RED'))
81 def PreviewNarrow(self
):
85 new_data
.append([val
[0], val
[1], val
[2], val
[4], val
[5]])
88 new_header
= [val
[0], val
[1], val
[2], val
[4], val
[5]]
90 prt
= PrintTable(self
.frame
)
92 prt
.set_column
= [ 1, 1, 1, 1, 2]
93 prt
.label
= new_header
94 prt
.SetColAlignment(1, wxALIGN_CENTRE
)
95 prt
.SetColBackgroundColour(0, wxNamedColour('RED'))
96 prt
.SetColTextColour(0, wxNamedColour('WHITE'))
97 prt
.SetCellColour(4, 0, wxNamedColour('LIGHT BLUE'))
98 prt
.SetCellColour(4, 1, wxNamedColour('LIGHT BLUE'))
99 prt
.SetCellColour(17, 1, wxNamedColour('LIGHT BLUE'))
101 prt
.SetColBackgroundColour(2, wxNamedColour('LIGHT BLUE'))
102 prt
.SetCellText(4, 2, wxNamedColour('RED'))
104 prt
.SetColTextColour(3, wxNamedColour('RED'))
105 prt
.label_font_colour
= wxNamedColour('WHITE')
106 prt
.SetHeader("wxWindows Applications", colour
= wxNamedColour('RED'))
108 prt
.SetHeader("Printed: ", type = "Date & Time", align
=wxALIGN_RIGHT
, indent
= -2, colour
= wxNamedColour('BLUE'))
109 prt
.SetFooter("Page No", colour
= wxNamedColour('RED'), type ="Num")
112 def OnPreviewMatrix(self
):
121 for val
in range(total_col
):
122 columns
.append(hsize
)
124 prt
= PrintTable(self
.frame
)
126 for row
in range(total_row
):
128 for col
in range(total_col
):
129 value
.append(str(col
))
132 for col
in range(total_col
):
133 prt
.SetColAlignment(col
, wxALIGN_CENTRE
)
136 prt
.text_font_size
= 8
137 prt
.cell_left_margin
= 0
140 prt
.set_column
= columns
141 prt
.SetHeader("Test of Small Grid Size")
144 def PreviewLine(self
):
145 prt
= PrintTable(self
.frame
)
146 prt
.label
= ["Header 1", "Header 2", "Header 3"]
148 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"]]
154 prt
= PrintTable(self
.frame
)
157 prt
.left_margin
= 0.5
158 prt
.set_columns
= [ 1, 1, 1, 1, 2, 1, 3 ]
159 prt
.label
= self
.header
164 #---------------------------------------------------------------------------
166 def runTest(frame
, nb
, log
):
167 win
= TablePanel(nb
, log
, frame
)
170 #---------------------------------------------------------------------------
177 import wxPython
.lib
.printout
184 <h2>Table Printing</h2>
186 This demo shows various ways of using the <b><i>new
187 </i></b> PrintOut class. To understand the class you need to examine the demo examples
188 and the library <a href="%s">printout.py</a> module classes.
190 The initial class primarily contains a Table preview/printing class. There is alot of flexibility
191 in manipulating the placement, sizing, colours, alignment of the table text and cell background colors.
192 There are also a number of options for printing Header and Footer information on the page.
194 There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout.
196 The data is printed from a list object containing the column and row values. The label or table header
197 can be defined and will be repeated for all pages.
199 The correct "Total Page" does get calculated and used in the print out Footer.
201 There is still problems with the print framework to properly get the total pages in the preview unless
202 the program knows it before trying to parse through the available pages. This will be fixed
203 when the framework allows for it.
206 """ % os
.path
.join(os
.path
.dirname(wxPython
.lib
.printout
.__file
__), "printout.py")