]>
Commit | Line | Data |
---|---|---|
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 | ||
13 | import os | |
14 | ||
15 | import wx | |
16 | import wx.lib.printout as printout | |
17 | ||
18 | #--------------------------------------------------------------------------- | |
19 | ||
20 | buttonDefs = { | |
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 | ||
29 | class TablePanel(wx.Panel): | |
30 | def __init__(self, parent, log, frame): | |
31 | wx.Panel.__init__(self, parent, -1) | |
32 | self.log = log | |
33 | self.frame = frame | |
34 | ||
35 | box = wx.BoxSizer(wx.VERTICAL) | |
36 | box.Add((20, 30)) | |
37 | keys = buttonDefs.keys() | |
38 | keys.sort() | |
39 | ||
40 | for k in keys: | |
41 | text = buttonDefs[k][1] | |
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) | |
45 | ||
46 | self.SetAutoLayout(True) | |
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): | |
55 | test_file = "./data/testtable.txt" | |
56 | file = open(test_file,'r',1) | |
57 | i = 0 | |
58 | ||
59 | data = [] | |
60 | while 1: | |
61 | text = file.readline() | |
62 | text = text.strip() | |
63 | if not text: | |
64 | break | |
65 | ||
66 | list_val = text.split('\t') | |
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() | |
75 | prt = printout.PrintTable(self.frame) | |
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) | |
83 | prt.SetColumnLineColour(3, wx.NamedColour('RED')) | |
84 | ||
85 | prt.SetRowLineSize(1, 3) | |
86 | prt.SetRowLineColour(5, wx.NamedColour('RED')) | |
87 | ||
88 | prt.SetHeader("wx.Windows Applications") | |
89 | prt.SetFooter() | |
90 | prt.SetFooter("Date: ", type = "Date", align=wx.ALIGN_RIGHT, indent = -2, colour = wx.NamedColour('RED')) | |
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 | ||
102 | prt = printout.PrintTable(self.frame) | |
103 | prt.data = new_data | |
104 | prt.set_column = [ 1, 1, 1, 1, 2] | |
105 | prt.label = new_header | |
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") | |
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 | ||
136 | prt = printout.PrintTable(self.frame) | |
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): | |
145 | prt.SetColAlignment(col, wx.ALIGN_CENTRE) | |
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): | |
157 | prt = printout.PrintTable(self.frame) | |
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() | |
166 | prt = printout.PrintTable(self.frame) | |
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 | ||
178 | def runTest(frame, nb, log): | |
179 | win = TablePanel(nb, log, frame) | |
180 | return win | |
181 | ||
182 | #--------------------------------------------------------------------------- | |
183 | ||
184 | ||
185 | ||
186 | ||
187 | ||
188 | overview = """\ | |
189 | <html><body> | |
190 | <h2>Table Printing</h2> | |
191 | ||
192 | This 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 | |
194 | and the library <a href="%s">printout.py</a> module classes. | |
195 | <p> | |
196 | The initial class primarily contains a Table preview/printing class. There is a lot of flexibility | |
197 | in manipulating the placement, sizing, colours, alignment of the table text and cell background colors. | |
198 | There are also a number of options for printing Header and Footer information on the page. | |
199 | <p> | |
200 | There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout. | |
201 | <p> | |
202 | The data is printed from a list object containing the column and row values. The label or table header | |
203 | can be defined and will be repeated for all pages. | |
204 | <p> | |
205 | The correct "Total Page" does get calculated and used in the print out Footer. | |
206 | <p> | |
207 | There is still problems with the print framework to properly get the total pages in the preview unless | |
208 | the program knows it before trying to parse through the available pages. This will be fixed | |
209 | when the framework allows for it. | |
210 | ||
211 | ||
212 | """ % os.path.join(os.path.dirname(printout.__file__), "printout.py") | |
213 | ||
214 | ||
215 | ||
216 | ||
217 | ||
218 | if __name__ == '__main__': | |
219 | import sys,os | |
220 | import run | |
221 | run.main(['', os.path.basename(sys.argv[0])]) | |
222 |