Repository: spyder-ide/spyder

Issue:
AttributeError in dockwidgets tabbar
## Description

### What steps will reproduce the problem?

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

i dont know, im beginner in this program, so im watching a tutorial

### Traceback
```python-traceback
  File "/Users/luismireles/opt/anaconda3/envs/K37/lib/python3.7/site-packages/spyder/widgets/dock.py", line 43, in eventFilter
    self.tab_pressed(event)
  File "/Users/luismireles/opt/anaconda3/envs/K37/lib/python3.7/site-packages/spyder/widgets/dock.py", line 52, in tab_pressed
    if event.button() == Qt.RightButton:
AttributeError: 'QContextMenuEvent' object has no attribute 'button'
```

## Versions

* Spyder version: 4.0.0 
* Python version: 3.7.0
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Darwin 19.2.0

### Dependencies

```
cloudpickle >=0.5.0          :  1.2.2 (OK)
pygments >=2.0               :  2.5.2 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
sphinx >=0.6.6               :  2.3.0 (OK)
pylint >=0.25                :  2.4.4 (OK)
psutil >=0.3                 :  5.6.7 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.1.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  None (NOK)
cython >=0.21                :  0.29.14 (OK)
IPython >=4.0                :  7.10.2 (OK)
matplotlib >=2.0.0           :  3.1.1 (OK)
pandas >=0.13.1              :  0.25.3 (OK)
numpy >=1.7                  :  1.17.4 (OK)
scipy >=0.17.0               :  1.3.1 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.2 (OK)
applaunchservices >=0.1.7    :  0.2.1 (OK)
rtree >=0.8.3                :  0.8.3 (OK)
```



Discussion:
@luisgmireles, thanks for reporting.

@dalthviz, please enclose these lines:

https://github.com/spyder-ide/spyder/blob/59eded5422a0c00f6f384600f82f16ee1dfd7a40/spyder/widgets/dock.py#L52-L56

in a `try/except AttributeError` to avoid this error.

Resolving patch:
diff --git a/spyder/widgets/dock.py b/spyder/widgets/dock.py
--- a/spyder/widgets/dock.py
+++ b/spyder/widgets/dock.py
@@ -49,11 +49,17 @@ def tab_pressed(self, event):
         self.from_index = self.dock_tabbar.tabAt(event.pos())
         self.dock_tabbar.setCurrentIndex(self.from_index)
 
-        if event.button() == Qt.RightButton:
-            if self.from_index == -1:
-                self.show_nontab_menu(event)
-            else:
-                self.show_tab_menu(event)
+        try:
+            if event.button() == Qt.RightButton:
+                if self.from_index == -1:
+                    self.show_nontab_menu(event)
+                else:
+                    self.show_tab_menu(event)
+        except AttributeError:
+            # Needed to avoid an error when generating the
+            # context menu on top of the tab.
+            # See spyder-ide/spyder#11226
+            pass
 
     def show_tab_menu(self, event):
         """Show the context menu assigned to tabs."""


Test patch: