]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/TablePrint.py
I think I found out how GTK+ want popup windows
[wxWidgets.git] / wxPython / demo / TablePrint.py
CommitLineData
8fa876ca
RD
1
2import os
3
4import wx
5import wx.lib.printout as printout
53fe40ba
RD
6
7#---------------------------------------------------------------------------
8
9buttonDefs = {
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
8fa876ca 18class TablePanel(wx.Panel):
53fe40ba 19 def __init__(self, parent, log, frame):
8fa876ca 20 wx.Panel.__init__(self, parent, -1)
53fe40ba
RD
21 self.log = log
22 self.frame = frame
23
8fa876ca
RD
24 box = wx.BoxSizer(wx.VERTICAL)
25 box.Add((20, 30))
53fe40ba
RD
26 keys = buttonDefs.keys()
27 keys.sort()
8fa876ca 28
53fe40ba
RD
29 for k in keys:
30 text = buttonDefs[k][1]
8fa876ca
RD
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)
53fe40ba 34
1e4a197e 35 self.SetAutoLayout(True)
53fe40ba
RD
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):
572c7069 44 test_file = "./data/testtable.txt"
53fe40ba
RD
45 file = open(test_file,'r',1)
46 i = 0
47
48 data = []
49 while 1:
50 text = file.readline()
1e4a197e 51 text = text.strip()
53fe40ba
RD
52 if not text:
53 break
54
1e4a197e 55 list_val = text.split('\t')
53fe40ba
RD
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()
8fa876ca 64 prt = printout.PrintTable(self.frame)
53fe40ba
RD
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)
8fa876ca 72 prt.SetColumnLineColour(3, wx.NamedColour('RED'))
53fe40ba
RD
73
74 prt.SetRowLineSize(1, 3)
8fa876ca 75 prt.SetRowLineColour(5, wx.NamedColour('RED'))
53fe40ba 76
8fa876ca 77 prt.SetHeader("wx.Windows Applications")
53fe40ba 78 prt.SetFooter()
8fa876ca 79 prt.SetFooter("Date: ", type = "Date", align=wx.ALIGN_RIGHT, indent = -2, colour = wx.NamedColour('RED'))
53fe40ba
RD
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
8fa876ca 91 prt = printout.PrintTable(self.frame)
53fe40ba
RD
92 prt.data = new_data
93 prt.set_column = [ 1, 1, 1, 1, 2]
94 prt.label = new_header
8fa876ca
RD
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")
53fe40ba
RD
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
8fa876ca 125 prt = printout.PrintTable(self.frame)
53fe40ba
RD
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):
8fa876ca 134 prt.SetColAlignment(col, wx.ALIGN_CENTRE)
53fe40ba
RD
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):
8fa876ca 146 prt = printout.PrintTable(self.frame)
53fe40ba
RD
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()
8fa876ca 155 prt = printout.PrintTable(self.frame)
53fe40ba
RD
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
167def runTest(frame, nb, log):
168 win = TablePanel(nb, log, frame)
169 return win
170
171#---------------------------------------------------------------------------
172
173
174
175
176
53fe40ba
RD
177overview = """\
178<html><body>
179<h2>Table Printing</h2>
180
181This 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
183and the library <a href="%s">printout.py</a> module classes.
184<p>
8b9a4190 185The initial class primarily contains a Table preview/printing class. There is a lot of flexibility
53fe40ba
RD
186in manipulating the placement, sizing, colours, alignment of the table text and cell background colors.
187There are also a number of options for printing Header and Footer information on the page.
188<p>
189There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout.
190<p>
191The data is printed from a list object containing the column and row values. The label or table header
192can be defined and will be repeated for all pages.
193<p>
194The correct "Total Page" does get calculated and used in the print out Footer.
195<p>
196There is still problems with the print framework to properly get the total pages in the preview unless
197the program knows it before trying to parse through the available pages. This will be fixed
198when the framework allows for it.
199
200
8fa876ca 201""" % os.path.join(os.path.dirname(printout.__file__), "printout.py")
53fe40ba 202
1fded56b
RD
203
204
205
206
207if __name__ == '__main__':
208 import sys,os
209 import run
8eca4fef 210 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1fded56b 211