]>
Commit | Line | Data |
---|---|---|
53fe40ba RD |
1 | |
2 | from wxPython.wx import * | |
3 | from wxPython.lib.printout import PrintTable | |
4 | ||
5 | import os | |
6 | ||
7 | #--------------------------------------------------------------------------- | |
8 | ||
9 | buttonDefs = { | |
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 | ||
18 | class 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 | ||
1e4a197e | 34 | self.SetAutoLayout(True) |
53fe40ba RD |
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): | |
572c7069 | 43 | test_file = "./data/testtable.txt" |
53fe40ba RD |
44 | file = open(test_file,'r',1) |
45 | i = 0 | |
46 | ||
47 | data = [] | |
48 | while 1: | |
49 | text = file.readline() | |
1e4a197e | 50 | text = text.strip() |
53fe40ba RD |
51 | if not text: |
52 | break | |
53 | ||
1e4a197e | 54 | list_val = text.split('\t') |
53fe40ba RD |
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() | |
572c7069 | 78 | prt.SetFooter("Date: ", type = "Date", align=wxALIGN_RIGHT, indent = -2, colour = wxNamedColour('RED')) |
53fe40ba RD |
79 | prt.Preview() |
80 | ||
81 | def PreviewNarrow(self): | |
82 | self.ReadData() | |
83 | new_data = [] | |
84 | for val in self.data: | |
85 | new_data.append([val[0], val[1], val[2], val[4], val[5]]) | |
86 | ||
87 | val = self.header | |
88 | new_header = [val[0], val[1], val[2], val[4], val[5]] | |
89 | ||
90 | prt = PrintTable(self.frame) | |
91 | prt.data = new_data | |
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')) | |
100 | ||
101 | prt.SetColBackgroundColour(2, wxNamedColour('LIGHT BLUE')) | |
102 | prt.SetCellText(4, 2, wxNamedColour('RED')) | |
103 | ||
104 | prt.SetColTextColour(3, wxNamedColour('RED')) | |
105 | prt.label_font_colour = wxNamedColour('WHITE') | |
106 | prt.SetHeader("wxWindows Applications", colour = wxNamedColour('RED')) | |
107 | ||
572c7069 | 108 | prt.SetHeader("Printed: ", type = "Date & Time", align=wxALIGN_RIGHT, indent = -2, colour = wxNamedColour('BLUE')) |
53fe40ba RD |
109 | prt.SetFooter("Page No", colour = wxNamedColour('RED'), type ="Num") |
110 | prt.Preview() | |
111 | ||
112 | def OnPreviewMatrix(self): | |
113 | total_col = 45 | |
114 | total_row = 10 | |
115 | hsize = 0.2 | |
116 | vsize = 0.2 | |
117 | ||
118 | data = [] | |
119 | startx = 1.0 | |
120 | columns = [] | |
121 | for val in range(total_col): | |
122 | columns.append(hsize) | |
123 | ||
124 | prt = PrintTable(self.frame) | |
125 | ||
126 | for row in range(total_row): | |
127 | value = [] | |
128 | for col in range(total_col): | |
129 | value.append(str(col)) | |
130 | data.append(value) | |
131 | ||
132 | for col in range(total_col): | |
133 | prt.SetColAlignment(col, wxALIGN_CENTRE) | |
134 | ||
135 | prt.SetLandscape() | |
136 | prt.text_font_size = 8 | |
137 | prt.cell_left_margin = 0 | |
138 | ||
139 | prt.data = data | |
140 | prt.set_column = columns | |
141 | prt.SetHeader("Test of Small Grid Size") | |
142 | prt.Preview() | |
143 | ||
144 | def PreviewLine(self): | |
145 | prt = PrintTable(self.frame) | |
146 | prt.label = ["Header 1", "Header 2", "Header 3"] | |
147 | prt.set_column = [] | |
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"]] | |
149 | prt.SetFooter() | |
150 | prt.Preview() | |
151 | ||
152 | def PrintWide(self): | |
153 | self.ReadData() | |
154 | prt = PrintTable(self.frame) | |
155 | prt.data = self.data | |
156 | ||
157 | prt.left_margin = 0.5 | |
158 | prt.set_columns = [ 1, 1, 1, 1, 2, 1, 3 ] | |
159 | prt.label = self.header | |
160 | prt.SetLandscape() | |
161 | prt.Print() | |
162 | ||
163 | ||
164 | #--------------------------------------------------------------------------- | |
165 | ||
166 | def runTest(frame, nb, log): | |
167 | win = TablePanel(nb, log, frame) | |
168 | return win | |
169 | ||
170 | #--------------------------------------------------------------------------- | |
171 | ||
172 | ||
173 | ||
174 | ||
175 | ||
176 | import os | |
177 | import wxPython.lib.printout | |
178 | ||
179 | ||
180 | ||
181 | ||
182 | overview = """\ | |
183 | <html><body> | |
184 | <h2>Table Printing</h2> | |
185 | ||
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. | |
189 | <p> | |
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. | |
193 | <p> | |
194 | There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout. | |
195 | <p> | |
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. | |
198 | <p> | |
199 | The correct "Total Page" does get calculated and used in the print out Footer. | |
200 | <p> | |
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. | |
204 | ||
205 | ||
206 | """ % os.path.join(os.path.dirname(wxPython.lib.printout.__file__), "printout.py") | |
207 | ||
1fded56b RD |
208 | |
209 | ||
210 | ||
211 | ||
212 | if __name__ == '__main__': | |
213 | import sys,os | |
214 | import run | |
215 | run.main(['', os.path.basename(sys.argv[0])]) | |
216 |