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