]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/TablePrint.py
Refactored Python shadows to use wxControlWithItems where appropriate.
[wxWidgets.git] / wxPython / demo / TablePrint.py
... / ...
CommitLineData
1
2from wxPython.wx import *
3from wxPython.lib.printout import PrintTable
4
5import os
6
7#---------------------------------------------------------------------------
8
9buttonDefs = {
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'),
15 }
16
17
18class TablePanel(wxPanel):
19 def __init__(self, parent, log, frame):
20 wxPanel.__init__(self, parent, -1)
21 self.log = log
22 self.frame = frame
23
24 box = wxBoxSizer(wxVERTICAL)
25 box.Add(20, 30)
26 keys = buttonDefs.keys()
27 keys.sort()
28 for k in 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)
33
34 self.SetAutoLayout(true)
35 self.SetSizer(box)
36
37 def OnButton(self, evt):
38 funct = buttonDefs[evt.GetId()][0]
39 code = 'self.' + funct + '()'
40 eval(code)
41
42 def ReadData(self):
43 test_file = "TestTable.txt"
44 file = open(test_file,'r',1)
45 i = 0
46
47 data = []
48 while 1:
49 text = file.readline()
50 text = string.strip(text)
51 if not text:
52 break
53
54 list_val = string.splitfields(text,'\t')
55 data.append(list_val)
56 file.close()
57
58 self.header = data[0]
59 self.data = data[1:]
60
61 def PreviewWide(self):
62 self.ReadData()
63 prt = PrintTable(self.frame)
64 prt.data = self.data
65 prt.left_margin = 0.5
66 prt.set_column = [1.0, 1.0, 1.0, 1.5, 1.0, 3.0]
67 prt.label = self.header
68 prt.SetLandscape()
69
70 prt.SetColumnLineSize(2, 3)
71 prt.SetColumnLineColour(3, wxNamedColour('RED'))
72
73 prt.SetRowLineSize(1, 3)
74 prt.SetRowLineColour(5, wxNamedColour('RED'))
75
76 prt.SetHeader("wxWindows Applications")
77 prt.SetFooter()
78 prt.Preview()
79
80 def PreviewNarrow(self):
81 self.ReadData()
82 new_data = []
83 for val in self.data:
84 new_data.append([val[0], val[1], val[2], val[4], val[5]])
85
86 val = self.header
87 new_header = [val[0], val[1], val[2], val[4], val[5]]
88
89 prt = PrintTable(self.frame)
90 prt.data = new_data
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'))
99
100 prt.SetColBackgroundColour(2, wxNamedColour('LIGHT BLUE'))
101 prt.SetCellText(4, 2, wxNamedColour('RED'))
102
103 prt.SetColTextColour(3, wxNamedColour('RED'))
104 prt.label_font_colour = wxNamedColour('WHITE')
105 prt.SetHeader("wxWindows Applications", colour = wxNamedColour('RED'))
106
107 prt.SetHeader("Date", align=wxALIGN_RIGHT, indent = -2, colour = wxNamedColour('BLUE'))
108 prt.SetFooter("Page No", colour = wxNamedColour('RED'), type ="Num")
109 prt.Preview()
110
111 def OnPreviewMatrix(self):
112 total_col = 45
113 total_row = 10
114 hsize = 0.2
115 vsize = 0.2
116
117 data = []
118 startx = 1.0
119 columns = []
120 for val in range(total_col):
121 columns.append(hsize)
122
123 prt = PrintTable(self.frame)
124
125 for row in range(total_row):
126 value = []
127 for col in range(total_col):
128 value.append(str(col))
129 data.append(value)
130
131 for col in range(total_col):
132 prt.SetColAlignment(col, wxALIGN_CENTRE)
133
134 prt.SetLandscape()
135 prt.text_font_size = 8
136 prt.cell_left_margin = 0
137
138 prt.data = data
139 prt.set_column = columns
140 prt.SetHeader("Test of Small Grid Size")
141 prt.Preview()
142
143 def PreviewLine(self):
144 prt = PrintTable(self.frame)
145 prt.label = ["Header 1", "Header 2", "Header 3"]
146 prt.set_column = []
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"]]
148 prt.SetFooter()
149 prt.Preview()
150
151 def PrintWide(self):
152 self.ReadData()
153 prt = PrintTable(self.frame)
154 prt.data = self.data
155
156 prt.left_margin = 0.5
157 prt.set_columns = [ 1, 1, 1, 1, 2, 1, 3 ]
158 prt.label = self.header
159 prt.SetLandscape()
160 prt.Print()
161
162
163#---------------------------------------------------------------------------
164
165def runTest(frame, nb, log):
166 win = TablePanel(nb, log, frame)
167 return win
168
169#---------------------------------------------------------------------------
170
171
172
173
174
175import os
176import wxPython.lib.printout
177
178
179
180
181overview = """\
182<html><body>
183<h2>Table Printing</h2>
184
185This 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
187and the library <a href="%s">printout.py</a> module classes.
188<p>
189The initial class primarily contains a Table preview/printing class. There is alot of flexibility
190in manipulating the placement, sizing, colours, alignment of the table text and cell background colors.
191There are also a number of options for printing Header and Footer information on the page.
192<p>
193There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout.
194<p>
195The data is printed from a list object containing the column and row values. The label or table header
196can be defined and will be repeated for all pages.
197<p>
198The correct "Total Page" does get calculated and used in the print out Footer.
199<p>
200There is still problems with the print framework to properly get the total pages in the preview unless
201the program knows it before trying to parse through the available pages. This will be fixed
202when the framework allows for it.
203
204
205""" % os.path.join(os.path.dirname(wxPython.lib.printout.__file__), "printout.py")
206