File: Blt_test.py

package info (click to toggle)
python-pmw 0.8.5-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,820 kB
  • ctags: 3,468
  • sloc: python: 14,898; makefile: 37; sh: 17
file content (352 lines) | stat: -rw-r--r-- 13,067 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# Tests for Blt widgets.

import os
import Tkinter
import Test
import Pmw

Test.initialise()
testData = ()

# Blt vector type

def _setVectorItem(index, value):
    w = Test.currentWidget()
    w[index] = value

def _getVectorItem(index):
    w = Test.currentWidget()
    return w[index]

def _getVectorSlice(index1, index2):
    w = Test.currentWidget()
    return w[index1:index2]

def _delVectorItem(index):
    w = Test.currentWidget()
    del w[index]

def _vectorExpr(instanceMethod):
    w = Test.currentWidget()
    name = '::' + str(w)
    if instanceMethod:
        w.expr(name + '+ 0.5')
    else:
        return Pmw.Blt.vector_expr(name + '* 2')

def _vectorNames():
    name = '::' + str(Test.currentWidget())
    names = Pmw.Blt.vector_names()
    if name not in names:
        return names
    name2 = Pmw.Blt.vector_names(name)
    if name2 != (name,):
        return name2
    return None

if Test.haveBlt():
    c = Pmw.Blt.Vector
    tests = (
      (c.set, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
      (c.__repr__, (), '[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]'),
      (c.set, ((1, 2, 3, 4, 5, 6, 7, 8, 9, 10),)),
      (c.__repr__, (), '[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]'),
      (c.__str__, (), 'PY_VEC4'),
      (_getVectorItem, 7, 8),
      (_getVectorSlice, (3, 6), [4.0, 5.0, 6.0]),
      (_delVectorItem, 9),
      (c.get, (), [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]),
      (c.append, 10),
      (c.get, (), [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]),
      (c.length, (), 10),
      (c.append, 5),
      (c.__len__, (), 11),
      (c.count, 5, 2),
      (c.count, 20, 0),
      (c.search, 5, (4, 10)),
      (c.search, 20),
      (c.index, 5, 4),
      # Commented tests do not work because of a bug in the blt vector command.
      # (c.clear, ()),
      (_getVectorItem, 4, 5),
      #(c.remove, 5),     # This causes a core in blt 2.4 under Solaris 2.5
      #(c.index, 5, 9),
      (c.min, (), 1.0),
      (c.max, (), 10.0),
      # (c.reverse, ()),
      # (c.reverse, ()),
      # (c.get, (), [1.0, 2.0, 3.0, 4.0, 6.0, 7.0, 8.0, 9.0, 10.0, 5.0]),
      # (c.insert, (3, 66)),
      # (c.search, 66, (3,)),
      (c.get, (), [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 5.0]),
      (c.blt_sort, ()),
      (c.get, (), [1.0, 2.0, 3.0, 4.0, 5.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]),
      (c.blt_sort_reverse, ()),
      (c.get, (), [10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 5.0, 4.0, 3.0, 2.0, 1.0]),
      (_setVectorItem, (7, 77)),
      (c.search, 77, (7,)),
      (_setVectorItem, (2, 77)),
      (c.search, 77, (2, 7)),
      (_setVectorItem, (11, 77), 'TclError: can\'t set "PY_VEC4(11)": index "11" is out of range'),
      (c.get, (), [10.0, 9.0, 77.0, 7.0, 6.0, 5.0, 5.0, 77.0, 3.0, 2.0, 1.0]),
      (c.delete, (1, 3, 5)),
      (c.get, (), [10.0, 77.0, 6.0, 5.0, 77.0, 3.0, 2.0, 1.0]),
      (c.length, (), 8),
      (c.length, (9), 9),
      (c.get, (), [10.0, 77.0, 6.0, 5.0, 77.0, 3.0, 2.0, 1.0, 0.0]),
      (c.range, (1, 3), [77.0, 6.0, 5.0]),
      (_vectorExpr, 0, (20.0, 154.0, 12.0, 10.0, 154.0, 6.0, 4.0, 2.0, 0.0)),
      (_vectorExpr, 1),
      (c.get, (), [10.5, 77.5, 6.5, 5.5, 77.5, 3.5, 2.5, 1.5, 0.5]),
      (_vectorNames, ()),
    )
    testData = testData + ((c, ((tests, {}),)),)

    tests = (
      (c.get, (), [0.0, 0.0, 0.0, 0.0]),
      (c.length, (), 4),
    )
    testData = testData + ((c, ((tests, {'size' : 4}),)),)

    tests = (
      # (c.get, (), [0.0, 0.0, 0.0]),  Does not work.
      (c.length, (), 3),
      (_getVectorItem, 2, 0),
      (_getVectorItem, 4, 0),
      (_getVectorItem, 5, 'IndexError: 5'),
    )
    testData = testData + ((c, ((tests, {'size' : '2:4'}),)),)

#=============================================================================

# Blt graph widget

def _axisCommand(graph, value):
  return 'XX ' + value

def _createMarkerButton():
    w = Test.currentWidget()
    button = Tkinter.Button(w, text = 'This is\na button')
    w.marker_create('window', coords=(10, 200), window=button)

def _axisNamesSorted(pattern = None):
    w = Test.currentWidget()
    if pattern is None:
        names = list(w.axis_names())
    else:
        names = list(w.axis_names(pattern))
    names.sort()
    return tuple(names)

def _penNamesSorted(pattern = None):
    w = Test.currentWidget()
    if pattern is None:
        names = list(w.pen_names())
    else:
        names = list(w.pen_names(pattern))
    names.sort()
    return tuple(names)

if Test.haveBlt():
    c = Pmw.Blt.Graph
    tests = (
      ('height', 700),
      ('width', 900),
      (c.pack, (), {'fill': 'both', 'expand': 1}),

      (Test.num_options, (), 40),
      (c.pen_create, 'pen1', {'fill': 'green', 'symbol': 'circle'}),
      (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',}),
      (c.bar_create, 'bar1', {'xdata': Test.vector_x, 'ydata': Test.vector_y[0], 'foreground': 'blue'}),
      (c.bar_create, 'bar2', {'xdata': Test.vector_x, 'ydata': Test.vector_y[1], 'foreground': 'magenta'}),
      (c.line_create, 'line2', {'xdata': Test.vector_x, 'ydata': Test.vector_y[2], 'color': 'red'}),

      (c.marker_create, 'text', {'coords': (25, 200), 'rotate': 45, 'text':
	'This is\na marker', 'name': 'myMarker1'}, 'myMarker1'),
      (c.marker_create, 'line', {'coords': (35, 120, 15, 280), 'linewidth': 4}, 'marker1'),
      (c.marker_create, 'polygon', {'coords': (35, 40, 45, 40, 45, 120, 35, 120), 'linewidth': 4}, 'marker2'),
      (c.marker_create, 'bitmap', {'coords': (25, 200), 'rotate': 45, 'bitmap': 'questhead'}, 'marker3'),
      (_createMarkerButton, ()),

      (c.marker_after, 'myMarker1'),
      (c.marker_before, ('myMarker1', 'marker3')),
      (c.marker_create, 'text', {'coords': (10, 10), 'text':
	'Bye', 'name': 'myMarker2'}, 'myMarker2'),
      (c.marker_names, 'my*', ('myMarker1', 'myMarker2')),
      (c.marker_exists, 'myMarker2', 1),
      (c.marker_delete, ('myMarker1', 'myMarker2', 'marker3')),
      (c.marker_exists, 'myMarker2', 0),
      (c.marker_names, (), ('marker1', 'marker2', 'marker4')),
      (c.marker_type, 'marker1', 'line'),

      (c.marker_cget, ('marker1', 'linewidth'), '4'),
      (c.marker_cget, ('marker2', 'linewidth'), '4'),
      (c.marker_configure, (('marker1', 'marker2'),), {'linewidth': 5}),
      (c.marker_cget, ('marker1', 'linewidth'), '5'),
      (c.marker_cget, ('marker2', 'linewidth'), '5'),

      ('background', '#ffdddd'),
      ('barmode', 'stacked'),
      ('barwidth', 0.5),
      ('borderwidth', 100),
      ('borderwidth', 10),
      ('barwidth', 0.9),
      ('bottommargin', 100),
      ('bufferelements', 1),
      ('cursor', 'watch'),
      ('font', Test.font['variable']),
      ('foreground', 'blue'),
      ('halo', 20),
      ('barmode', 'aligned'),
      ('invertxy', 1),
      ('justify', 'left'),
      ('leftmargin', 100),
      ('plotbackground', 'aquamarine'),
      ('plotborderwidth', 4),
      ('plotrelief', 'groove'),
      ('relief', 'ridge'),
      ('rightmargin', 100),
      ('takefocus', '0'),
      ('tile', Test.earthris),
      ('barmode', 'infront'),
      ('title', 'Hello there\nmy little lovely'),
      ('topmargin', 100),
      ('invertxy', 0),

      # Change colours so that axis and legend are visible against image tile.
      (c.xaxis_configure, (), {'color': 'green'}),
      (c.yaxis_configure, (), {'color': 'green'}),
      (c.legend_configure, (), {'background': '#ffffcc'}),

      (c.axis_cget, ('x', 'color'), 'green'),
      (c.axis_configure, ('x2'), {'color': 'red'}),
      (c.axis_cget, ('x2', 'color'), 'red'),
      (c.axis_create, 'myaxis', {'rotate': 45}),
      (c.axis_cget, ('myaxis', 'rotate'), '45.0'),
      (_axisNamesSorted, (), ('myaxis', 'x', 'x2', 'y', 'y2')),
      (_axisNamesSorted, ('*x*'), ('myaxis', 'x', 'x2')),
      (c.y2axis_use, 'myaxis', 'myaxis'),
      (c.axis_delete, 'myaxis'),

      (c.extents, 'leftmargin', 100),
      (c.inside, (1000, 1000), 0),
      (c.inside, (400, 400), 1),
      (c.snap, Test.emptyimage),

      (c.element_bind, ('line1', '<1>', Test.callback), Test.callback),
      (c.element_bind, 'line1', ('<Button-1>',)),
      (c.legend_bind, ('line1', '<1>', Test.callback), Test.callback),
      (c.legend_bind, 'line1', ('<Button-1>',)),
      (c.marker_bind, ('marker1', '<1>', Test.callback), Test.callback),
      (c.marker_bind, 'marker1', ('<Button-1>',)),

      (c.pen_create, 'mypen', {'type' : 'bar', 'foreground': 'red'}),
      (c.pen_cget, ('mypen', 'foreground'), 'red'),
      (c.pen_configure, ('mypen'), {'foreground': 'green'}),
      (c.pen_cget, ('mypen', 'foreground'), 'green'),
      (_penNamesSorted, (), ('activeBar', 'activeLine', 'mypen', 'pen1')),
      (_penNamesSorted, ('*pen*'), ('mypen', 'pen1')),
      (c.pen_delete, 'mypen'),

      # These tests are not portable
      # (c.invtransform, (0, 0), (-10.2518, 507.203)),
      # (c.transform, (-10.2518, 507.203), (0.0, 0.0)),

      # Reset margins to automatic
      ('bottommargin', 0),
      ('leftmargin', 0),
      ('rightmargin', 0),
      ('topmargin', 0),

      (c.crosshairs_configure, (), {'hide': 0}),
      (c.crosshairs_configure, (), {'position': '@300,300'}),
      (c.crosshairs_configure, (), {'color': 'seagreen4'}),
      (c.crosshairs_toggle, ()),
      (c.crosshairs_cget, 'hide', 1),
      (c.crosshairs_configure, (), {'dashes': (4, 8, 8, 8)}),
      (c.crosshairs_configure, (), {'linewidth': 4}),
      (c.crosshairs_toggle, ()),
      (c.crosshairs_cget, 'hide', 0),
      (c.crosshairs_off, ()),
      (c.crosshairs_cget, 'hide', 1),
      (c.crosshairs_on, ()),
      (c.crosshairs_cget, 'hide', 0),

      (c.pen_configure, 'activeBar', {'foreground': '#ffffaa'}),

      (c.element_configure, 'bar2', {'foreground': '#ffffaa'}),
      (c.element_activate, 'bar1'),
      (c.element_activate, 'bar2'),
      (c.element_deactivate, ('bar1', 'bar2')),
      (c.element_deactivate, ()),
      (c.element_activate, ('bar2',) + tuple(range(Test.vectorSize / 2))),
      (c.element_configure, 'bar1', {'ydata': Test.vector_y[1]}),
      (c.element_configure, 'bar2', {'ydata': Test.vector_y[0]}),

      (c.element_cget, ('bar1', 'barwidth'), '0.0'),
      (c.element_cget, ('bar2', 'barwidth'), '0.0'),
      (c.element_configure, (('bar1', 'bar2'),), {'barwidth': 0.5}),
      (c.element_cget, ('bar1', 'barwidth'), '0.5'),
      (c.element_cget, ('bar2', 'barwidth'), '0.5'),

      # These tests are not portable
      # (c.element_closest, (330, 430), {}, {'x': 18.0, 'dist': 17.0, 'name': 'bar1', 'index': 18, 'y': 156.0}),
      # (c.element_closest, (0, 0)),
      # (c.element_closest, (0, 0), {'halo': 500}, {'x': 0.0, 'dist': 154.797, 'name': 'line2', 'index': 0, 'y': 359.0}),
      # (c.element_closest, (0, 0), {'halo': 500, 'interpolate': 1}, {'x': -0.0320109, 'dist': 154.797, 'name': 'line2', 'index': 0, 'y': 358.879}),

      (c.element_type, 'bar2', 'bar'),
      (c.element_type, 'line2', 'line'),

      (c.legend_activate, ('line1', 'bar2',)),
      (c.legend_activate, ()),
      (c.legend_deactivate, ('line1', 'bar2',)),
      (c.legend_deactivate, ()),
      (c.legend_configure, (), {'hide': 1}),
      (c.legend_cget, 'hide', 1),
      (c.legend_configure, (), {'hide': 0}),
      (c.legend_configure, (), {'position': 'left', 'anchor': 'nw', 'ipadx': 100, 'ipady': 100}),
      (c.legend_get, '@150,150', 'line1'),

      # This probably works, but I haven't installed the prologue file
      # (c.postscript_output, '/tmp/tmp.ps', {'landscape': 1}),
      # (os.unlink, '/tmp/tmp.ps'),

      (c.element_show, (), ('line2', 'bar2', 'bar1', 'line1')),
      (c.element_show, (('line1', 'bar1'),), ('line1', 'bar1')),
      (c.element_names, (), ('line1', 'line2', 'bar1', 'bar2')),
      (c.element_names, 'line*', ('line1', 'line2')),
      (c.element_show, (('line1', 'line2', 'bar1', 'bar2'),), ('line1', 'line2', 'bar1', 'bar2')),
      (c.element_exists, 'bar1', 1),
      (c.element_delete, ('bar1', 'bar2')),
      (c.element_names, (), ('line1', 'line2')),
      (c.element_exists, 'bar1', 0),
      (c.element_delete, ()),
      (c.element_names, (), ('line1', 'line2')),

      (c.grid_configure, (), {'hide': 0}),
      (c.grid_toggle, ()),
      (c.grid_cget, 'hide', 1),
      (c.grid_on, ()),
      (c.grid_cget, 'hide', 0),
      (c.grid_off, ()),

      # These tests are not portable
      # (c.xaxis_invtransform, 0, -37.1153),
      # (c.axis_limits, 'x', (-0.98, 49.98)),
      # (c.axis_transform, ('x', 0), 360),
      # (c.axis_invtransform, ('y', 0), 444.198),
      # (c.yaxis_limits, (), (-6.96, 406.96)),
      # (c.axis_transform, ('y', 0), 620),
      # (c.axis_invtransform, ('x2', 0), -25.1491),
      # (c.axis_limits, 'x2', (-10.4, 10.4)),
      # (c.x2axis_transform, 0, 598),
      # (c.y2axis_invtransform, 0, 12.2713),
      # (c.axis_limits, 'y2', (-10.4, 10.4)),
      # (c.axis_transform, ('y2', 0), 341),
    )
    
    testData = testData + ((c, ((tests, {}),)),)

if __name__ == '__main__':
    Test.runTests(testData)