FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Tkagg fixes by anntzer · Pull Request #9275 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (4) All 1 file type selected
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 3 additions & 3 deletions examples/animation/simple_anim.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def animate(i):
line.set_ydata(np.sin(x + i/10.0)) # update the data
line.set_ydata(np.sin(x + i / 100)) # update the data
return line,


Expand All @@ -25,6 +25,6 @@ def init():
line.set_ydata(np.ma.array(x, mask=True))
return line,

ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,
interval=25, blit=True)
ani = animation.FuncAnimation(
fig, animate, init_func=init, interval=2, blit=True)
plt.show()
49 changes: 0 additions & 49 deletions examples/user_interfaces/embedding_in_tk2_sgskip.py

This file was deleted.

51 changes: 21 additions & 30 deletions examples/user_interfaces/embedding_in_tk_sgskip.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,51 @@
===============

"""
import matplotlib
matplotlib.use('TkAgg')

from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
# implement the default mpl key bindings
from matplotlib.backend_bases import key_press_handler

from six.moves import tkinter as Tk

from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2TkAgg)
# Implement the default Matplotlib key bindings.
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure

import sys
if sys.version_info[0] < 3:
import Tkinter as Tk
else:
import tkinter as Tk

root = Tk.Tk()
root.wm_title("Embedding in TK")
import numpy as np


f = Figure(figsize=(5, 4), dpi=100)
a = f.add_subplot(111)
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)

a.plot(t, s)
root = Tk.Tk()
root.wm_title("Embedding in Tk")

fig = Figure(figsize=(5, 4), dpi=100)
t = np.arange(0, 3, .01)
fig.add_subplot(111).plot(t, 2 * np.sin(2 * np.pi * t))

# a tk.DrawingArea
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea.
canvas.draw()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)

toolbar = NavigationToolbar2TkAgg(canvas, root)
toolbar.update()
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)


def on_key_event(event):
print('you pressed %s' % event.key)
def on_key_press(event):
print("you pressed {}".format(event.key))
key_press_handler(event, canvas, toolbar)

canvas.mpl_connect('key_press_event', on_key_event)

canvas.mpl_connect("key_press_event", on_key_press)


def _quit():
root.quit() # stops mainloop
root.destroy() # this is necessary on Windows to prevent
# Fatal Python Error: PyEval_RestoreThread: NULL tstate

button = Tk.Button(master=root, text='Quit', command=_quit)

button = Tk.Button(master=root, text="Quit", command=_quit)
button.pack(side=Tk.BOTTOM)

Tk.mainloop()
# If you put root.destroy() here, it will cause an error if
# the window is closed with the window manager.
# If you put root.destroy() here, it will cause an error if the window is
# closed with the window manager.
18 changes: 10 additions & 8 deletions lib/matplotlib/backends/backend_tkagg.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def resize(self, event):
master=self._tkcanvas, width=int(width), height=int(height))
self._tkcanvas.create_image(int(width/2),int(height/2),image=self._tkphoto)
self.resize_event()
self.show()
self.draw()

# a resizing will in general move the pointer position
# relative to the canvas, so process it as a motion notify
Expand Down Expand Up @@ -307,10 +307,12 @@ def draw(self):
self._master.update_idletasks()

def blit(self, bbox=None):
tkagg.blit(self._tkphoto, self.renderer._renderer, bbox=bbox, colormode=2)
tkagg.blit(
self._tkphoto, self.renderer._renderer, bbox=bbox, colormode=2)
self._master.update_idletasks()

show = draw
show = cbook.deprecated("2.2", name="FigureCanvasTkAgg.show",
alternative="FigureCanvasTkAgg.draw")(draw)

def draw_idle(self):
'update drawing area only if idle'
Expand Down Expand Up @@ -536,6 +538,8 @@ def resize(self, width, height=None):

# when a single parameter is given, consider it as a event
if height is None:
cbook.warn_deprecated("2.2", "FigureManagerTkAgg.resize now takes "
"width and height as separate arguments")
width = width.width
else:
self.canvas._tkcanvas.master.geometry("%dx%d" % (width, height))
Expand All @@ -555,8 +559,6 @@ def destroy(*args):
Gcf.destroy(self._num)
self.canvas._tkcanvas.bind("<Destroy>", destroy)
self.window.deiconify()
# anim.py requires this
self.window.update()
else:
self.canvas.draw_idle()
# Raise the new window.
Expand Down Expand Up @@ -738,8 +740,8 @@ def configure_subplots(self):
window = Tk.Toplevel()
canvas = FigureCanvasTkAgg(toolfig, master=window)
toolfig.subplots_adjust(top=0.9)
canvas.tool = SubplotTool(self.canvas.figure, toolfig)
canvas.show()
canvas.tool = SubplotTool(self.canvas.figure, toolfig)
canvas.draw()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
window.grab_set()

Expand Down Expand Up @@ -1021,7 +1023,7 @@ def init_window(self):
canvas = FigureCanvasTkAgg(toolfig, master=self.window)
toolfig.subplots_adjust(top=0.9)
_tool = SubplotTool(self.figure, toolfig)
canvas.show()
canvas.draw()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
self.window.protocol("WM_DELETE_WINDOW", self.destroy)

Expand Down

Back | FazBrowse Home | New Git URL