Repository: spyder-ide/spyder

Issue:
Cannot remove thumbnails on Plots pane
## Description
![thumnail](https://user-images.githubusercontent.com/22970578/67294365-b111c080-f520-11e9-9a0a-22c0e1455f65.gif)
  
I cannot remove thumnails of plots pane when using lastest master.
  
### What steps will reproduce the problem?

<!--- You can use Markdown here --->

1. Plot to figure browser

2. delete figure or delete thumnail



## Versions

* Spyder version: 4.0.0.dev0 d84908e66
* Python version: 3.7.3
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Linux 5.3.6-1-MANJARO

### Dependencies

```
cloudpickle >=0.5.0          :  1.2.1 (OK)
pygments >=2.0               :  2.4.2 (OK)
qtconsole >=4.5.5            :  4.5.5 (OK)
nbconvert >=4.0              :  5.5.0 (OK)
sphinx >=0.6.6               :  2.1.2 (OK)
pylint >=0.25                :  2.3.1 (OK)
psutil >=0.3                 :  5.6.3 (OK)
qtawesome >=0.5.7            :  0.5.7 (OK)
qtpy >=1.5.0                 :  1.8.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.0.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.5.0;<2.0.0:  1.6.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  1.4 (OK)
cython >=0.21                :  0.29.12 (OK)
IPython >=4.0                :  7.6.1 (OK)
matplotlib >=2.0.0           :  3.1.0 (OK)
pandas >=0.13.1              :  0.24.2 (OK)
numpy >=1.7                  :  1.16.4 (OK)
scipy >=0.17.0               :  1.3.0 (OK)
pyls >=0.28.2;<0.29.0        :  0.28.3 (OK)
xdg >=0.26                   :  0.26 (OK)
rtree >=0.8.3                :  0.8.3 (OK)
```



Discussion:
I can reproduce this on OSX! (there is some glitch with the remove button)
@steff456, please take a look at this one. It was probably introduced by PR #10476.
Also remember to add a test @steff456 !
I can't reproduce this on Linux.
I can reproduce this on Linux and on Mac!
I will work in this one :)

Resolving patch:
diff --git a/spyder/plugins/plots/widgets/figurebrowser.py b/spyder/plugins/plots/widgets/figurebrowser.py
--- a/spyder/plugins/plots/widgets/figurebrowser.py
+++ b/spyder/plugins/plots/widgets/figurebrowser.py
@@ -774,6 +774,7 @@ def remove_all_thumbnails(self):
             thumbnail.sig_canvas_clicked.disconnect()
             thumbnail.sig_remove_figure.disconnect()
             thumbnail.sig_save_figure.disconnect()
+            thumbnail.setParent(None)
         self._thumbnails = []
         self.current_thumbnail = None
         self.figure_viewer.figcanvas.clear_canvas()
@@ -784,6 +785,7 @@ def remove_thumbnail(self, thumbnail):
             index = self._thumbnails.index(thumbnail)
             self._thumbnails.remove(thumbnail)
         self.layout().removeWidget(thumbnail)
+        thumbnail.setParent(None)
         thumbnail.sig_canvas_clicked.disconnect()
         thumbnail.sig_remove_figure.disconnect()
         thumbnail.sig_save_figure.disconnect()


Test patch:
diff --git a/spyder/plugins/plots/widgets/tests/test_plots_widgets.py b/spyder/plugins/plots/widgets/tests/test_plots_widgets.py
--- a/spyder/plugins/plots/widgets/tests/test_plots_widgets.py
+++ b/spyder/plugins/plots/widgets/tests/test_plots_widgets.py
@@ -28,7 +28,8 @@
 from qtpy.QtCore import Qt
 
 # Local imports
-from spyder.plugins.plots.widgets.figurebrowser import FigureBrowser
+from spyder.plugins.plots.widgets.figurebrowser import (FigureBrowser,
+                                                        FigureThumbnail)
 from spyder.py3compat import to_text_string
 
 
@@ -210,6 +211,23 @@ def test_close_all_figures(figbrowser, tmpdir, fmt):
     assert figbrowser.thumbnails_sb.get_current_index() == -1
     assert figbrowser.thumbnails_sb.current_thumbnail is None
     assert figbrowser.figviewer.figcanvas.fig is None
+    assert len(figbrowser.thumbnails_sb.findChildren(FigureThumbnail)) == 0
+
+
+@pytest.mark.parametrize("fmt", ['image/png', 'image/svg+xml'])
+def test_close_one_thumbnail(figbrowser, tmpdir, fmt):
+    """
+    Test the thumbnail is removed from the GUI.
+    """
+    # Add two figures to the browser
+    add_figures_to_browser(figbrowser, 2, tmpdir, fmt)
+    assert len(figbrowser.thumbnails_sb.findChildren(FigureThumbnail)) == 2
+
+    # Remove the first figure
+    figures = figbrowser.thumbnails_sb.findChildren(FigureThumbnail)
+    figbrowser.thumbnails_sb.remove_thumbnail(figures[0])
+
+    assert len(figbrowser.thumbnails_sb.findChildren(FigureThumbnail)) == 1
 
 
 @pytest.mark.parametrize("fmt", ['image/png', 'image/svg+xml'])