Repository: spyder-ide/spyder

Issue:
Maximising current pane fails and hangs Spyder 3.1.x
Icon "Maximise current pane" fails in maximising panes. An error prompt pops out instead. I'm running Spyder in Anaconda 3 environment. 

**What I'm doing:**
1. Open Spyder3 in version 3.1 (tested 3.1.0., 3.1.2) as normal 
2. Press "Maximise current pane" icon
3. It fails to open the pane
4. Click the icon again and it fails to return to the previous pane layout.

**Output:**
Instead of a workable pane of my selection an error console prompts displaying this message:
`Traceback (most recent call last):
  File "/home/piotr/anaconda3/lib/python3.5/site-packages/spyder/app/mainwindow.py", line 2202, in maximize_dockwidget
    self.last_plugin.dockwidget.toggleViewAction().setDisabled(True)
AttributeError: 'NoneType' object has no attribute 'dockwidget'`

**Additional information**
I downgraded to Spyder 3.0.2 using Anaconda Navigator and maximisation of panes works fine. 

**Sofrware Versions**
I'm running Spyder in Anaconda 3 environment
* Spyder Version: 3.1.0 ; 3.1.2
* Python Version: Python 3.5.2 , Anaconda custom (64-bit)
* Operating system: Linux *ubuntu 14.04, 64-bit 
* Anaconda Version: conda 4.3.8

**Dependencies**:
jedi >=0.8.1     :  0.9.0 (OK)
matplotlib >=1.0 :  1.5.3 (OK)
nbconvert >=4.0  :  4.2.0 (OK)
numpy >=1.7      :  1.11.1 (OK)
pandas >=0.13.1  :  0.18.1 (OK)
pep8 >=0.6       :  1.7.0 (OK)
psutil >=0.3     :  4.3.1 (OK)
pyflakes >=0.6.0 :  1.3.0 (OK)
pygments >=2.0   :  2.1.3 (OK)
pylint >=0.25    :  1.5.4 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
sphinx >=0.6.6   :  1.4.6 (OK)
sympy >=0.7.3    :  1.0 (OK)



Discussion:
@mariacamilaremolinagutierrez seems like we need to check `if self.last_plugin is not None` and act accordingly.

Resolving patch:
diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py
--- a/spyder/app/mainwindow.py
+++ b/spyder/app/mainwindow.py
@@ -264,8 +264,6 @@ def __init__(self, options=None):
         self.open_project = options.open_project
 
         self.debug_print("Start of MainWindow constructor")
-        
-        self.setFocusPolicy(Qt.StrongFocus)
 
         def signal_handler(signum, frame=None):
             """Handler for signals."""
@@ -2105,12 +2103,6 @@ def moveEvent(self, event):
         # To be used by the tour to be able to move
         self.sig_moved.emit(event)
 
-    def focusInEvent(self, event):
-        """Reimplement Qt method."""
-        QMainWindow.focusInEvent(self, event)
-        if self.hasFocus():
-            self.tour.gain_focus()
-
     def hideEvent(self, event):
         """Reimplement Qt method"""
         for plugin in self.widgetlist:
@@ -2191,6 +2183,7 @@ def __update_maximize_action(self):
         self.maximize_action.setToolTip(tip)
 
     @Slot()
+    @Slot(bool)
     def maximize_dockwidget(self, restore=False):
         """Shortcut: Ctrl+Alt+Shift+M
         First call: maximize current dockwidget


Test patch:
diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py
--- a/spyder/app/tests/test_mainwindow.py
+++ b/spyder/app/tests/test_mainwindow.py
@@ -23,6 +23,28 @@ def main_window():
     return widget
 
 
+def test_maximize_minimize_plugins(main_window, qtbot):
+    """Test that the maximize button is working correctly."""
+    # Wait until the window is fully up
+    shell = main_window.ipyconsole.get_current_shellwidget()
+    qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=6000)
+
+    # Set focus to the Editor
+    main_window.editor.get_focus_widget().setFocus()
+
+    # Click the maximize button
+    max_action = main_window.maximize_action
+    max_button = main_window.main_toolbar.widgetForAction(max_action)
+    qtbot.mouseClick(max_button, Qt.LeftButton)
+
+    # Verify that the Editor is maximized
+    assert main_window.editor.ismaximized
+
+    # Verify that the action minimizes the plugin too
+    qtbot.mouseClick(max_button, Qt.LeftButton)
+    assert not main_window.editor.ismaximized
+
+
 def test_issue_4066(main_window, qtbot):
     """
     Test for a segfault when these steps are followed: