1
2 """
3 Table Testing module.
4 Created Oct 2008
5 Copyright (C) Damien Farrell
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 """
21
22 import random, string
23 from Tkinter import *
24 from Tables import TableCanvas
25 from TableModels import TableModel
26
27 """Testing general functionality of tables"""
28
31 self.main = Frame(master)
32 self.main.pack(fill=BOTH,expand=1)
33 master.geometry('600x400+200+100')
34
36 """create list of l random strings, each of length n"""
37 names = []
38 for i in range(l):
39 val = ''.join(random.choice(string.ascii_lowercase) for x in range(n))
40 names.append(val)
41 return names
42
44 """Creare random dict for test data"""
45
46 data = {}
47 names = createRandomStrings(rows,16)
48 colnames = createRandomStrings(cols,5)
49 for n in names:
50 data[n]={}
51 data[n]['label'] = n
52 for c in range(0,cols):
53 colname=colnames[c]
54 vals = [round(random.normalvariate(100,50),2) for i in range(0,len(names))]
55 vals = sorted(vals)
56 i=0
57 for n in names:
58 data[n][colname] = vals[i]
59 i+=1
60 return data
61
69
71 """Setup a table and populate it with data"""
72 app = App(root)
73 master = app.main
74 model = TableModel()
75 data = createData(40)
76
77
78 model.importDict(data)
79 table = TableCanvas(master, model,
80 cellwidth=60, cellbackgr='#e3f698',
81 thefont=('Arial',12),rowheight=18, rowheaderwidth=30,
82 rowselectedcolor='yellow', editable=True)
83 table.createTableFrame()
84
85
86 model.deleteColumns([0])
87 model.deleteRows(range(0,2))
88
89
90 table.addRow(1,label='aaazzz')
91 table.addRow(label='bbb')
92 table.addRow(**{'label':'www'})
93 table.addColumn('col6')
94 model.data[1]['col6']='TEST'
95
96
97 model.columnlabels['col6'] = 'new label'
98
99 table.setSelectedRow(2)
100 table.setSelectedCol(1)
101 table.setSelectedCells(1,80,2,4)
102
103
104
105
106 model.save('test.table')
107
108 table.load('test.table')
109
110 return
111
113 """Multuple tables in one window"""
114 t=Toplevel()
115 app = App(t)
116 master = app.main
117 c=0; r=1
118 for i in range(12):
119 model = TableModel()
120 data = createData(50)
121 model.importDict(data)
122 fr = Frame(master)
123 if c%3==0: c=0; r+=1
124 fr.grid(row=r,column=c,sticky='nws')
125 table = TableCanvas(fr, model, width=250,height=150,rowheaderwidth=0)
126 table.createTableFrame()
127 c+=1
128 return
129
137
139 """Filtering/searching"""
140 model = TableModel()
141 data = createData(100)
142 model.importDict(data)
143 model.addColumn('comment')
144 for i in model.reclist:
145 val = random.sample(['a','b','c'],1)[0]
146 model.data[i]['comment'] = val
147
148
149 searchterms = [('comment', 'a', '!=', 'AND'),
150 ('comment', 'b', '!=', 'AND')]
151 vals = model.getColumnData(columnIndex=0, filters=searchterms)
152
153
154 print '%s found' %len(vals)
155
156 return
157
159 """frame placement"""
160 import Pmw
161 t=Toplevel()
162 app = App(t)
163 master = app.main
164 w = Pmw.Group(master,
165 tag_text='Show/Hide')
166 w.pack(fill=BOTH)
167 f=Frame(master)
168 f.pack(fill=BOTH)
169 table = TableCanvas(w)
170 table.createTableFrame()
171 return
172
174 """Run standard tests"""
175 root = Tk()
176 test1(root)
177 test2()
178 test3()
179 test4()
180
181 print 'GUI tests done'
182 return root
183
185 root = GUITests()
186 root.mainloop()
187
188
189 if __name__ == '__main__':
190 main()
191