Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Remove lambdas in Qt slots #19471

Merged
merged 6 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spyder/api/plugins/new_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ def update_margins(self, margin):
"""
self.get_widget().update_margins(margin)

@Slot()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this (see below).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't this this one should be removed, isn't it called from a signal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example in the ipythonconsole plugin on_initialize

def switch_to_plugin(self, force_focus=False):
"""
Switch to plugin and define if focus should be given or not.
Expand Down
2 changes: 1 addition & 1 deletion spyder/plugins/breakpoints/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def on_initialize(self):
self.create_action(
BreakpointsActions.ListBreakpoints,
_("List breakpoints"),
triggered=lambda: self.switch_to_plugin(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of calling this directly, please emit sig_switch_to_plugin_requested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't work because sig_switch_to_plugin_requested is connected to MainWindow.switch_to_plugin not to SpyderDockablePlugin.switch_to_plugin

triggered=self.switch_to_plugin,
icon=self.get_icon(),
)

Expand Down
6 changes: 2 additions & 4 deletions spyder/plugins/completion/providers/kite/widgets/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,8 @@ def __init__(self, parent):
self.setLayout(general_layout)

# Signals
self._progress_filter.sig_hover_enter.connect(
lambda: self.cancel_button.show())
self._progress_filter.sig_hover_leave.connect(
lambda: self.cancel_button.hide())
self._progress_filter.sig_hover_enter.connect(self.cancel_button.show)
self._progress_filter.sig_hover_leave.connect(self.cancel_button.hide)

def update_installation_status(self, status):
"""Update installation status (downloading, installing, finished)."""
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/console/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,12 @@ def __init__(self, parent, history_filename, profile=False, initial_message=None

def create_shortcuts(self):
array_inline = CONF.config_shortcut(
lambda: self.enter_array_inline(),
self.enter_array_inline,
context='array_builder',
name='enter array inline',
parent=self)
array_table = CONF.config_shortcut(
lambda: self.enter_array_table(),
self.enter_array_table,
context='array_builder',
name='enter array table',
parent=self)
Expand Down
11 changes: 5 additions & 6 deletions spyder/plugins/editor/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,8 @@ def register_plugin(self):
self.switcher_manager = EditorSwitcherManager(
self,
self.main.switcher,
lambda: self.get_current_editor(),
lambda: self.get_current_editorstack(),
self.get_current_editor,
self.get_current_editorstack,
section=self.get_plugin_title())

def update_source_menu(self, options, **kwargs):
Expand Down Expand Up @@ -1573,8 +1573,7 @@ def register_editorstack(self, editorstack):
editorstack.run_cell_in_ipyclient.connect(self.run_cell_in_ipyclient)
editorstack.debug_cell_in_ipyclient.connect(
self.debug_cell_in_ipyclient)
editorstack.update_plugin_title.connect(
lambda: self.sig_update_plugin_title.emit())
editorstack.update_plugin_title.connect(self.sig_update_plugin_title)
editorstack.editor_focus_changed.connect(self.save_focused_editorstack)
editorstack.editor_focus_changed.connect(self.main.plugin_focus_changed)
editorstack.editor_focus_changed.connect(self.sig_editor_focus_changed)
Expand All @@ -1599,9 +1598,9 @@ def register_editorstack(self, editorstack):
editorstack.sig_perform_completion_request.connect(
self.send_completion_request)
editorstack.todo_results_changed.connect(self.todo_results_changed)
editorstack.update_code_analysis_actions.connect(
editorstack.sig_update_code_analysis_actions.connect(
self.update_code_analysis_actions)
editorstack.update_code_analysis_actions.connect(
editorstack.sig_update_code_analysis_actions.connect(
self.update_todo_actions)
editorstack.refresh_file_dependent_actions.connect(
self.refresh_file_dependent_actions)
Expand Down
12 changes: 6 additions & 6 deletions spyder/plugins/editor/widgets/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class CodeEditor(TextEditBaseWidget):
sig_filename_changed = Signal(str)
sig_bookmarks_changed = Signal()
go_to_definition = Signal(str, int, int)
sig_show_object_info = Signal(int)
sig_show_object_info = Signal(bool)
sig_run_selection = Signal()
sig_run_to_line = Signal()
sig_run_from_line = Signal()
Expand Down Expand Up @@ -2324,8 +2324,7 @@ def intelligent_backtab(self):
elif self.in_comment_or_string():
self.unindent()
elif leading_text[-1] in '(,' or leading_text.endswith(', '):
position = self.get_position('cursor')
self.show_object_info(position)
self.show_object_info()
else:
# if the line ends with any other character but comma
self.unindent()
Expand Down Expand Up @@ -2761,9 +2760,10 @@ def show_completion_object_info(self, name, signature):
force = True
self.sig_show_completion_object_info.emit(name, signature, force)

def show_object_info(self, position):
@Slot()
def show_object_info(self):
"""Trigger a calltip"""
self.sig_show_object_info.emit(position)
self.sig_show_object_info.emit(True)

# -----blank spaces
def set_blanks_enabled(self, state):
Expand Down Expand Up @@ -4423,7 +4423,7 @@ def setup_context_menu(self):
self, _("Inspect current object"),
icon=ima.icon('MessageBoxInformation'),
shortcut=CONF.get_shortcut('editor', 'inspect current object'),
triggered=self.sig_show_object_info.emit)
triggered=self.sig_show_object_info)

# Run actions
self.run_cell_action = create_action(
Expand Down
62 changes: 32 additions & 30 deletions spyder/plugins/editor/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class EditorStack(QWidget):
opened_files_list_changed = Signal()
active_languages_stats = Signal(set)
todo_results_changed = Signal()
update_code_analysis_actions = Signal()
sig_update_code_analysis_actions = Signal()
refresh_file_dependent_actions = Signal()
refresh_save_all_action = Signal()
sig_breakpoints_saved = Signal()
Expand Down Expand Up @@ -492,13 +492,13 @@ def create_shortcuts(self):
parent=self)

new_file = CONF.config_shortcut(
lambda: self.sig_new_file[()].emit(),
self.sig_new_file[()],
context='Editor',
name='New file',
parent=self)

open_file = CONF.config_shortcut(
lambda: self.plugin_load[()].emit(),
self.plugin_load[()],
context='Editor',
name='Open file',
parent=self)
Expand All @@ -516,7 +516,7 @@ def create_shortcuts(self):
parent=self)

save_as = CONF.config_shortcut(
lambda: self.sig_save_as.emit(),
self.sig_save_as,
context='Editor',
name='Save As',
parent=self)
Expand All @@ -528,43 +528,43 @@ def create_shortcuts(self):
parent=self)

prev_edit_pos = CONF.config_shortcut(
lambda: self.sig_prev_edit_pos.emit(),
self.sig_prev_edit_pos,
context="Editor",
name="Last edit location",
parent=self)

prev_cursor = CONF.config_shortcut(
lambda: self.sig_prev_cursor.emit(),
self.sig_prev_cursor,
context="Editor",
name="Previous cursor position",
parent=self)

next_cursor = CONF.config_shortcut(
lambda: self.sig_next_cursor.emit(),
self.sig_next_cursor,
context="Editor",
name="Next cursor position",
parent=self)

zoom_in_1 = CONF.config_shortcut(
lambda: self.zoom_in.emit(),
self.zoom_in,
context="Editor",
name="zoom in 1",
parent=self)

zoom_in_2 = CONF.config_shortcut(
lambda: self.zoom_in.emit(),
self.zoom_in,
context="Editor",
name="zoom in 2",
parent=self)

zoom_out = CONF.config_shortcut(
lambda: self.zoom_out.emit(),
self.zoom_out,
context="Editor",
name="zoom out",
parent=self)

zoom_reset = CONF.config_shortcut(
lambda: self.zoom_reset.emit(),
self.zoom_reset,
context="Editor",
name="zoom reset",
parent=self)
Expand Down Expand Up @@ -618,25 +618,25 @@ def create_shortcuts(self):
parent=self)

prev_warning = CONF.config_shortcut(
lambda: self.sig_prev_warning.emit(),
self.sig_prev_warning,
context="Editor",
name="Previous warning",
parent=self)

next_warning = CONF.config_shortcut(
lambda: self.sig_next_warning.emit(),
self.sig_next_warning,
context="Editor",
name="Next warning",
parent=self)

split_vertically = CONF.config_shortcut(
lambda: self.sig_split_vertically.emit(),
self.sig_split_vertically,
context="Editor",
name="split vertically",
parent=self)

split_horizontally = CONF.config_shortcut(
lambda: self.sig_split_horizontally.emit(),
self.sig_split_horizontally,
context="Editor",
name="split horizontally",
parent=self)
Expand Down Expand Up @@ -820,7 +820,7 @@ def open_switcher_dlg(self, initial_text=''):
self.switcher_manager = EditorSwitcherManager(
self.get_plugin(),
self.switcher_dlg,
lambda: self.get_current_editor(),
self.get_current_editor,
lambda: self,
section=self.get_plugin_title())

Expand Down Expand Up @@ -879,13 +879,15 @@ def set_bookmark(self, slot_num):
editor = self.get_current_editor()
editor.add_bookmark(slot_num)

def inspect_current_object(self, pos=None):
@Slot()
@Slot(bool)
def inspect_current_object(self, clicked=False):
"""Inspect current object in the Help plugin"""
editor = self.get_current_editor()
editor.sig_display_object_info.connect(self.display_help)
cursor = None
offset = editor.get_position('cursor')
if pos:
if clicked:
cursor = editor.get_last_hover_cursor()
if cursor:
offset = cursor.position()
Expand All @@ -894,7 +896,7 @@ def inspect_current_object(self, pos=None):

line, col = editor.get_cursor_line_column(cursor)
editor.request_hover(line, col, offset,
show_hint=False, clicked=bool(pos))
show_hint=False, clicked=clicked)

@Slot(str, bool)
def display_help(self, help_text, clicked):
Expand Down Expand Up @@ -1439,7 +1441,7 @@ def __get_split_actions(self):
_("Split vertically"),
icon=ima.icon('versplit'),
tip=_("Split vertically this editor window"),
triggered=lambda: self.sig_split_vertically.emit(),
triggered=self.sig_split_vertically,
shortcut=CONF.get_shortcut(context='Editor',
name='split vertically'),
context=Qt.WidgetShortcut)
Expand All @@ -1449,7 +1451,7 @@ def __get_split_actions(self):
_("Split horizontally"),
icon=ima.icon('horsplit'),
tip=_("Split horizontally this editor window"),
triggered=lambda: self.sig_split_horizontally.emit(),
triggered=self.sig_split_horizontally,
shortcut=CONF.get_shortcut(context='Editor',
name='split horizontally'),
context=Qt.WidgetShortcut)
Expand Down Expand Up @@ -1664,7 +1666,7 @@ def close_file(self, index=None, force=False):
self.sig_close_file.emit(str(id(self)), filename)

self.opened_files_list_changed.emit()
self.update_code_analysis_actions.emit()
self.sig_update_code_analysis_actions.emit()
self.refresh_file_dependent_actions.emit()
self.update_plugin_title.emit()

Expand Down Expand Up @@ -2407,7 +2409,7 @@ def refresh(self, index=None):
editor = finfo.editor
editor.setFocus()
self._refresh_outlineexplorer(index, update=False)
self.update_code_analysis_actions.emit()
self.sig_update_code_analysis_actions.emit()
self.__refresh_statusbar(index)
self.__refresh_readonly(index)
self.__check_file_status(index)
Expand Down Expand Up @@ -2512,8 +2514,7 @@ def create_new_editor(self, fname, enc, txt, set_current, new=False,
self.add_to_data(finfo, set_current, add_where)
finfo.sig_send_to_help.connect(self.send_to_help)
finfo.sig_show_object_info.connect(self.inspect_current_object)
finfo.todo_results_changed.connect(
lambda: self.todo_results_changed.emit())
finfo.todo_results_changed.connect(self.todo_results_changed)
finfo.edit_goto.connect(lambda fname, lineno, name:
self.edit_goto.emit(fname, lineno, name))
finfo.sig_save_bookmarks.connect(lambda s1, s2:
Expand All @@ -2528,7 +2529,7 @@ def create_new_editor(self, fname, enc, txt, set_current, new=False,
editor.sig_new_file.connect(self.sig_new_file)
editor.sig_breakpoints_saved.connect(self.sig_breakpoints_saved)
editor.sig_process_code_analysis.connect(
lambda: self.update_code_analysis_actions.emit())
self.sig_update_code_analysis_actions)
editor.sig_refresh_formatting.connect(self.sig_refresh_formatting)
language = get_file_language(fname, txt)
editor.setup_editor(
Expand Down Expand Up @@ -2599,9 +2600,9 @@ def perform_completion_request(lang, method, params):
lambda state: self.modification_changed(
state, editor_id=id(editor)))
editor.focus_in.connect(self.focus_changed)
editor.zoom_in.connect(lambda: self.zoom_in.emit())
editor.zoom_out.connect(lambda: self.zoom_out.emit())
editor.zoom_reset.connect(lambda: self.zoom_reset.emit())
editor.zoom_in.connect(self.zoom_in)
editor.zoom_out.connect(self.zoom_out)
editor.zoom_reset.connect(self.zoom_reset)
editor.sig_eol_chars_changed.connect(
lambda eol_chars: self.refresh_eol_chars(eol_chars))
editor.sig_next_cursor.connect(self.sig_next_cursor)
Expand Down Expand Up @@ -3037,7 +3038,7 @@ def __init__(self, parent, plugin, menu_actions, first=False,
self.register_editorstack_cb(self.editorstack)
if not first:
self.plugin.clone_editorstack(editorstack=self.editorstack)
self.editorstack.destroyed.connect(lambda: self.editorstack_closed())
self.editorstack.destroyed.connect(self.editorstack_closed)
self.editorstack.sig_split_vertically.connect(
lambda: self.split(orientation=Qt.Vertical))
self.editorstack.sig_split_horizontally.connect(
Expand All @@ -3062,6 +3063,7 @@ def __give_focus_to_remaining_editor(self):
if focus_widget is not None:
focus_widget.setFocus()

@Slot()
def editorstack_closed(self):
try:
logger.debug("method 'editorstack_closed':")
Expand Down
2 changes: 1 addition & 1 deletion spyder/plugins/editor/widgets/editorstack_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class FileInfo(QObject):
edit_goto = Signal(str, int, str)
sig_send_to_help = Signal(str, str, bool)
sig_filename_changed = Signal(str)
sig_show_object_info = Signal(int)
sig_show_object_info = Signal(bool)
sig_show_completion_object_info = Signal(str, str)

def __init__(self, filename, encoding, editor, new, threadmanager):
Expand Down
Loading