Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid possible exception when toggling full-screen #4844

Merged
merged 2 commits into from Aug 6, 2015

Conversation

jlutgen
Copy link
Contributor

@jlutgen jlutgen commented Aug 1, 2015

In examples/user_interfaces/embedding_in_tk.py, a FigureCanvasTkAgg is embedded into a Tkinter window and the default mpl key bindings are implemented with matplotlib.backend_bases.key_press_handler. If the user attempts to toggle full-screen mode by pressing 'f', an AttributeError is raised because the FigureCanvasTkAgg has no 'manager' attribute. Indeed, since pyplot is not being used, no FigureManagerTkAgg object gets created.

One fix is to check for the 'manager' attribute and do nothing if it doesn't exist. (This is what is done in FigureCanvasBase.get_window_title/set_window_title, for example.)

Traceback

In `examples/user_interfaces/embedding_in_tk.py`, a FigureCanvasTkAgg is embedded into a Tkinter window and the default mpl key bindings are implemented with matplotlib.backend_bases.key_press_handler. If the user attempts to toggle full-screen mode by pressing 'f', an AttributeError is raised because the FigureCanvasTkAgg has no 'manager' attribute. Indeed, since pyplot is not being used, no FigureManagerTkAgg object gets created. 

One fix is to check for the 'manager' attribute and do nothing if it doesn't exist. (This is what is done in FigureCanvasBase.get_window_title/set_window_title, for example.)
@@ -2479,7 +2479,8 @@ def key_press_handler(event, canvas, toolbar=None):

# toggle fullscreen mode (default key 'f')
if event.key in fullscreen_keys:
canvas.manager.full_screen_toggle()
if hasattr(canvas, 'manager'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use a try: ... except AttributeError instead?

@jlutgen
Copy link
Contributor Author

jlutgen commented Aug 1, 2015

@tacaswell Yes, try/except is much nicer. Thanks.

tacaswell added a commit that referenced this pull request Aug 6, 2015
FIX: Avoid possible exception when toggling full-screen
@tacaswell tacaswell merged commit d265a6e into matplotlib:master Aug 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants