Repository: spyder-ide/spyder

Issue:
AttributeError when searching for help
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Hi,
Whenever i type an object name into the search bar in Help window to see the definition, Issue reporter shows up and says that "Spyder has encountered an internal problem!".
Thanks for your interest.
Miktat

### Traceback
```python-traceback
Traceback (most recent call last):
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 894, in force_refresh
    self.set_object_text(None, force_refresh=True)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 924, in set_object_text
    found = self.show_help(text, ignore_unknown=ignore_unknown)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 1054, in show_help
    self.render_sphinx_doc(doc, css_path=self.css_path)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 1016, in render_sphinx_doc
    self.show_loading_message()
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 757, in show_loading_message
    self.set_rich_text_html(
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 746, in set_rich_text_html
    self.rich_text.set_html(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 191, in set_html
    self.webview.setHtml(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\widgets\browser.py", line 367, in setHtml
    self.focusProxy().installEventFilter(self)
AttributeError: 'NoneType' object has no attribute 'installEventFilter'
Traceback (most recent call last):
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 581, in _on_sphinx_thread_html_ready
    self.set_rich_text_html(html_text, QUrl.fromLocalFile(self.css_path))
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 746, in set_rich_text_html
    self.rich_text.set_html(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 191, in set_html
    self.webview.setHtml(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\widgets\browser.py", line 367, in setHtml
    self.focusProxy().installEventFilter(self)
AttributeError: 'NoneType' object has no attribute 'installEventFilter'
Traceback (most recent call last):
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 894, in force_refresh
    self.set_object_text(None, force_refresh=True)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 924, in set_object_text
    found = self.show_help(text, ignore_unknown=ignore_unknown)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 1054, in show_help
    self.render_sphinx_doc(doc, css_path=self.css_path)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 1016, in render_sphinx_doc
    self.show_loading_message()
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 757, in show_loading_message
    self.set_rich_text_html(
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 746, in set_rich_text_html
    self.rich_text.set_html(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 191, in set_html
    self.webview.setHtml(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\widgets\browser.py", line 367, in setHtml
    self.focusProxy().installEventFilter(self)
AttributeError: 'NoneType' object has no attribute 'installEventFilter'
Traceback (most recent call last):
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 894, in force_refresh
    self.set_object_text(None, force_refresh=True)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 924, in set_object_text
    found = self.show_help(text, ignore_unknown=ignore_unknown)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 1054, in show_help
    self.render_sphinx_doc(doc, css_path=self.css_path)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 1016, in render_sphinx_doc
    self.show_loading_message()
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 757, in show_loading_message
    self.set_rich_text_html(
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 746, in set_rich_text_html
    self.rich_text.set_html(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 191, in set_html
    self.webview.setHtml(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\widgets\browser.py", line 367, in setHtml
    self.focusProxy().installEventFilter(self)
AttributeError: 'NoneType' object has no attribute 'installEventFilter'
Traceback (most recent call last):
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 581, in _on_sphinx_thread_html_ready
    self.set_rich_text_html(html_text, QUrl.fromLocalFile(self.css_path))
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 746, in set_rich_text_html
    self.rich_text.set_html(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 191, in set_html
    self.webview.setHtml(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\widgets\browser.py", line 367, in setHtml
    self.focusProxy().installEventFilter(self)
AttributeError: 'NoneType' object has no attribute 'installEventFilter'
Traceback (most recent call last):
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 581, in _on_sphinx_thread_html_ready
    self.set_rich_text_html(html_text, QUrl.fromLocalFile(self.css_path))
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 746, in set_rich_text_html
    self.rich_text.set_html(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\plugins\help\widgets.py", line 191, in set_html
    self.webview.setHtml(html_text, base_url)
  File "C:\Users\mikta\anaconda3\lib\site-packages\spyder\widgets\browser.py", line 367, in setHtml
    self.focusProxy().installEventFilter(self)
AttributeError: 'NoneType' object has no attribute 'installEventFilter'
```

## Versions

* Spyder version: 5.1.5 
* Python version: 3.8.12
* Qt version: 5.9.7
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```

# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.2 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0               :  7.27.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.0 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.1.0 (OK)
nbconvert >=4.0               :  6.1.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
paramiko >=2.4.0              :  2.7.2 (OK)
parso >=0.7.0;<0.9.0          :  0.8.2 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.10.0 (OK)
pylint >=2.5.0;<2.10.0        :  2.9.6 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.2.2;<1.3.0          :  1.2.4 (OK)
pylsp_black >=1.0.0           :  None (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.1.10 (OK)
qtawesome >=1.0.2             :  1.0.2 (OK)
qtconsole >=5.1.0             :  5.1.1 (OK)
qtpy >=1.5.0                  :  1.10.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  58.0.4 (OK)
sphinx >=0.6.6                :  4.2.0 (OK)
spyder_kernels >=2.1.1;<2.2.0 :  2.1.3 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.3 (OK)
zmq >=17                      :  22.2.1 (OK)

# Optional:
cython >=0.21                 :  None (OK)
matplotlib >=2.0.0            :  3.3.1 (OK)
numpy >=1.7                   :  1.21.2 (OK)
pandas >=1.1.1                :  1.1.3 (OK)
scipy >=0.17.0                :  None (OK)
sympy >=0.7.3                 :  None (OK)
```



Discussion:
Hey @Bobuwashere, thanks for reporting. We'll fix this problem in our next version (5.2.0), to be released in a couple of weeks.

Resolving patch:
diff --git a/spyder/widgets/browser.py b/spyder/widgets/browser.py
--- a/spyder/widgets/browser.py
+++ b/spyder/widgets/browser.py
@@ -367,9 +367,15 @@ def setHtml(self, html, baseUrl=QUrl()):
         else:
             super(WebView, self).setHtml(html, baseUrl)
 
-        # The event filter needs to be installed every time html is set
-        # because the proxy changes with new content.
-        self.focusProxy().installEventFilter(self)
+        # This is required to catch an error with PyQt 5.9, for which
+        # it seems this functionality is not working.
+        # Fixes spyder-ide/spyder#16703
+        try:
+            # The event filter needs to be installed every time html is set
+            # because the proxy changes with new content.
+            self.focusProxy().installEventFilter(self)
+        except AttributeError:
+            pass
 
     def load(self, url):
         """


Test patch: