10000 register _blit with Tcl without an extra widget · matplotlib/matplotlib@321b7a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 321b7a0

Browse files
register _blit with Tcl without an extra widget
current status: Relies on tkinter arcana, untested
1 parent a4a920e commit 321b7a0

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def _restore_foreground_window_at_end():
4545

4646

4747
_blit_args = {}
48-
_blit_tcl_name = None
48+
# Initialized to non-empty string that is not a current Tcl command
49+
_blit_tcl_name = "29345091836409813"
4950

5051

5152
def _blit(argsid):
@@ -56,7 +57,7 @@ def _blit(argsid):
5657
_tkagg.blit(*args)
5758

5859

59-
def blit(tk_instance, photoimage, aggimage, offsets, bbox=None):
60+
def blit(photoimage, aggimage, offsets, bbox=None):
6061
"""
6162
Blit *aggimage* to *photoimage*.
6263
@@ -92,13 +93,12 @@ def blit(tk_instance, photoimage, aggimage, offsets, bbox=None):
9293
global _blit_tcl_name
9394
# tkapp.call coerces all arguments to strings
9495
try:
95-
tk_instance.tk.call(_blit_tcl_name, argsid)
96+
photoimage.tk.call(_blit_tcl_name, argsid)
9697
except tk.TclError:
97-
# need to register with the tk root or constantly re-register
98-
# each time tk_instance is destroyed
99-
root = tk_instance._root()
100-
_blit_tcl_name = root.register(_blit)
101-
tk_instance.tk.call(_blit_tcl_name, argsid)
98+
# register _blit by copying code from tkinter.Misc._register
99+
_blit_tcl_name = repr(id(_blit)) + _blit.__name__
100+
photoimage.tk.createcommand(_blit_tcl_name, _blit)
101+
photoimage.tk.call(_blit_tcl_name, argsid)
102102

103103

104104
class TimerTk(TimerBase):

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ def draw(self):
99
self.blit()
1010

1111
def blit(self, bbox=None):
12-
blit(self._tkcanvas, self._tkphoto,
13-
self.renderer._renderer, (0, 1, 2, 3), bbox=bbox)
12+
blit(self._tkphoto, self.renderer._renderer, (0, 1, 2, 3), bbox=bbox)
1413

1514

1615
@_BackendTk.export

lib/matplotlib/backends/backend_tkcairo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def draw(self):
2121
self.figure.draw(self._renderer)
2222
buf = np.reshape(surface.get_data(), (height, width, 4))
2323
_backend_tk.blit(
24-
self._tkcanvas, self._tkphoto, buf,
24+
self._tkphoto, buf,
2525
(2, 1, 0, 3) if sys.byteorder == "little" else (1, 2, 3, 0))
2626

2727

0 commit comments

Comments
 (0)
0