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: Add context menu entries for collections to a toolbar (Variable Explorer) #17473

Merged
merged 14 commits into from
Apr 15, 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
2 changes: 2 additions & 0 deletions spyder/utils/icon_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def __init__(self):
'rename': [('mdi.rename-box',), {'color': self.MAIN_FG_COLOR}],
'move': [('mdi.file-move',), {'color': self.MAIN_FG_COLOR}],
'edit_add': [('mdi.plus',), {'color': self.MAIN_FG_COLOR}],
'collapse_column': [('mdi.arrow-collapse-horizontal',), {'color': self.MAIN_FG_COLOR}],
'collapse_row': [('mdi.arrow-collapse-vertical',), {'color': self.MAIN_FG_COLOR}],
'edit_remove': [('mdi.minus',), {'color': self.MAIN_FG_COLOR}],
'browse_tab': [('mdi.tab',), {'color': self.MAIN_FG_COLOR}],
'filelist': [('mdi.view-list',), {'color': self.MAIN_FG_COLOR}],
Expand Down
38 changes: 28 additions & 10 deletions spyder/widgets/collectionseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from spyder.widgets.helperwidgets import CustomSortFilterProxy
from spyder.plugins.variableexplorer.widgets.basedialog import BaseDialog
from spyder.utils.palette import SpyderPalette
from spyder.api.widgets.toolbars import SpyderToolbar


# Maximum length of a serialized variable to be set in the kernel
Expand Down Expand Up @@ -585,6 +586,7 @@ def __init__(self, parent):

self.array_filename = None
self.menu = None
self.menu_actions = []
self.empty_ws_menu = None
self.paste_action = None
self.copy_action = None
Expand Down Expand Up @@ -619,14 +621,17 @@ def setup_table(self):
# Sorting columns
self.setSortingEnabled(True)
self.sortByColumn(0, Qt.AscendingOrder)
self.selectionModel().selectionChanged.connect(self.refresh_menu)

def setup_menu(self):
"""Setup context menu"""
resize_action = create_action(self, _("Resize rows to contents"),
icon=ima.icon('collapse_row'),
triggered=self.resizeRowsToContents)
resize_columns_action = create_action(
self,
_("Resize columns to contents"),
icon=ima.icon('collapse_column'),
triggered=self.resize_column_contents)
self.paste_action = create_action(self, _("Paste"),
icon=ima.icon('editpaste'),
Expand Down Expand Up @@ -683,15 +688,16 @@ def setup_menu(self):
icon=ima.icon('outline_explorer'),
triggered=self.view_item)
menu = QMenu(self)
menu_actions = [self.edit_action, self.plot_action, self.hist_action,
self.imshow_action, self.save_array_action,
self.insert_action,
self.insert_action_above, self.insert_action_below,
self.remove_action, self.copy_action,
self.paste_action, self.view_action,
None, self.rename_action, self.duplicate_action,
None, resize_action, resize_columns_action]
add_actions(menu, menu_actions)
self.menu_actions = [self.edit_action, self.plot_action,
self.hist_action, self.imshow_action,
self.save_array_action, self.insert_action,
self.insert_action_above,
self.insert_action_below,
self.remove_action, self.copy_action,
self.paste_action, self.view_action,
None, self.rename_action, self.duplicate_action,
None, resize_action, resize_columns_action]
add_actions(menu, self.menu_actions)
self.empty_ws_menu = QMenu(self)
add_actions(
self.empty_ws_menu,
Expand Down Expand Up @@ -1184,7 +1190,6 @@ def __init__(self, parent, data, readonly=False, title="",

self.setup_table()
self.menu = self.setup_menu()

if isinstance(data, set):
self.horizontalHeader().hideSection(0)

Expand Down Expand Up @@ -1312,7 +1317,16 @@ def __init__(self, parent, data, readonly=False, title="", remote=False):
else:
self.editor = CollectionsEditorTableView(self, data, readonly,
title)
toolbar = SpyderToolbar(parent=None, title='Editor toolbar')

for item in self.editor.menu_actions:
if item is not None:
toolbar.addAction(item)

dalthviz marked this conversation as resolved.
Show resolved Hide resolved
# Update the toolbar actions state
self.editor.refresh_menu()
layout = QVBoxLayout()
layout.addWidget(toolbar)
layout.addWidget(self.editor)
self.setLayout(layout)

Expand Down Expand Up @@ -1574,6 +1588,10 @@ def setup_menu(self):
menu = BaseTableView.setup_menu(self)
return menu

def refresh_menu(self):
if self.var_properties:
super().refresh_menu()

def set_regex(self, regex=None, reset=False):
"""Update the regex text for the variable finder."""
if reset or self.finder is None or not self.finder.text():
Expand Down