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
Remove figure from Gcf when it is closed #1683
Conversation
Gcf when it is closed. In PR matplotlib#1498 the attribute WA_DeleteOnClose was no longer set on the QtMainWindow object in QtFigureManager. The signal connection that was being used to remove the figure from Gcf when the window was closed was tied to the `destroyed()` signal of QtMainWindow, which is no longer being destroyed. Thus, gca and gcf would return references to no-longer visible figures/axes. _widgetclosed is now called when MainWindow emits 'closing()'.
How do we test these Qt4-based issues? I merged #1678 because there appeared to be no succinct way to test it, but perhaps that was an oversight on my part. |
@@ -389,7 +389,9 @@ def __init__( self, canvas, num ): | |||
self.window = MainWindow() | |||
self.window.connect(self.window, QtCore.SIGNAL('closing()'), | |||
canvas.close_event) | |||
|
|||
self.window.connect( self.window, QtCore.SIGNAL( 'closing()' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra whitespace has found its way in here. would you mind removing it? (Is it an automatic editor thing?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, on my to-do list this weekend is to get my editor set up to highlight pep8 issue.
This is not directly related to #1678 , it's fixing a bug from #1498 I don't know how to test this stuff in general. As near as I can tell, there is no UI testing at all. This particular bug should be straight forward to test (make a figure, call close() on it, look at the state of Gcf before and after), but I don't know enough about nose to write that test from scratch (if you can point me at a similar test, I can take a crack at it). |
@tacaswell I made a pull request against your branch to add a skeleton test for you. See tacaswell#1. |
Add figure close test for qt4 backend
@tacaswell Now you need to add the |
I think all of the test failures are false-negatives
|
@@ -0,0 +1,25 @@ | |||
from matplotlib import rcParams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you moved from rcParams
to switch_backend
, so you can remove this line.
I think you are right. The |
It is the same failure as this one which you pointed out in this thread: |
Yep. I no longer get that failure locally, but it doesn't seem to sit well with Travis. You clearly didn't cause the error. |
@cleanup | ||
def test_fig_close(): | ||
# force switch to the Qt4 backend | ||
plt.switch_backend('Qt4Agg') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably mark this test as knownfail
or skip
if Qt4/PySide are not installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the correct way to test if Qt4/PySide is available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like:
try:
import Qt
HAS_PYQT = True
except ImportError:
HAS_PYQT = False
(And obviously extend to also check for PySide -- it should be good enough to have one or the other).
as this should hit either PySide or PyQt4, depending on which is installed. (I have faith that the setup code that will make sure that if only one of them is installed, it defaults to using that one)
It looks like travis does not have Qt, but yet this test seems to pass. I am deeply confused why this test did not fail on travis before adding the guard. |
@tacaswell To investigate, you can simulate a missing dependency locally: sys.modules['Qt'] = None
try:
import Qt # will fail
HAS_PYQT = True
except ImportError:
HAS_PYQT = False P.S.: I thought it was |
Ah -- I think Travis is using And, yes, I misremembered the name of the module. Indeed it is |
Not tested; merely proven to be correct. |
@tacaswell That's my fault. I should have added that when I forked your branch. Apologies for the wild goose chase. |
@dmcdougall no worries. I will deal with this tonight. |
I also checked that it does indeed fail (gracefully) if you hide both |
+1 |
can this get tagged to 1.2.x? I think it should have the same milestone as the commit that introduced the bug. Sorry if I am mis-understanding the meaning of milestones/the release process (as none of the commits related to this are on the v1.2.x branch). |
I agree.
I just noticed this wasn't targeted to the |
Yes: #1498 was cherry-picked to v1.2.x. This should be as well. |
Superceded by #1705. Closing. |
Re-wired signal/slot connections so that the figure in removed from Gcf when it is closed.
In PR #1498 the attribute WA_DeleteOnClose was no longer set on the
QtMainWindow object in QtFigureManager. The signal connection that
was being used to remove the figure from Gcf when the window was closed
was tied to the
destroyed()
signal of QtMainWindow, which is nolonger being destroyed. Thus, gca and gcf would return references
to no-longer visible figures/axes. _widgetclosed is now called when
MainWindow emits 'closing()'.