]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/TablePrint.py
Applied patch [ 827011 ] Event-based processing of item tooltips in wxTreeCtrl
[wxWidgets.git] / wxPython / demo / TablePrint.py
CommitLineData
8fa876ca
RD
1# 11/13/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4# o Color preview example generates deprecation warnings.
5#
6# 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
7#
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
11#
12
13import os
14
15import wx
16import wx.lib.printout as printout
53fe40ba
RD
17
18#---------------------------------------------------------------------------
19
20buttonDefs = {
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'),
26 }
27
28
8fa876ca 29class TablePanel(wx.Panel):
53fe40ba 30 def __init__(self, parent, log, frame):
8fa876ca 31 wx.Panel.__init__(self, parent, -1)
53fe40ba
RD
32 self.log = log
33 self.frame = frame
34
8fa876ca
RD
35 box = wx.BoxSizer(wx.VERTICAL)
36 box.Add((20, 30))
53fe40ba
RD
37 keys = buttonDefs.keys()
38 keys.sort()
8fa876ca 39
53fe40ba
RD
40 for k in keys:
41 text = buttonDefs[k][1]
8fa876ca
RD
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)
53fe40ba 45
1e4a197e 46 self.SetAutoLayout(True)
53fe40ba
RD
47 self.SetSizer(box)
48
49 def OnButton(self, evt):
50 funct = buttonDefs[evt.GetId()][0]
51 code = 'self.' + funct + '()'
52 eval(code)
53
54 def ReadData(self):
572c7069 55 test_file = "./data/testtable.txt"
53fe40ba
RD
56 file = open(test_file,'r',1)
57 i = 0
58
59 data = []
60 while 1:
61 text = file.readline()
1e4a197e 62 text = text.strip()
53fe40ba
RD
63 if not text:
64 break
65
1e4a197e 66 list_val = text.split('\t')
53fe40ba
RD
67 data.append(list_val)
68 file.close()
69
70 self.header = data[0]
71 self.data = data[1:]
72
73 def PreviewWide(self):
74 self.ReadData()
8fa876ca 75 prt = printout.PrintTable(self.frame)
53fe40ba
RD
76 prt.data = self.data
77 prt.left_margin = 0.5
78 prt.set_column = [1.0, 1.0, 1.0, 1.5, 1.0, 3.0]
79 prt.label = self.header
80 prt.SetLandscape()
81
82 prt.SetColumnLineSize(2, 3)
8fa876ca 83 prt.SetColumnLineColour(3, wx.NamedColour('RED'))
53fe40ba
RD
84
85 prt.SetRowLineSize(1, 3)
8fa876ca 86 prt.SetRowLineColour(5, wx.NamedColour('RED'))
53fe40ba 87
8fa876ca 88 prt.SetHeader("wx.Windows Applications")
53fe40ba 89 prt.SetFooter()
8fa876ca 90 prt.SetFooter("Date: ", type = "Date", align=wx.ALIGN_RIGHT, indent = -2, colour = wx.NamedColour('RED'))
53fe40ba
RD
91 prt.Preview()
92
93 def PreviewNarrow(self):
94 self.ReadData()
95 new_data = []
96 for val in self.data:
97 new_data.append([val[0], val[1], val[2], val[4], val[5]])
98
99 val = self.header
100 new_header = [val[0], val[1], val[2], val[4], val[5]]
101
8fa876ca 102 prt = printout.PrintTable(self.frame)
53fe40ba
RD
103 prt.data = new_data
104 prt.set_column = [ 1, 1, 1, 1, 2]
105 prt.label = new_header
8fa876ca
RD
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'))
112
113 prt.SetColBackgroundColour(2, wx.NamedColour('LIGHT BLUE'))
114 prt.SetCellText(4, 2, wx.NamedColour('RED'))
115
116 prt.SetColTextColour(3, wx.NamedColour('RED'))
117 prt.label_font_colour = wx.NamedColour('WHITE')
118 prt.SetHeader("wxWindows Applications", colour = wx.NamedColour('RED'))
119
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")
53fe40ba
RD
122 prt.Preview()
123
124 def OnPreviewMatrix(self):
125 total_col = 45
126 total_row = 10
127 hsize = 0.2
128 vsize = 0.2
129
130 data = []
131 startx = 1.0
132 columns = []
133 for val in range(total_col):
134 columns.append(hsize)
135
8fa876ca 136 prt = printout.PrintTable(self.frame)
53fe40ba
RD
137
138 for row in range(total_row):
139 value = []
140 for col in range(total_col):
141 value.append(str(col))
142 data.append(value)
143
144 for col in range(total_col):
8fa876ca 145 prt.SetColAlignment(col, wx.ALIGN_CENTRE)
53fe40ba
RD
146
147 prt.SetLandscape()
148 prt.text_font_size = 8
149 prt.cell_left_margin = 0
150
151 prt.data = data
152 prt.set_column = columns
153 prt.SetHeader("Test of Small Grid Size")
154 prt.Preview()
155
156 def PreviewLine(self):
8fa876ca 157 prt = printout.PrintTable(self.frame)
53fe40ba
RD
158 prt.label = ["Header 1", "Header 2", "Header 3"]
159 prt.set_column = []
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"]]
161 prt.SetFooter()
162 prt.Preview()
163
164 def PrintWide(self):
165 self.ReadData()
8fa876ca 166 prt = printout.PrintTable(self.frame)
53fe40ba
RD
167 prt.data = self.data
168
169 prt.left_margin = 0.5
170 prt.set_columns = [ 1, 1, 1, 1, 2, 1, 3 ]
171 prt.label = self.header
172 prt.SetLandscape()
173 prt.Print()
174
175
176#---------------------------------------------------------------------------
177
178def runTest(frame, nb, log):
179 win = TablePanel(nb, log, frame)
180 return win
181
182#---------------------------------------------------------------------------
183
184
185
186
187
53fe40ba
RD
188overview = """\
189<html><body>
190<h2>Table Printing</h2>
191
192This 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
194and the library <a href="%s">printout.py</a> module classes.
195<p>
8b9a4190 196The initial class primarily contains a Table preview/printing class. There is a lot of flexibility
53fe40ba
RD
197in manipulating the placement, sizing, colours, alignment of the table text and cell background colors.
198There are also a number of options for printing Header and Footer information on the page.
199<p>
200There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout.
201<p>
202The data is printed from a list object containing the column and row values. The label or table header
203can be defined and will be repeated for all pages.
204<p>
205The correct "Total Page" does get calculated and used in the print out Footer.
206<p>
207There is still problems with the print framework to properly get the total pages in the preview unless
208the program knows it before trying to parse through the available pages. This will be fixed
209when the framework allows for it.
210
211
8fa876ca 212""" % os.path.join(os.path.dirname(printout.__file__), "printout.py")
53fe40ba 213
1fded56b
RD
214
215
216
217
218if __name__ == '__main__':
219 import sys,os
220 import run
221 run.main(['', os.path.basename(sys.argv[0])])
222