Skip to content

Commit

Permalink
Merge from 5.x: PR #20268
Browse files Browse the repository at this point in the history
Fixes #20255
  • Loading branch information
dalthviz committed Dec 28, 2022
2 parents 64ddbd9 + 7a00975 commit ec93395
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 17 deletions.
1 change: 1 addition & 0 deletions spyder/utils/icon_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def __init__(self):
'drag_dock_widget': [('mdi.drag-variant',), {'color': self.MAIN_FG_COLOR}],
'format_letter_case': [('mdi.format-letter-case',), {'color': self.MAIN_FG_COLOR}],
'format_letter_matches': [('mdi.format-letter-matches',), {'color': self.MAIN_FG_COLOR}],
'no_matches': [('mdi.do-not-disturb',), {'color': SpyderPalette.COLOR_WARN_2}],
'clear_text': [('mdi.backspace',), {'color': self.MAIN_FG_COLOR}],
'regex': [('mdi.regex',), {'color': self.MAIN_FG_COLOR}],
'log': [('mdi.file-document',), {'color': self.MAIN_FG_COLOR}],
Expand Down
21 changes: 20 additions & 1 deletion spyder/widgets/comboboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from qtpy.QtCore import QEvent, Qt, QTimer, QUrl, Signal, QSize
from qtpy.QtGui import QFont
from qtpy.QtWidgets import (QAction, QComboBox, QCompleter, QLineEdit,
QSizePolicy, QToolTip)
QSizePolicy, QToolButton, QToolTip)

# Local imports
from spyder.config.base import _
Expand Down Expand Up @@ -177,11 +177,15 @@ def __init__(self, parent, items=None, tip=None,
self.clear_action, QLineEdit.TrailingPosition
)

# Button that corresponds to the clear_action above
self.clear_button = self.lineEdit().findChildren(QToolButton)[0]

# Hide clear_action by default because lineEdit is empty when the
# combobox is created, so it doesn't make sense to show it.
self.clear_action.setVisible(False)

self.lineEdit().textChanged.connect(self._on_text_changed)
self.installEventFilter(self)

def _on_text_changed(self, text):
"""Actions to take when text has changed on the line edit widget."""
Expand All @@ -190,6 +194,21 @@ def _on_text_changed(self, text):
else:
self.clear_action.setVisible(False)

def eventFilter(self, widget, event):
"""
Event filter for this combobox.
Notes
-----
* Reduce space between clear_action and the right border of lineEdit.
"""
if event.type() == QEvent.Paint:
self.clear_button.move(
self.lineEdit().width() - 22, self.clear_button.y()
)

return super().eventFilter(widget, event)


class EditableComboBox(BaseComboBox):
"""
Expand Down
46 changes: 31 additions & 15 deletions spyder/widgets/findreplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from qtpy.QtCore import QEvent, QSize, Qt, QTimer, Signal, Slot
from qtpy.QtGui import QTextCursor
from qtpy.QtWidgets import (QAction, QGridLayout, QHBoxLayout, QLabel,
QLineEdit, QSizePolicy, QSpacerItem, QWidget)
QLineEdit, QToolButton, QSizePolicy, QSpacerItem,
QWidget)

# Local imports
from spyder.config.base import _
Expand Down Expand Up @@ -104,7 +105,7 @@ def __init__(self, parent, enable_replace=False):
self.number_matches_text.hide
)

self.warning_icon = ima.icon('warning')
self.no_matches_icon = ima.icon('no_matches')
self.error_icon = ima.icon('error')
self.messages_action = QAction(self)
self.messages_action.setVisible(False)
Expand All @@ -114,6 +115,11 @@ def __init__(self, parent, enable_replace=False):
lambda: self.messages_action.setVisible(False)
)

# Button corresponding to the messages_action above
self.messages_button = (
self.search_text.lineEdit().findChildren(QToolButton)[1]
)

self.replace_on = False
self.replace_text_button = create_toolbutton(
self,
Expand Down Expand Up @@ -249,11 +255,15 @@ def __init__(self, parent, enable_replace=False):
self.search_text.installEventFilter(self)

def eventFilter(self, widget, event):
"""Event filter for search_text widget.
Emits signals when presing Enter and Shift+Enter.
This signals are used for search forward and backward.
Also, a crude hack to get tab working in the Find/Replace boxes.
"""
Event filter for search_text widget.
Notes
-----
* Emit signals when Enter and Shift+Enter are pressed. These signals
are used for search forward and backward.
* Add crude hack to get tab working between the find/replace boxes.
* Reduce space between the messages_button and the clear one.
"""

# Type check: Prevent error in PySide where 'event' may be of type
Expand All @@ -277,7 +287,13 @@ def eventFilter(self, widget, event):
self.search_text.currentText())
self.focusNextChild()

return super(FindReplace, self).eventFilter(widget, event)
if event.type() == QEvent.Paint:
self.messages_button.move(
self.search_text.lineEdit().width() - 42,
self.messages_button.y()
)

return super().eventFilter(widget, event)

def create_shortcuts(self, parent):
"""Create shortcuts for this widget"""
Expand Down Expand Up @@ -745,7 +761,7 @@ def change_number_matches(self, current_match=0, total_matches=0):
else:
self.number_matches_text.hide()
if self.search_text.currentText():
self.show_warning()
self.show_no_matches()

def update_matches(self):
"""Update total number of matches if text has changed in the editor."""
Expand All @@ -758,9 +774,9 @@ def update_matches(self):
)
self.change_number_matches(total_matches=number_matches)

def show_warning(self):
"""Show a warning message with an icon when no matches can be found."""
self._show_icon_message('warning')
def show_no_matches(self):
"""Show a no matches message with an icon."""
self._show_icon_message('no_matches')

def show_error(self, error_msg):
"""Show a regexp error message with an icon."""
Expand All @@ -774,13 +790,13 @@ def _show_icon_message(self, kind, extra_info=None):
Parameters
----------
kind: str
The kind of message. It can be 'warning' or 'error'.
The kind of message. It can be 'no_matches' or 'error'.
extra_info:
Extra info to add to the icon's tooltip.
"""
if kind == 'warning':
if kind == 'no_matches':
tooltip = self.TOOLTIP['no_matches']
icon = self.warning_icon
icon = self.no_matches_icon
else:
tooltip = self.TOOLTIP['regexp_error']
icon = self.error_icon
Expand Down
2 changes: 1 addition & 1 deletion spyder/widgets/tests/test_findreplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_messages_action(findreplace_editor, qtbot):
qtbot.keyClicks(edit, 'foo')
assert not findreplace.number_matches_text.isVisible()
assert findreplace.messages_action.icon().cacheKey() == \
findreplace.warning_icon.cacheKey()
findreplace.no_matches_icon.cacheKey()
assert findreplace.messages_action.toolTip() == \
findreplace.TOOLTIP['no_matches']

Expand Down

0 comments on commit ec93395

Please sign in to comment.