Repository: spyder-ide/spyder

Issue:
Console/Editor lose focus when auto-connected to help
## Description of your problem
1. Open spyder
2. Enable automatic connection to help in settings
3. Type in editor or console until the help connects, either by function(, or function? in the console

Expected behaviour is for the help for that function to show and I can continue typing my code.
What happens is that when the help activates, where I'm typing loses focus and I need to click back into the editor or console window to continue typing. The only way to write code in the editor without constantly being interrupted is to disable the help connection, which is annoying because thats one of my favourite parts of spyder.
## Versions and main components
- Spyder Version: 3.0.0b4
- Python Version:3.5.2
- Operating system: Mac OSX 10.11.5
## Dependencies

jedi >=0.8.1     :  0.9.0 (OK)
matplotlib >=1.0 :  1.5.1 (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.0 (OK)
pyflakes >=0.6.0 :  1.2.3 (OK)
pygments >=2.0   :  2.1.3 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
sphinx >=0.6.6   :  1.4.1 (OK)
sympy >=0.7.3    :  1.0 (OK)



Discussion:
We need to give focus to the Help pane to show it in case it's not visible at the moment of asking for the docs of an object.

But we could improve the logic of how this is done to not do it every time a request is sent to Help ;-)

Or we should just give the focus back to the editor (in the cases where the help pane was indeed "hidden") ?

Needing to give focus makes sense, but it is obstructive to typing when it happens at every open bracket. This isn't the behaviour I get on the Windows version, so there must be something different about the Mac. 

The solution could either be to send the focus back and make sure it happens fast enough that is doesn't cause lost keystrokes.

Or, don't change the focus and just have the help update in the background. If a user has the help panel not visible, they can manually shift focus if they need to read it, which is much better than interrupting coding when they don't need it.

The problem is worst than that : when I type into the help (let's say 'percentile') I can't go further than "p" because the focus is on the Help pane showing "No further documentation available" instead of letting me typing the rest.

The problem seems to be new with the beta3 or 4 or with the QT5-
in Winpython 3.4.4.1 (not QT5), the HELP pane behave as expected. Winpython 3.4.4.1 is using Spyder3 beta2 according to their changelog ( https://github.com/winpython/winpython/issues/217 ).

I don't agree on "we need to give focus". If one would need to see the Help, he would search for the pane. Changing the focus and forcing the pane to be visible just slow down everything for a function which (imho) is meant to work in background.

On contrary to Keou0007, I reproduced it on Win7. (but in Spyder beta4 not in beta2)

I would not mark this as issue "enhancement" because this focus behaviour make the HELP pane completely useless.

With the current behavior it is impossible to work with help connected to editor and/or console. 

I don't think there is any reason to give focus to the help pane when help is updated in the background as you type. 

I would expect the focus to move to the help pane only for the cases when help is called explicitly via ctrl-I. 

Yes, we also think this is a bug.

Thank you for marking this as a bug. (I would still remove the "Type-Enhancement" label)
I tested the last WinPython version "3.4.4.4Qt5" with Spyder 3.0.0beta 5 in it : it works like a charm :)

I agree with wtheis : 

> I would expect the focus to move to the help pane only for the cases when help is called explicitly via ctrl-I. 


Resolving patch:
diff --git a/spyder/widgets/browser.py b/spyder/widgets/browser.py
--- a/spyder/widgets/browser.py
+++ b/spyder/widgets/browser.py
@@ -142,7 +142,22 @@ def contextMenuEvent(self, event):
         add_actions(menu, actions)
         menu.popup(event.globalPos())
         event.accept()
-                
+
+    def setHtml(self, html, baseUrl=QUrl()):
+        """
+        Reimplement Qt method to prevent WebEngine to steal focus
+        when setting html on the page
+
+        Solution taken from
+        https://bugreports.qt.io/browse/QTBUG-52999
+        """
+        if WEBENGINE:
+            self.setEnabled(False)
+            super(WebView, self).setHtml(html, baseUrl)
+            self.setEnabled(True)
+        else:
+            super(WebView, self).setHtml(html, baseUrl)
+
 
 class WebBrowser(QWidget):
     """


Test patch: