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