Skip to content

Commit

Permalink
Initial code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
dalthviz committed Sep 21, 2023
1 parent bc4b18f commit 6642e17
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 1,031 deletions.
3 changes: 2 additions & 1 deletion spyder/api/widgets/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ def _update_action_state(self, action_name, value):
# other it refers to a section of the configuration (or the widget
# name where it is applied).
def create_action(self, name, text, icon=None, icon_text='', tip=None,
toggled=None, triggered=None, data=None, shortcut_context=None,
toggled=None, triggered=None, data=None,
shortcut_context=None,
context=Qt.WidgetWithChildrenShortcut, initial=None,
register_shortcut=False, section=None, option=None,
parent=None, register_action=True, overwrite=False,
Expand Down
87 changes: 47 additions & 40 deletions spyder/plugins/editor/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
SelectionContextModificator, ExtraAction)
from spyder.plugins.editor.confpage import EditorConfigPage
from spyder.plugins.editor.widgets.main_widget import (
EditorMainWidget,
EditorWidgetActions,
EditorWidgetMenus
EditorMainWidget
)
from spyder.plugins.mainmenu.api import (
ApplicationMenus,
Expand Down Expand Up @@ -174,7 +172,7 @@ def get_description():
@staticmethod
def get_icon():
return ima.icon('edit')

def on_initialize(self):
widget = self.get_widget()

Expand Down Expand Up @@ -250,19 +248,25 @@ def on_run_available(self):
run = self.get_plugin(Plugins.Run)

widget.sig_editor_focus_changed_uuid.connect(
run.switch_focused_run_configuration)

run.switch_focused_run_configuration
)
widget.sig_register_run_configuration_provider_requested.connect(
lambda supported_extension:
run.register_run_configuration_provider(self.NAME, supported_extension)
lambda supported_extension:
run.register_run_configuration_provider(
self.NAME, supported_extension
)
)
widget.sig_deregister_run_configuration_provider_requested.connect(
lambda unsupported_extension:
run.deregister_run_configuration_provider(self.NAME, unsupported_extension)
lambda unsupported_extension:
run.deregister_run_configuration_provider(
self.NAME, unsupported_extension
)
)
run.register_run_configuration_provider(
self.NAME, widget.supported_run_extensions)
self.NAME, widget.supported_run_extensions
)

# Buttons creation
run.create_run_button(
RunContext.Cell,
_("Run cell"),
Expand All @@ -273,7 +277,6 @@ def on_run_available(self):
add_to_toolbar=True,
add_to_menu=True
)

run.create_run_button(
RunContext.Cell,
_("Run cell and advance"),
Expand All @@ -285,7 +288,6 @@ def on_run_available(self):
add_to_menu=True,
extra_action_name=ExtraAction.Advance
)

run.create_run_button(
RunContext.Cell,
_("Re-run last cell"),
Expand All @@ -295,7 +297,6 @@ def on_run_available(self):
add_to_menu=True,
re_run=True
)

run.create_run_button(
RunContext.Selection,
_("Run &selection or current line"),
Expand All @@ -307,7 +308,6 @@ def on_run_available(self):
add_to_menu=True,
extra_action_name=ExtraAction.Advance,
)

run.create_run_button(
RunContext.Selection,
_("Run &to line"),
Expand All @@ -318,7 +318,6 @@ def on_run_available(self):
add_to_menu=True,
context_modificator=SelectionContextModificator.ToLine
)

run.create_run_button(
RunContext.Selection,
_("Run &from line"),
Expand Down Expand Up @@ -392,7 +391,7 @@ def on_mainmenu_available(self):
menu_id=ApplicationMenus.File,
section=FileMenuSections.Save,
before_section=FileMenuSections.Print
)
)
# Open section
open_actions = [
widget.open_action,
Expand All @@ -413,6 +412,7 @@ def on_mainmenu_available(self):
section=FileMenuSections.New,
before_section=FileMenuSections.Open
)

# ---- Edit menu ----
edit_menu = mainmenu.get_application_menu(ApplicationMenus.Edit)
edit_menu.aboutToShow.connect(widget.update_edit_menu)
Expand Down Expand Up @@ -442,7 +442,7 @@ def on_mainmenu_available(self):
menu_id=ApplicationMenus.Edit,
section=EditMenuSections.Editor
)

# ---- Search menu ----
search_menu = mainmenu.get_application_menu(ApplicationMenus.Search)
search_menu.aboutToShow.connect(widget.update_search_menu)
Expand All @@ -454,7 +454,7 @@ def on_mainmenu_available(self):
section=SearchMenuSections.FindInText,
before_section=SearchMenuSections.FindInFiles
)

# ---- Source menu ----
source_menu = mainmenu.get_application_menu(
ApplicationMenus.Source
Expand Down Expand Up @@ -521,7 +521,7 @@ def on_mainmenu_teardown(self):
def on_toolbar_available(self):
widget = self.get_widget()
toolbar = self.get_plugin(Plugins.Toolbar)
# TODO:
# TODO: Check changes to toolbar plugin
file_toolbar_actions = [
widget.new_action,
widget.open_action,
Expand All @@ -538,8 +538,8 @@ def on_toolbar_available(self):
@on_plugin_teardown(plugin=Plugins.Toolbar)
def on_toolbar_teardown(self):
toolbar = self.get_plugin(Plugins.Toolbar)
# TODO:
# TODO: Check toolbar teardown

@on_plugin_available(plugin=Plugins.Completions)
def on_completions_available(self):
widget = self.get_widget()
Expand Down Expand Up @@ -570,9 +570,8 @@ def on_outlineexplorer_available(self):
widget = self.get_widget()
outline = self.get_plugin(Plugins.OutlineExplorer)
outline_widget = outline.get_widget()

widget.set_outlineexplorer(outline_widget)

# TODO: Should the above be done from the Outline Explorer plugin
# as done with the console/internal console plugin?
outline_widget.edit_goto.connect(
Expand All @@ -592,7 +591,7 @@ def on_outlineexplorer_available(self):
@on_plugin_teardown(plugin=Plugins.OutlineExplorer)
def on_outlinexplorer_teardown(self):
outline = self.get_plugin(Plugins.OutlineExplorer)
# TODO:
# TODO: Check outline teardown

@on_plugin_available(plugin=Plugins.IPythonConsole)
def on_ipyconsole_available(self):
Expand All @@ -615,7 +614,7 @@ def on_ipyconsole_available(self):
@on_plugin_teardown(plugin=Plugins.IPythonConsole)
def on_ipyconsole_teardown(self):
ipyconsole = self.get_plugin(Plugins.IPythonConsole)
# TODO:
# TODO: Check ipython consle teardown

@on_plugin_available(plugin=Plugins.Switcher)
def on_switcher_available(self):
Expand All @@ -625,13 +624,13 @@ def on_switcher_available(self):
@on_plugin_teardown(plugin=Plugins.Switcher)
def on_switcher_teardown(self):
switcher = self.get_plugin(Plugins.Switcher)
# TODO:
# TODO: Check switcher teardown

@on_plugin_available(plugin=Plugins.Projects)
def on_projects_available(self):
projects = self.get_plugin(Plugins.Projects)
# TODO: See handling of active project path done by IPython console

@on_plugin_teardown(plugin=Plugins.Projects)
def on_projects_teardown(self):
widget = self.get_widget()
Expand All @@ -651,7 +650,7 @@ def on_mainwindow_visible(self):
outline = self.get_plugin(Plugins.OutlineExplorer, error=False)
widget.setup_other_windows(self._main, outline)
widget.restore_scrollbar_position()
# TODO: Something else?. Move setup_other_windows to plugin
# TODO: Something else?. Move setup_other_windows to plugin?

def on_close(self, cancellable=True):
# TODO: See `closing_plugin`
Expand Down Expand Up @@ -702,38 +701,46 @@ def load(self, *args, **kwargs):
def new(self, *args, **kwargs):
return self.get_widget().new(*args, **kwargs)

def removed(self, *args, **kwargs): # explorer plugin
def removed(self, *args, **kwargs): # explorer plugin
return self.get_widget().removed(*args, **kwargs)

def removed_tree(self, *args, **kwargs): # explorer plugin
def removed_tree(self, *args, **kwargs): # explorer plugin
return self.get_widget().removed_tree(*args, **kwargs)

def renamed(self, *args, **kwargs): # explorer plugin
def renamed(self, *args, **kwargs): # explorer plugin
return self.get_widget().renamed(*args, **kwargs)

def renamed_tree(self, *args, **kwargs): # explorer plugin
def renamed_tree(self, *args, **kwargs): # explorer plugin
return self.get_widget().renamed_tree(*args, **kwargs)

def add_supported_run_configuration(self, *args, **kwargs): # external console plugin
return self.get_widget().add_supported_run_configuration(*args, **kwargs)
def add_supported_run_configuration(self, *args, **kwargs):
# external console plugin
return self.get_widget().add_supported_run_configuration(
*args, **kwargs
)

def save_open_files(self, *args, **kwargs): # projects plugin
def save_open_files(self, *args, **kwargs): # projects plugin
return self.get_widget().save_open_files(*args, **kwargs)

def get_current_editor(self, *args, **kwargs): # debugger plugin
def get_current_editor(self, *args, **kwargs): # debugger plugin
return self.get_widget().get_current_editor(*args, **kwargs)
def setup_open_files(self, *args, **kwargs): # mainwindow?

def setup_open_files(self, *args, **kwargs): # mainwindow?
return self.get_widget().setup_open_files(*args, **kwargs)

def save(self, *args, **kwargs):
return self.get_widget().save(*args, **kwargs)

# ---- Private API
# ------------------------------------------------------------------------
# ---- Run related methods
# TODO: Is there other way to do this?
def register_run_configuration_metadata(self, metadata):
run = self.get_plugin(Plugins.Run, error=False)
if run is not None:
run.register_run_configuration_metadata(self.get_widget(), metadata)
run.register_run_configuration_metadata(
self.get_widget(), metadata
)

def deregister_run_configuration_metadata(self, file_id):
run = self.get_plugin(Plugins.Run, error=False)
Expand Down
5 changes: 4 additions & 1 deletion spyder/plugins/editor/utils/autosave.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ def try_recover_from_autosave(self):
the pid files.
"""
files_to_recover, pidfiles = self.get_files_to_recover()
parent = self.editor if running_under_pytest() else self.editor._plugin.main
parent = (
self.editor if running_under_pytest() else
self.editor._plugin.main
)
dialog = RecoveryDialog(files_to_recover, parent=parent)
dialog.exec_if_nonempty()
self.recover_files_to_open = dialog.files_to_open[:]
Expand Down
6 changes: 4 additions & 2 deletions spyder/plugins/editor/utils/switcher_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def handle_switcher_modes(self, mode):
elif mode == self.LINE_MODE:
self.create_line_switcher()
elif mode == self.FILES_MODE:
# Each plugin/main_widget that wants to attach to the switcher should do this?
# Each plugin/main_widget that wants to attach to the switcher
# should do this?
self.create_editor_switcher()

def create_editor_switcher(self):
Expand Down Expand Up @@ -190,7 +191,8 @@ def handle_switcher_selection(self, item, mode, search_text):
elif mode == ':':
self.line_switcher_handler(data, search_text)
elif mode == '':
# Each plugin/main_widget that wants to attach to the switcher should do this?
# Each plugin/main_widget that wants to attach to the switcher
# should do this?
if item.get_section() == self._section:
self.editor_switcher_handler(data)
self._main_widget.switch_to_main_widget()
Expand Down
Loading

0 comments on commit 6642e17

Please sign in to comment.