Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | # Tests for Blt widgets. |
2 | ||
3 | import os | |
4 | import Tkinter | |
5 | import Test | |
6 | import Pmw | |
7 | ||
8 | Test.initialise() | |
9 | testData = () | |
10 | ||
11 | # Blt vector type | |
12 | ||
13 | def _setVectorItem(index, value): | |
14 | w = Test.currentWidget() | |
15 | w[index] = value | |
16 | ||
17 | def _getVectorItem(index): | |
18 | w = Test.currentWidget() | |
19 | return w[index] | |
20 | ||
21 | def _getVectorSlice(index1, index2): | |
22 | w = Test.currentWidget() | |
23 | return w[index1:index2] | |
24 | ||
25 | def _delVectorItem(index): | |
26 | w = Test.currentWidget() | |
27 | del w[index] | |
28 | ||
29 | def _vectorExpr(instanceMethod): | |
30 | w = Test.currentWidget() | |
31 | name = '::' + str(w) | |
32 | if instanceMethod: | |
33 | w.expr(name + '+ 0.5') | |
34 | else: | |
35 | return Pmw.Blt.vector_expr(name + '* 2') | |
36 | ||
37 | def _vectorNames(): | |
38 | name = '::' + str(Test.currentWidget()) | |
39 | names = Pmw.Blt.vector_names() | |
40 | if name not in names: | |
41 | return names | |
42 | name2 = Pmw.Blt.vector_names(name) | |
43 | if name2 != (name,): | |
44 | return name2 | |
45 | return None | |
46 | ||
47 | if Test.haveBlt(): | |
48 | c = Pmw.Blt.Vector | |
49 | tests = ( | |
50 | (c.set, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), | |
51 | (c.__repr__, (), '[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]'), | |
52 | (c.set, ((1, 2, 3, 4, 5, 6, 7, 8, 9, 10),)), | |
53 | (c.__repr__, (), '[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]'), | |
54 | (c.__str__, (), 'PY_VEC4'), | |
55 | (_getVectorItem, 7, 8), | |
56 | (_getVectorSlice, (3, 6), [4.0, 5.0, 6.0]), | |
57 | (_delVectorItem, 9), | |
58 | (c.get, (), [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]), | |
59 | (c.append, 10), | |
60 | (c.get, (), [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]), | |
61 | (c.length, (), 10), | |
62 | (c.append, 5), | |
63 | (c.__len__, (), 11), | |
64 | (c.count, 5, 2), | |
65 | (c.count, 20, 0), | |
66 | (c.search, 5, (4, 10)), | |
67 | (c.search, 20), | |
68 | (c.index, 5, 4), | |
69 | # Commented tests do not work because of a bug in the blt vector command. | |
70 | # (c.clear, ()), | |
71 | (_getVectorItem, 4, 5), | |
72 | #(c.remove, 5), # This causes a core in blt 2.4 under Solaris 2.5 | |
73 | #(c.index, 5, 9), | |
74 | (c.min, (), 1.0), | |
75 | (c.max, (), 10.0), | |
76 | # (c.reverse, ()), | |
77 | # (c.reverse, ()), | |
78 | # (c.get, (), [1.0, 2.0, 3.0, 4.0, 6.0, 7.0, 8.0, 9.0, 10.0, 5.0]), | |
79 | # (c.insert, (3, 66)), | |
80 | # (c.search, 66, (3,)), | |
81 | (c.get, (), [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 5.0]), | |
82 | (c.blt_sort, ()), | |
83 | (c.get, (), [1.0, 2.0, 3.0, 4.0, 5.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]), | |
84 | (c.blt_sort_reverse, ()), | |
85 | (c.get, (), [10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 5.0, 4.0, 3.0, 2.0, 1.0]), | |
86 | (_setVectorItem, (7, 77)), | |
87 | (c.search, 77, (7,)), | |
88 | (_setVectorItem, (2, 77)), | |
89 | (c.search, 77, (2, 7)), | |
90 | (_setVectorItem, (11, 77), 'TclError: can\'t set "PY_VEC4(11)": index "11" is out of range'), | |
91 | (c.get, (), [10.0, 9.0, 77.0, 7.0, 6.0, 5.0, 5.0, 77.0, 3.0, 2.0, 1.0]), | |
92 | (c.delete, (1, 3, 5)), | |
93 | (c.get, (), [10.0, 77.0, 6.0, 5.0, 77.0, 3.0, 2.0, 1.0]), | |
94 | (c.length, (), 8), | |
95 | (c.length, (9), 9), | |
96 | (c.get, (), [10.0, 77.0, 6.0, 5.0, 77.0, 3.0, 2.0, 1.0, 0.0]), | |
97 | (c.range, (1, 3), [77.0, 6.0, 5.0]), | |
98 | (_vectorExpr, 0, (20.0, 154.0, 12.0, 10.0, 154.0, 6.0, 4.0, 2.0, 0.0)), | |
99 | (_vectorExpr, 1), | |
100 | (c.get, (), [10.5, 77.5, 6.5, 5.5, 77.5, 3.5, 2.5, 1.5, 0.5]), | |
101 | (_vectorNames, ()), | |
102 | ) | |
103 | testData = testData + ((c, ((tests, {}),)),) | |
104 | ||
105 | tests = ( | |
106 | (c.get, (), [0.0, 0.0, 0.0, 0.0]), | |
107 | (c.length, (), 4), | |
108 | ) | |
109 | testData = testData + ((c, ((tests, {'size' : 4}),)),) | |
110 | ||
111 | tests = ( | |
112 | # (c.get, (), [0.0, 0.0, 0.0]), Does not work. | |
113 | (c.length, (), 3), | |
114 | (_getVectorItem, 2, 0), | |
115 | (_getVectorItem, 4, 0), | |
116 | (_getVectorItem, 5, 'IndexError: 5'), | |
117 | ) | |
118 | testData = testData + ((c, ((tests, {'size' : '2:4'}),)),) | |
119 | ||
120 | #============================================================================= | |
121 | ||
122 | # Blt graph widget | |
123 | ||
124 | def _axisCommand(graph, value): | |
125 | return 'XX ' + value | |
126 | ||
127 | def _createMarkerButton(): | |
128 | w = Test.currentWidget() | |
129 | button = Tkinter.Button(w, text = 'This is\na button') | |
130 | w.marker_create('window', coords=(10, 200), window=button) | |
131 | ||
132 | def _axisNamesSorted(pattern = None): | |
133 | w = Test.currentWidget() | |
134 | if pattern is None: | |
135 | names = list(w.axis_names()) | |
136 | else: | |
137 | names = list(w.axis_names(pattern)) | |
138 | names.sort() | |
139 | return tuple(names) | |
140 | ||
141 | def _penNamesSorted(pattern = None): | |
142 | w = Test.currentWidget() | |
143 | if pattern is None: | |
144 | names = list(w.pen_names()) | |
145 | else: | |
146 | names = list(w.pen_names(pattern)) | |
147 | names.sort() | |
148 | return tuple(names) | |
149 | ||
150 | if Test.haveBlt(): | |
151 | c = Pmw.Blt.Graph | |
152 | tests = ( | |
153 | ('height', 700), | |
154 | ('width', 900), | |
155 | (c.pack, (), {'fill': 'both', 'expand': 1}), | |
156 | ||
157 | (Test.num_options, (), 43), | |
158 | (c.pen_create, 'pen1', {'fill': 'green', 'symbol': 'circle'}), | |
159 | (c.line_create, 'line1', {'xdata': (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'ydata': (7, 2, 1, 4, 7, 3, 9, 3, 8, 5), 'pen': 'pen1',}), | |
160 | (c.bar_create, 'bar1', {'xdata': Test.vector_x, 'ydata': Test.vector_y[0], 'foreground': 'blue'}), | |
161 | (c.bar_create, 'bar2', {'xdata': Test.vector_x, 'ydata': Test.vector_y[1], 'foreground': 'magenta'}), | |
162 | (c.line_create, 'line2', {'xdata': Test.vector_x, 'ydata': Test.vector_y[2], 'color': 'red'}), | |
163 | ||
164 | (c.marker_create, 'text', {'coords': (25, 200), 'rotate': 45, 'text': | |
165 | 'This is\na marker', 'name': 'myMarker1'}, 'myMarker1'), | |
166 | (c.marker_create, 'line', {'coords': (35, 120, 15, 280), 'linewidth': 4}, 'marker1'), | |
167 | (c.marker_create, 'polygon', {'coords': (35, 40, 45, 40, 45, 120, 35, 120), 'linewidth': 4}, 'marker2'), | |
168 | (c.marker_create, 'bitmap', {'coords': (25, 200), 'rotate': 45, 'bitmap': 'questhead'}, 'marker3'), | |
169 | (_createMarkerButton, ()), | |
170 | ||
171 | (c.marker_after, 'myMarker1'), | |
172 | (c.marker_before, ('myMarker1', 'marker3')), | |
173 | (c.marker_create, 'text', {'coords': (10, 10), 'text': | |
174 | 'Bye', 'name': 'myMarker2'}, 'myMarker2'), | |
175 | (c.marker_names, 'my*', ('myMarker1', 'myMarker2')), | |
176 | (c.marker_exists, 'myMarker2', 1), | |
177 | (c.marker_delete, ('myMarker1', 'myMarker2', 'marker3')), | |
178 | (c.marker_exists, 'myMarker2', 0), | |
179 | (c.marker_names, (), ('marker1', 'marker2', 'marker4')), | |
180 | (c.marker_type, 'marker1', 'line'), | |
181 | ||
182 | (c.marker_cget, ('marker1', 'linewidth'), '4'), | |
183 | (c.marker_cget, ('marker2', 'linewidth'), '4'), | |
184 | (c.marker_configure, (('marker1', 'marker2'),), {'linewidth': 5}), | |
185 | (c.marker_cget, ('marker1', 'linewidth'), '5'), | |
186 | (c.marker_cget, ('marker2', 'linewidth'), '5'), | |
187 | ||
188 | ('background', '#ffdddd'), | |
189 | ('barmode', 'stacked'), | |
190 | ('barwidth', 0.5), | |
191 | ('borderwidth', 100), | |
192 | ('borderwidth', 10), | |
193 | ('barwidth', 0.9), | |
194 | ('bottommargin', 100), | |
195 | ('bufferelements', 1), | |
196 | ('cursor', 'watch'), | |
197 | ('font', Test.font['variable']), | |
198 | ('foreground', 'blue'), | |
199 | ('halo', 20), | |
200 | ('barmode', 'aligned'), | |
201 | ('invertxy', 1), | |
202 | ('justify', 'left'), | |
203 | ('leftmargin', 100), | |
204 | ('plotbackground', 'aquamarine'), | |
205 | ('plotborderwidth', 4), | |
206 | ('plotrelief', 'groove'), | |
207 | ('relief', 'ridge'), | |
208 | ('rightmargin', 100), | |
209 | ('takefocus', '0'), | |
210 | ('tile', Test.earthris), | |
211 | ('barmode', 'infront'), | |
212 | ('title', 'Hello there\nmy little lovely'), | |
213 | ('topmargin', 100), | |
214 | ('invertxy', 0), | |
215 | ||
216 | # Change colours so that axis and legend are visible against image tile. | |
217 | (c.xaxis_configure, (), {'color': 'green'}), | |
218 | (c.yaxis_configure, (), {'color': 'green'}), | |
219 | (c.legend_configure, (), {'background': '#ffffcc'}), | |
220 | ||
221 | (c.axis_cget, ('x', 'color'), 'green'), | |
222 | (c.axis_configure, ('x2'), {'color': 'red'}), | |
223 | (c.axis_cget, ('x2', 'color'), 'red'), | |
224 | (c.axis_create, 'myaxis', {'rotate': 45}), | |
225 | (c.axis_cget, ('myaxis', 'rotate'), '45.0'), | |
226 | (_axisNamesSorted, (), ('myaxis', 'x', 'x2', 'y', 'y2')), | |
227 | (_axisNamesSorted, ('*x*'), ('myaxis', 'x', 'x2')), | |
228 | # Blt 2.4u returns the empty string for the axis use command | |
229 | # (c.y2axis_use, 'myaxis', 'myaxis'), | |
230 | (c.axis_delete, 'myaxis'), | |
231 | ||
232 | (c.extents, 'leftmargin', 100), | |
233 | (c.inside, (1000, 1000), 0), | |
234 | (c.inside, (400, 400), 1), | |
235 | (c.snap, Test.emptyimage), | |
236 | ||
237 | (c.element_bind, ('line1', '<1>', Test.callback), Test.callback), | |
238 | (c.element_bind, 'line1', ('<Button-1>',)), | |
239 | (c.legend_bind, ('line1', '<1>', Test.callback), Test.callback), | |
240 | (c.legend_bind, 'line1', ('<Button-1>',)), | |
241 | (c.marker_bind, ('marker1', '<1>', Test.callback), Test.callback), | |
242 | (c.marker_bind, 'marker1', ('<Button-1>',)), | |
243 | ||
244 | (c.pen_create, 'mypen', {'type' : 'bar', 'foreground': 'red'}), | |
245 | (c.pen_cget, ('mypen', 'foreground'), 'red'), | |
246 | (c.pen_configure, ('mypen'), {'foreground': 'green'}), | |
247 | (c.pen_cget, ('mypen', 'foreground'), 'green'), | |
248 | (_penNamesSorted, (), ('activeBar', 'activeLine', 'mypen', 'pen1')), | |
249 | (_penNamesSorted, ('*pen*'), ('mypen', 'pen1')), | |
250 | (c.pen_delete, 'mypen'), | |
251 | ||
252 | # These tests are not portable | |
253 | # (c.invtransform, (0, 0), (-10.2518, 507.203)), | |
254 | # (c.transform, (-10.2518, 507.203), (0.0, 0.0)), | |
255 | ||
256 | # Reset margins to automatic | |
257 | ('bottommargin', 0), | |
258 | ('leftmargin', 0), | |
259 | ('rightmargin', 0), | |
260 | ('topmargin', 0), | |
261 | ||
262 | (c.crosshairs_configure, (), {'hide': 0}), | |
263 | (c.crosshairs_configure, (), {'position': '@300,300'}), | |
264 | (c.crosshairs_configure, (), {'color': 'seagreen4'}), | |
265 | (c.crosshairs_toggle, ()), | |
266 | (c.crosshairs_cget, 'hide', 1), | |
267 | (c.crosshairs_configure, (), {'dashes': (4, 8, 8, 8)}), | |
268 | (c.crosshairs_configure, (), {'linewidth': 4}), | |
269 | (c.crosshairs_toggle, ()), | |
270 | (c.crosshairs_cget, 'hide', 0), | |
271 | (c.crosshairs_off, ()), | |
272 | (c.crosshairs_cget, 'hide', 1), | |
273 | (c.crosshairs_on, ()), | |
274 | (c.crosshairs_cget, 'hide', 0), | |
275 | ||
276 | # Blt 2.4u gives an error with this (looks like activeBar | |
277 | # is same as activeLine): | |
278 | # (c.pen_configure, 'activeBar', {'foreground': '#ffffaa'}), | |
279 | ||
280 | (c.element_configure, 'bar2', {'foreground': '#ffffaa'}), | |
281 | # Blt 2.4u segmentation faults around here, remove tests: | |
282 | # (c.element_activate, 'bar1'), | |
283 | # (c.element_activate, 'bar2'), | |
284 | # (c.element_deactivate, ('bar1', 'bar2')), | |
285 | # (c.element_deactivate, ()), | |
286 | # (c.element_activate, ('bar2',) + tuple(range(Test.vectorSize / 2))), | |
287 | (c.element_configure, 'bar1', {'ydata': Test.vector_y[1]}), | |
288 | (c.element_configure, 'bar2', {'ydata': Test.vector_y[0]}), | |
289 | ||
290 | (c.element_cget, ('bar1', 'barwidth'), '0.0'), | |
291 | (c.element_cget, ('bar2', 'barwidth'), '0.0'), | |
292 | (c.element_configure, (('bar1', 'bar2'),), {'barwidth': 0.5}), | |
293 | (c.element_cget, ('bar1', 'barwidth'), '0.5'), | |
294 | (c.element_cget, ('bar2', 'barwidth'), '0.5'), | |
295 | ||
296 | # These tests are not portable | |
297 | # (c.element_closest, (330, 430), {}, {'x': 18.0, 'dist': 17.0, 'name': 'bar1', 'index': 18, 'y': 156.0}), | |
298 | # (c.element_closest, (0, 0)), | |
299 | # (c.element_closest, (0, 0), {'halo': 500}, {'x': 0.0, 'dist': 154.797, 'name': 'line2', 'index': 0, 'y': 359.0}), | |
300 | # (c.element_closest, (0, 0), {'halo': 500, 'interpolate': 1}, {'x': -0.0320109, 'dist': 154.797, 'name': 'line2', 'index': 0, 'y': 358.879}), | |
301 | ||
302 | (c.element_type, 'bar2', 'bar'), | |
303 | (c.element_type, 'line2', 'line'), | |
304 | ||
305 | (c.legend_activate, ('line1', 'bar2',)), | |
306 | (c.legend_activate, ()), | |
307 | (c.legend_deactivate, ('line1', 'bar2',)), | |
308 | (c.legend_deactivate, ()), | |
309 | (c.legend_configure, (), {'hide': 1}), | |
310 | (c.legend_cget, 'hide', 1), | |
311 | (c.legend_configure, (), {'hide': 0}), | |
312 | (c.legend_configure, (), {'position': 'left', 'anchor': 'nw', 'ipadx': 100, 'ipady': 100}), | |
313 | (c.legend_get, '@150,150', 'line1'), | |
314 | ||
315 | # This probably works, but I haven't installed the prologue file | |
316 | # (c.postscript_output, '/tmp/tmp.ps', {'landscape': 1}), | |
317 | # (os.unlink, '/tmp/tmp.ps'), | |
318 | ||
319 | (c.element_show, (), ('line2', 'bar2', 'bar1', 'line1')), | |
320 | (c.element_show, (('line1', 'bar1'),), ('line1', 'bar1')), | |
321 | (c.element_names, (), ('line1', 'line2', 'bar1', 'bar2')), | |
322 | (c.element_names, 'line*', ('line1', 'line2')), | |
323 | (c.element_show, (('line1', 'line2', 'bar1', 'bar2'),), ('line1', 'line2', 'bar1', 'bar2')), | |
324 | (c.element_exists, 'bar1', 1), | |
325 | (c.element_delete, ('bar1', 'bar2')), | |
326 | (c.element_names, (), ('line1', 'line2')), | |
327 | (c.element_exists, 'bar1', 0), | |
328 | (c.element_delete, ()), | |
329 | (c.element_names, (), ('line1', 'line2')), | |
330 | ||
331 | (c.grid_configure, (), {'hide': 0}), | |
332 | (c.grid_toggle, ()), | |
333 | (c.grid_cget, 'hide', 1), | |
334 | (c.grid_on, ()), | |
335 | (c.grid_cget, 'hide', 0), | |
336 | (c.grid_off, ()), | |
337 | ||
338 | # These tests are not portable | |
339 | # (c.xaxis_invtransform, 0, -37.1153), | |
340 | # (c.axis_limits, 'x', (-0.98, 49.98)), | |
341 | # (c.axis_transform, ('x', 0), 360), | |
342 | # (c.axis_invtransform, ('y', 0), 444.198), | |
343 | # (c.yaxis_limits, (), (-6.96, 406.96)), | |
344 | # (c.axis_transform, ('y', 0), 620), | |
345 | # (c.axis_invtransform, ('x2', 0), -25.1491), | |
346 | # (c.axis_limits, 'x2', (-10.4, 10.4)), | |
347 | # (c.x2axis_transform, 0, 598), | |
348 | # (c.y2axis_invtransform, 0, 12.2713), | |
349 | # (c.axis_limits, 'y2', (-10.4, 10.4)), | |
350 | # (c.axis_transform, ('y2', 0), 341), | |
351 | ) | |
352 | ||
353 | testData = testData + ((c, ((tests, {}),)),) | |
354 | ||
355 | if __name__ == '__main__': | |
356 | Test.runTests(testData) |