Skip to content

Commit

Permalink
Fix window.py Editor widget test
Browse files Browse the repository at this point in the history
  • Loading branch information
dalthviz committed Sep 20, 2023
1 parent d4accf7 commit bc4b18f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
6 changes: 3 additions & 3 deletions spyder/plugins/editor/widgets/editorstack/editorstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def get_plugin(self):
"""Get the plugin of the parent widget."""
# Needed for the editor stack to use its own switcher instance.
# See spyder-ide/spyder#10684.
return self.parent().plugin
return self.parent().main_widget

def get_plugin_title(self):
"""Get the plugin title of the parent widget."""
Expand Down Expand Up @@ -1249,7 +1249,7 @@ def __setup_menu(self):
# ------ Hor/Ver splitting
def __get_split_actions(self):
if self.parent() is not None:
plugin = self.parent().plugin
plugin = self.parent().main_widget
else:
plugin = None

Expand Down Expand Up @@ -1470,7 +1470,7 @@ def close_file(self, index=None, force=False):
else:
new_index = current_index

can_close_file = self.parent().plugin.can_close_file(
can_close_file = self.parent().main_widget.can_close_file(
self.data[index].filename) if self.parent() else True
is_ok = (force or self.save_if_changed(cancelable=True, index=index)
and can_close_file)
Expand Down
7 changes: 5 additions & 2 deletions spyder/plugins/editor/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,9 @@ def update_actions(self):

# ---- Private API
# ------------------------------------------------------------------------
def get_color_scheme(self):
return self._plugin.get_color_scheme()

def restore_scrollbar_position(self):
"""Restoring scrollbar position after main window is visible"""
# Widget is now visible, we may center cursor on top level editor:
Expand Down Expand Up @@ -2271,7 +2274,7 @@ def update_source_menu(self, options, **kwargs):
def update_font(self, font):
"""Update font from Preferences"""
self._font = font
color_scheme = self._plugin.get_color_scheme() # TODO: Should be available for the main_widgets too?
color_scheme = self.get_color_scheme() # TODO: Should be available for the main_widgets too?
for editorstack in self.editorstacks:
editorstack.set_default_font(font, color_scheme)
completion_size = self.get_conf('completion/size', section='main')
Expand Down Expand Up @@ -2551,7 +2554,7 @@ def register_editorstack(self, editorstack):
editorstack.set_hover_hints_enabled(hover_hints)
editorstack.set_format_on_save(format_on_save)
editorstack.set_edgeline_columns(edge_line_columns)
color_scheme = self._plugin.get_color_scheme() # TODO: Should be available for the main_widgets too?
color_scheme = self.get_color_scheme() # TODO: Should be available for the main_widgets too?
editorstack.set_default_font(self._font, color_scheme)

editorstack.starting_long_process.connect(self.starting_long_process)
Expand Down
28 changes: 14 additions & 14 deletions spyder/plugins/editor/widgets/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@
class EditorSplitter(QSplitter):
"""QSplitter for editor windows."""

def __init__(self, parent, plugin, menu_actions, first=False,
def __init__(self, parent, main_widget, menu_actions, first=False,
register_editorstack_cb=None, unregister_editorstack_cb=None,
use_switcher=True):
"""Create a splitter for dividing an editor window into panels.
Adds a new EditorStack instance to this splitter. If it's not
the first splitter, clones the current EditorStack from the plugin.
the first splitter, clones the current EditorStack from the EditorMainWidget.
Args:
parent: Parent widget.
plugin: Plugin this widget belongs to.
main_widget: PluginMainWidget this widget belongs to.
menu_actions: QActions to include from the parent.
first: Boolean if this is the first splitter in the editor.
register_editorstack_cb: Callback to register the EditorStack.
Defaults to plugin.register_editorstack() to
register the EditorStack with the Editor plugin.
Defaults to main_widget.register_editorstack() to
register the EditorStack with the EditorMainWidget.
unregister_editorstack_cb: Callback to unregister the EditorStack.
Defaults to plugin.unregister_editorstack() to
unregister the EditorStack with the Editor plugin.
Defaults to main_widget.unregister_editorstack() to
unregister the EditorStack with the EditorMainWidget.
"""

QSplitter.__init__(self, parent)
Expand All @@ -60,20 +60,20 @@ def __init__(self, parent, plugin, menu_actions, first=False,
self.toolbar_list = None
self.menu_list = None

self.plugin = plugin
self.main_widget = main_widget

if register_editorstack_cb is None:
register_editorstack_cb = self.plugin.register_editorstack
register_editorstack_cb = self.main_widget.register_editorstack
self.register_editorstack_cb = register_editorstack_cb
if unregister_editorstack_cb is None:
unregister_editorstack_cb = self.plugin.unregister_editorstack
unregister_editorstack_cb = self.main_widget.unregister_editorstack
self.unregister_editorstack_cb = unregister_editorstack_cb

self.menu_actions = menu_actions
self.editorstack = EditorStack(self, menu_actions, use_switcher)
self.register_editorstack_cb(self.editorstack)
if not first:
self.plugin.clone_editorstack(editorstack=self.editorstack)
self.main_widget.clone_editorstack(editorstack=self.editorstack)
self.editorstack.destroyed.connect(self.editorstack_closed)
self.editorstack.sig_split_vertically.connect(
lambda: self.split(orientation=Qt.Vertical))
Expand All @@ -82,7 +82,7 @@ def __init__(self, parent, plugin, menu_actions, first=False,
self.addWidget(self.editorstack)

if not running_under_pytest():
self.editorstack.set_color_scheme(plugin._plugin.get_color_scheme()) # TODO: Color scheme handling?
self.editorstack.set_color_scheme(main_widget.get_color_scheme()) # TODO: Color scheme handling?

self.setStyleSheet(self._stylesheet)

Expand All @@ -95,7 +95,7 @@ def closeEvent(self, event):
QSplitter.closeEvent(self, event)

def __give_focus_to_remaining_editor(self):
focus_widget = self.plugin.get_focus_widget()
focus_widget = self.main_widget.get_focus_widget()
if focus_widget is not None:
focus_widget.setFocus()

Expand Down Expand Up @@ -154,7 +154,7 @@ def split(self, orientation=Qt.Vertical):
self.editorstack.set_orientation(orientation)
editorsplitter = EditorSplitter(
self.parent(),
self.plugin,
self.main_widget,
self.menu_actions,
register_editorstack_cb=self.register_editorstack_cb,
unregister_editorstack_cb=self.unregister_editorstack_cb
Expand Down
22 changes: 12 additions & 10 deletions spyder/plugins/editor/widgets/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,17 @@ def set_layout_settings(self, settings):
self.editorwidget.editorsplitter.set_layout_settings(splitsettings)


class EditorPluginExample(QSplitter):
class EditorMainWidgetExample(QSplitter):
def __init__(self):
QSplitter.__init__(self)

self._dock_action = None
self._undock_action = None
self._close_plugin_action = None
self._undocked_window = None
self._lock_unlock_action = None
self._plugin = None

self.dock_action = None
self.undock_action = None
self.close_action = None
self.windowwidget = None
self.lock_unlock_action = None
menu_actions = []

self.editorstacks = []
Expand Down Expand Up @@ -490,9 +492,9 @@ def file_renamed_in_data_in_editorstack(
if str(id(editorstack)) != editorstack_id_str:
editorstack.rename_in_data(original_filename, filename)

def register_widget_shortcuts(self, widget):
"""Fake!"""
pass
# def register_widget_shortcuts(self, widget):
# """Fake!"""
# pass

def get_color_scheme(self):
pass
Expand All @@ -505,7 +507,7 @@ def test():
spyder_dir = get_module_path('spyder')
app = qapplication(test_time=8)

test = EditorPluginExample()
test = EditorMainWidgetExample()
test.resize(900, 700)
test.show()

Expand Down

0 comments on commit bc4b18f

Please sign in to comment.