Repository: spyder-ide/spyder

Issue:
Editor - Cannot close a (vertical) split after open
## Description
In editor, after splitting (vertically), when trying to 'close this panel' in the newly created split panel, an error returns.

**What steps will reproduce the problem?**

1. In editor, open some .py file. 
2. Then, at the upper right corner of the editor panel, use the 'wheel' shape drop-down menu to choose 'split vertically'
3. Go to the newly created split panel, click on its 'wheel' shape drop-down menu, the error will appear.

**What is the expected output? What do you see instead?**
I expect I can 'close this panel' to close the newly created split panel. It gives me an error instead. 

**Please provide any additional information below**

  File "C:\ProgramData\Anaconda2\lib\site-packages\spyder\widgets\editor.py", line 1239, in __setup_menu
    add_actions(self.menu, list(actions) + self.__get_split_actions())
  File "C:\ProgramData\Anaconda2\lib\site-packages\spyder\utils\qthelpers.py", line 314, in add_actions
    target.addAction(action)
RuntimeError: wrapped C/C++ object of type SpyderAction has been deleted


## Version and main components

* Spyder Version: 3.2.1 
* Python Version: 2.7.13
* Qt Versions: 5.6.2, PyQt5 5.6 on Windows

## Dependencies
```
pyflakes >=0.5.0  :  1.6.0 (OK)
pycodestyle >=2.3 :  2.3.1 (OK)
pygments >=2.0    :  2.2.0 (OK)
pandas >=0.13.1   :  0.20.3 (OK)
numpy >=1.7       :  1.13.1 (OK)
sphinx >=0.6.6    :  1.6.3 (OK)
rope >=0.9.4      :  0.9.4 (OK)
jedi >=0.9.0      :  0.10.2 (OK)
nbconvert >=4.0   :  5.2.1 (OK)
sympy >=0.7.3     :  1.1.1 (OK)
cython >=0.21     :  0.26 (OK)
qtconsole >=4.2.0 :  4.3.1 (OK)
IPython >=4.0;<6.0:  5.3.0 (OK)
pylint >=0.25     :  1.7.2 (OK)

```



Discussion:
@dalthviz, can you reproduce this?
Yes,  many times. On Aug 28, 2017 4:31 PM, Carlos Cordoba <notifications@github.com> wrote:@dalthviz, can you reproduce this?

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or mute the thread.
I was asking to @dalthviz.

This was supposed to be fixed in 3.2.1, so I don't understand what happens in your case.
I am using 3.2.1 but it happened twice to me today. I am away from my deck now.  I can try again later tonight.On Aug 28, 2017 4:45 PM, Carlos Cordoba <notifications@github.com> wrote:I was asking to @dalthviz.
This was supposed to be fixed in 3.2.1, so I don't understand what happens in your case.

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or mute the thread.
Hi, just back home and I am sure I can replicate. Here are the steps: 
1. Launch spyder.2. I have a .py file already opened since my last use. On the editor, click on the 'wheel' menu at the upper right corner. 3. Choose 'split vertically' (I also tried 'split horizontally, same). 4. Now, go to the newly created panel. Click the the 'wheel' menu at the upper right corner, and the error appears. 
Notice that, the first time I tried, it seems working without the error. In this case, try to resize the newly created panel, and click on the 'wheel' menu, the error will appear.
I installed via anaconda and update the my spyder 3.2.1 as well. My home computer is i5, windows 10 home, with 8Mb ram. Apart from spyder, I was also running a chrome, and openned 2 IE to look at same subdir. I am running python 2.7 using ipython as my console. 
Please let me know if you need more info.
Thanks. 
 

    On Monday, August 28, 2017 4:45 PM, Carlos Cordoba <notifications@github.com> wrote:
 

 I was asking to @dalthviz.This was supposed to be fixed in 3.2.1, so I don't understand what happens in your case.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.  

   
I tried again this morning. I found that apart from: 
"Notice that, the first time I tried, it seems working without the error. In this case, try to resize the newly created panel, and click on the 'wheel' menu, the error will appear." 
Sometimes, if clicking the 'wheel' menu of the newly created panel and works without the error, then go ahead to choose 'close the panel'. Then go to the original panel and split again. This time, click on the 'wheel' menu of the newly created panel will trigger the error. 
Hope this help.
Thanks again. 

    On Monday, August 28, 2017 5:56 PM, Chiu Y. <chiu2@yahoo.com> wrote:
 

 Hi, just back home and I am sure I can replicate. Here are the steps: 
1. Launch spyder.2. I have a .py file already opened since my last use. On the editor, click on the 'wheel' menu at the upper right corner. 3. Choose 'split vertically' (I also tried 'split horizontally, same). 4. Now, go to the newly created panel. Click the the 'wheel' menu at the upper right corner, and the error appears. 
Notice that, the first time I tried, it seems working without the error. In this case, try to resize the newly created panel, and click on the 'wheel' menu, the error will appear.
I installed via anaconda and update the my spyder 3.2.1 as well. My home computer is i5, windows 10 home, with 8Mb ram. Apart from spyder, I was also running a chrome, and openned 2 IE to look at same subdir. I am running python 2.7 using ipython as my console. 
Please let me know if you need more info.
Thanks. 
 

    On Monday, August 28, 2017 4:45 PM, Carlos Cordoba <notifications@github.com> wrote:
 

 I was asking to @dalthviz.This was supposed to be fixed in 3.2.1, so I don't understand what happens in your case.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.  

   

   
@ccordoba12 testing in Python2 I can reproduce the problem.
@dalthviz, thanks!

@andfoy, please take a look at this one.

Resolving patch:
diff --git a/spyder/utils/qthelpers.py b/spyder/utils/qthelpers.py
--- a/spyder/utils/qthelpers.py
+++ b/spyder/utils/qthelpers.py
@@ -311,7 +311,12 @@ def add_actions(target, actions, insert_before=None):
                     except RuntimeError:
                         continue
             if insert_before is None:
-                target.addAction(action)
+                # This is needed in order to ignore adding an action whose
+                # wrapped C/C++ object has been deleted. See issue 5074
+                try:
+                    target.addAction(action)
+                except RuntimeError:
+                    continue
             else:
                 target.insertAction(insert_before, action)
         previous_action = action


Test patch: