Repository: spyder-ide/spyder

Issue:
Some problems with the Find plugin in master
After merging PR #13376 I found the following problems with the Find plugin in master:

* The `Find in Files` action in the `Search` menu does nothing when Spyder is started with clean settings. That's because now it's associated to the `Search` button in its toolbar:

    ![Selección_005](https://user-images.githubusercontent.com/365293/88446283-4d3d6080-cdee-11ea-8a9d-40e992ccaf48.png)

   So it's clear why it does nothing: because there's no text to search by default. But in Spyder 4 that action was associated to the toggle action of the plugin, so it showed the plugin in case it was hidden (which is the default with clean settings).

* All buttons in the Find toolbar are now QAction's, whereas in Spyder 4 they were QToolButton's. That doesn't allow us to remove their tooltips because QActions always have an associated tooltip. For instance, in PR #13376 I removed the tooltip of the `Search` button  because it was really unnecessary.

----

The last problem points to a really significant change (switching QToolButton's for QAction's). I don't understand its purpose because it makes things less flexible for us in master (like the above issue clearly shows).

@goanpeca, could you explain your rationale for this? Also, is it possible for us to revert to QToolButton's everywhere where they were used in Spyder 4?


Discussion:

Resolving patch:
diff --git a/spyder/api/widgets/mixins.py b/spyder/api/widgets/mixins.py
--- a/spyder/api/widgets/mixins.py
+++ b/spyder/api/widgets/mixins.py
@@ -443,7 +443,8 @@ def create_action(self, name, text, icon=None, icon_text='', tip=None,
         icon: QIcon,
             Icon for the action when applied to menu or toolbutton.
         icon_text: str
-            Icon for text in toolbars.
+            Icon for text in toolbars. If True, this will also disable
+            the tooltip on this toolbutton if part of a toolbar.
         tip: str
             Tooltip to define for action on menu or toolbar.
         toggled: callable
@@ -469,6 +470,8 @@ def create_action(self, name, text, icon=None, icon_text='', tip=None,
         shortcuts on plugin registration in the main window with the
         register_shortcut argument.
 
+        If icon_text is True, this will also disable the tooltip.
+
         If a shortcut is found in the default config then it is assigned,
         otherwise it's left blank for the user to define one for it.
         """
diff --git a/spyder/api/widgets/toolbars.py b/spyder/api/widgets/toolbars.py
--- a/spyder/api/widgets/toolbars.py
+++ b/spyder/api/widgets/toolbars.py
@@ -9,13 +9,14 @@
 """
 
 # Standard library imports
-from collections import OrderedDict
 import textwrap
 import uuid
+from collections import OrderedDict
 
 # Third part imports
-from qtpy.QtCore import QSize, Qt
-from qtpy.QtWidgets import QAction, QSizePolicy, QToolBar, QWidget
+from qtpy.QtCore import QEvent, QObject, QSize, Qt
+from qtpy.QtWidgets import (QAction, QSizePolicy, QToolBar, QToolButton,
+                            QWidget)
 
 # Local imports
 from spyder.config.gui import is_dark_interface
@@ -39,6 +40,22 @@ class ToolBarLocation:
     Bottom = Qt.BottomToolBarArea
 
 
+# --- Event filters
+# ----------------------------------------------------------------------------
+class ToolTipFilter(QObject):
+    """
+    Filter tool tip events on toolbuttons.
+    """
+
+    def eventFilter(self, obj, event):
+        event_type = event.type()
+        action = obj.defaultAction() if isinstance(obj, QToolButton) else None
+        if event_type == QEvent.ToolTip and action is not None:
+            return action.text_beside_icon
+
+        return QObject.eventFilter(self, obj, event)
+
+
 # --- Widgets
 # ----------------------------------------------------------------------------
 class SpyderToolBar(QToolBar):
@@ -99,12 +116,12 @@ def _render(self):
 
             if isinstance(item, QAction):
                 text_beside_icon = getattr(item, 'text_beside_icon', False)
+                widget = self.widgetForAction(item)
+
                 if text_beside_icon:
-                    widget = self.widgetForAction(item)
                     widget.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
 
                 if item.isCheckable():
-                    widget = self.widgetForAction(item)
                     widget.setCheckable(True)
 
 
@@ -137,6 +154,7 @@ def __init__(self, parent=None, title=None, location=ToolBarLocation.Top,
         self.setContextMenuPolicy(Qt.PreventContextMenu)
         self.setIconSize(self._icon_size)
         self._setup_style()
+        self._filter = ToolTipFilter()
 
     def set_icon_size(self, icon_size):
         self._icon_size = icon_size
@@ -210,13 +228,14 @@ def _render(self):
                 add_method(item)
 
             if isinstance(item, QAction):
+                widget = self.widgetForAction(item)
+                widget.installEventFilter(self._filter)
+
                 text_beside_icon = getattr(item, 'text_beside_icon', False)
                 if text_beside_icon:
-                    widget = self.widgetForAction(item)
                     widget.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
 
                 if item.isCheckable():
-                    widget = self.widgetForAction(item)
                     widget.setCheckable(True)
 
     def _setup_style(self):
diff --git a/spyder/plugins/findinfiles/plugin.py b/spyder/plugins/findinfiles/plugin.py
--- a/spyder/plugins/findinfiles/plugin.py
+++ b/spyder/plugins/findinfiles/plugin.py
@@ -78,6 +78,8 @@ def register(self):
             findinfiles_action,
             menu=menu,
         )
+        findinfiles_action.triggered.connect(lambda: self.switch_to_plugin())
+
         search_toolbar = self.get_application_toolbar(
             ApplicationToolBars.Search)
         self.add_item_to_application_toolbar(


Test patch: