]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/TablePrint.py
fix building/running of tex2rtf
[wxWidgets.git] / wxPython / demo / TablePrint.py
1
2 import os
3 import wx
4 import wx.lib.printout as printout
5
6 #---------------------------------------------------------------------------
7
8 buttonDefs = {
9 814 : ('PreviewWide', 'Preview print of a wide table'),
10 815 : ('PreviewNarrow', 'Preview print of a narrow table with color highlights'),
11 816 : ('PreviewText', 'Preview print of a text file'),
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 = -1, 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 = -1, 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 PreviewText(self):
154 prt = printout.PrintTable(self.frame)
155 prt.SetHeader("PROCLAMATION")
156 file = open('data/proclamation.txt')
157 data = []
158 for txt in file:
159 data.append(txt.strip())
160 file.close()
161 prt.data = data
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])] + sys.argv[1:])
222