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

Keyboard shortcuts to close the figure are not active on OS X with the backend MacOSX #4372

Closed
stsievert opened this issue Apr 23, 2015 · 16 comments
Milestone

Comments

@stsievert
Copy link

Issue

I have a special key (q) mapped to close the current figure. Using matplotlib 1.4.3 I can not close the current figure with this keymap and under the backend MacOSX. Specifically when I press the q key the keypress is sent to the shell instead.

I am currently on OSX Yosemite. My quick fix was to choose a different backed, Qt4Agg.

In my matplotlibrc file I have keymap.quit : q

Related issues

I am currently unsure if this has been fixed in the bleeding edge version of mpl. I have tested mpl-1.4.3 under a virtualenv and get the same results.

@tacaswell
Copy link
Member

attn @mdehoon

@tacaswell tacaswell added this to the next point release milestone Apr 23, 2015
@WeatherGod
Copy link
Member

Do you have other keys mapped to actions? Do they work? I wonder if this is
really a terminal/figure window focus issue.

On Thu, Apr 23, 2015 at 10:51 AM, Thomas A Caswell <notifications@github.com

wrote:

attn @mdehoon https://github.com/mdehoon


Reply to this email directly or view it on GitHub
#4372 (comment)
.

@mdehoon
Copy link
Contributor

mdehoon commented Apr 24, 2015

If I put keymap.quit : q in matplotlibrc and do the following:

$ python
Python 2.7.8 (default, Feb 27 2015, 23:52:58) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.use("macosx")
>>> from pylab import *
>>> figure()
<matplotlib.figure.Figure object at 0x1043e67d0>
>>> 

then the figure closes if I click on the figure (to make it active) and press 'q'.
If I don't click on the figure first (so the terminal keeps key input), then pressing 'q' the key press is sent to the terminal instead. Do you get the same? As far as I know, this is the desired behavior.

@stsievert
Copy link
Author

I think this is a terminal/plot focus issue. When I click on the plot, both my terminal and the figure are active (screenshot).

I have tried other keymaps. They do not work with the MacOSX backend but do work with the Qt4Agg backend.

Is this problem unique to my system? I see this behavior even under a virtualenv after activating and running pip install matplotlib.

@mdehoon
Copy link
Contributor

mdehoon commented May 1, 2015

The screenshot suggests that your Python is not installed as a framework.
See the section "Building and using a framework-based Python on Mac OS X" in the README in the subdirectory "Mac" of the Python source distribution for a full explanation.
Did you install Python yourself, or are you using a pre-compiled version of Python?

@stsievert
Copy link
Author

This issue can be close if it's local to my machine. I have solved it by switching backends.

(I'm using Anaconda)

@mdehoon
Copy link
Contributor

mdehoon commented May 19, 2015

Let's not close this issue yet. I'd like to find out why matplotlib didn't notice that Python was not installed as a framework.

@mdehoon
Copy link
Contributor

mdehoon commented May 20, 2015

@scottsievert Can you have a look in your pyconfig.h to see if WITH_NEXT_FRAMEWORK is defined? It should contain the following line:
#define WITH_NEXT_FRAMEWORK 1
To find pyconfig.h on your computer, you can use

>>> import sys
>>> sys.prefix
'/Library/Frameworks/Python.framework/Versions/2.7'

then pyconfig.h will be in the directory sys.prefix + /include/python2.7.
Also, can you let me know what sys.prefix returns in your case?

@stsievert
Copy link
Author

In [1]: import sys

In [2]: sys.prefix
Out[2]: '/Users/scott/anaconda'

The relevant part of pyconfig.h:

/* Define if you want to produce an OpenStep/Rhapsody framework (shared
   library plus accessory files). */
/* #undef WITH_NEXT_FRAMEWORK */

I just installed a fresh version of Anaconda. It worked after that fresh install.

@mdehoon
Copy link
Contributor

mdehoon commented May 20, 2015

OK thanks. Indeed your Python is not installed as a framework. Matplotlib should have noticed that when it was compiled. Did you compile matplotlib yourself, or did you use a precompiled matplotlib?

@stsievert
Copy link
Author

I used the version of mpl that came with Anaconda. I installed Anaconda long before this bug appeared, and the only real changes I can think of was that I upgraded anaconda (using conda upgrade anaconda) and developed a package which required I play with pandoc/markdown.

@stsievert
Copy link
Author

Aha, got it! This is perhaps a different issue -- it is present under a freshly installed version of anaconda.

I switched Python shells from IPython to ptipython. My keybinding 'q' works only when I use IPython. To show that, I have run the script under different python interpreters (and get different behaviors!):

from __future__ import division
from numpy import sin, linspace, pi
from matplotlib.pyplot import figure, plot, show

t = linspace(0, 2*pi)
y = sin(t)

figure()
plot(t, y)
show()

To be clear, while I was running this, by backend was MacOSX on OSX 10.10 under a freshly installed Anaconda. Under python, ptpython and ptipython, the keymap q is sent to the shell and not to the current figure window.

@mdehoon
Copy link
Contributor

mdehoon commented May 24, 2015

@scottsievert I have added a run-time check to the MacOSX backend to make sure Python is installed as a framework (see the pull request). On Python2, the same check is also available as part of the MacOS module, which is part of the Python standard library. Could you try the following with python/ipython/ptpython/ptipython:

>>> import MacOS
>>> MacOS.WMAvailable()

This should return True if python is installed as a framework, and False otherwise.

@stsievert
Copy link
Author

Shell WMAvailable()
python False
ipython True
ptpython False
ptipython False

@mdehoon
Copy link
Contributor

mdehoon commented Jun 1, 2015

Thanks! This was fixed by pull request #4452 . The new code effectively does the same as WMAvailable().
This issue can be closed.

@tacaswell
Copy link
Member

Closed by #4452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants