Repository: spyder-ide/spyder

Issue:
AttributeError: 'NoneType' object has no attribute 'raise_' error on startup in latest master
## Problem Description

An error occur when starting Spyder on the latest version of master

I think this may have been introduced by spyder-ide/spyder#7205, but the error was masked by spyder-ide/spyder#8216

### What steps reproduce the problem?

1. Start Spyder

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

This is occurring during startup during `2018-11-21 09:02:14,368 [INFO] [spyder.app.mainwindow] -> Loading editor...`.

```python-traceback
Traceback (most recent call last):
  File "C:\Users\User\spyder\spyder\plugins\editor\plugin.py", line 1315, in toogle
    self.switch_to_plugin()
  File "C:\Users\User\spyder\spyder\plugins\editor\plugin.py", line 1612, in switch_to_plugin
    super(Editor, self).switch_to_plugin()
  File "C:\Users\User\spyder\spyder\plugins\base.py", line 131, in switch_to_plugin
    self.visibility_changed(True)
  File "C:\Users\User\spyder\spyder\plugins\editor\plugin.py", line 667, in visibility_changed
    SpyderPluginWidget.visibility_changed(self, enable)
  File "C:\Users\User\spyder\spyder\api\plugins.py", line 155, in visibility_changed
    self.dockwidget.raise_()
AttributeError: 'NoneType' object has no attribute 'raise_'
Traceback (most recent call last):
  File "C:\Users\User\spyder\spyder\plugins\editor\plugin.py", line 1315, in toogle
    self.switch_to_plugin()
  File "C:\Users\User\spyder\spyder\plugins\editor\plugin.py", line 1612, in switch_to_plugin
    super(Editor, self).switch_to_plugin()
  File "C:\Users\User\spyder\spyder\plugins\base.py", line 131, in switch_to_plugin
    self.visibility_changed(True)
  File "C:\Users\User\spyder\spyder\plugins\editor\plugin.py", line 667, in visibility_changed
    SpyderPluginWidget.visibility_changed(self, enable)
  File "C:\Users\User\spyder\spyder\api\plugins.py", line 155, in visibility_changed
    self.dockwidget.raise_()
AttributeError: 'NoneType' object has no attribute 'raise_'
```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: Spyder 4.0.0.dev0  https://github.com/spyder-ide/spyder/commit/f08fd91ab96caef8b2a359fb3bb4a7365dbbeaa0
* Python version: Python 3.6.6 64-bit 
* Qt version: Qt 5.9.4 
* PyQt version: PyQt5 5.9.2 
* Operating System name/version: Windows 10 

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
pygments >=2.0    :  2.2.0 (OK)
sphinx >=0.6.6    :  1.8.1 (OK)
pyls >=0.19.0     :  0.19.0 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
pandas >=0.13.1   :  0.23.4 (OK)
numpy >=1.7       :  1.15.2 (OK)
sympy >=0.7.3     :  None (NOK)
cython >=0.21     :  None (NOK)
qtconsole >=4.2.0 :  4.5.0.dev0 (OK)
IPython >=4.0     :  7.0.1 (OK)
matplotlib >=2.0.0:  None (NOK)
pylint >=0.25     :  2.1.1 (OK)

```



Discussion:
> but the error was masked by #8216

I think this conjecture may correct, since when I checked out a commit before that fix, if closed the first error dialog very quickly with just the right timing, the other error would pop up. However, I had to do it so fast I'm not sure which one was before which and I couldn't reliably get the timing right to reproduce that easily. However, now that its fixed this error always occurs reliably.
@dalthviz, please work on this one.

Resolving patch:
diff --git a/spyder/api/plugins.py b/spyder/api/plugins.py
--- a/spyder/api/plugins.py
+++ b/spyder/api/plugins.py
@@ -151,6 +151,8 @@ def register_widget_shortcuts(self, widget):
 
     def visibility_changed(self, enable):
         """Dock widget visibility has changed."""
+        if self.dockwidget is None:
+            return
         if enable:
             self.dockwidget.raise_()
             widget = self.get_focus_widget()


Test patch: