|
7 | 7 | import numpy as np |
8 | 8 |
|
9 | 9 | from matplotlib.backends import _tkagg |
| 10 | +from platform import python_implementation |
10 | 11 |
|
11 | | -def blit(photoimage, aggimage, bbox=None, colormode=1): |
12 | | - tk = photoimage.tk |
13 | | - |
14 | | - if bbox is not None: |
15 | | - bbox_array = bbox.__array__() |
16 | | - else: |
17 | | - bbox_array = None |
18 | | - data = np.asarray(aggimage) |
19 | | - try: |
20 | | - tk.call( |
21 | | - "PyAggImagePhoto", photoimage, |
22 | | - id(data), colormode, id(bbox_array)) |
23 | | - except Tk.TclError: |
| 12 | +if python_implementation() == 'PyPy': |
| 13 | + def blit(photoimage, aggimage, bbox=None, colormode=1): |
| 14 | + tk = photoimage.tk |
| 15 | + |
| 16 | + if bbox is not None: |
| 17 | + bbox_array = bbox.__array__() |
| 18 | + else: |
| 19 | + bbox_array = None |
| 20 | + data = np.asarray(aggimage) |
| 21 | + try: |
| 22 | + tk.call( |
| 23 | + "PyAggImagePhoto", photoimage, |
| 24 | + data, colormode, bbox_array) |
| 25 | + except Tk.TclError: |
| 26 | + _tkagg.tkinit(tk) |
| 27 | + tk.call("PyAggImagePhoto", photoimage, |
| 28 | + data, colormode, bbox_array) |
| 29 | + |
| 30 | +else: |
| 31 | + def blit(photoimage, aggimage, bbox=None, colormode=1): |
| 32 | + tk = photoimage.tk |
| 33 | + |
| 34 | + if bbox is not None: |
| 35 | + bbox_array = bbox.__array__() |
| 36 | + else: |
| 37 | + bbox_array = None |
| 38 | + data = np.asarray(aggimage) |
24 | 39 | try: |
| 40 | + import pdb;pdb.set_trace() |
| 41 | + tk.call( |
| 42 | + "PyAggImagePhoto", photoimage, |
| 43 | + id(data), colormode, id(bbox_array)) |
| 44 | + except Tk.TclError: |
25 | 45 | try: |
26 | | - _tkagg.tkinit(tk.interpaddr(), 1) |
27 | | - except AttributeError: |
28 | | - _tkagg.tkinit(id(tk), 0) |
29 | | - tk.call("PyAggImagePhoto", photoimage, |
30 | | - id(data), colormode, id(bbox_array)) |
31 | | - except (ImportError, AttributeError, Tk.TclError): |
32 | | - raise |
| 46 | + import pdb;pdb.set_trace() |
| 47 | + try: |
| 48 | + _tkagg.tkinit(tk.interpaddr(), 1) |
| 49 | + except AttributeError: |
| 50 | + _tkagg.tkinit(id(tk), 0) |
| 51 | + tk.call("PyAggImagePhoto", photoimage, |
| 52 | + id(data), colormode, id(bbox_array)) |
| 53 | + except (ImportError, AttributeError, Tk.TclError): |
| 54 | + raise |
33 | 55 |
|
34 | 56 | def test(aggimage): |
35 | 57 | import time |
|
0 commit comments