Skip to content

Feature: add edit_parameters widget to toolbar for GUI backends #17105

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

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9d10737
Add new widget
leungbyr Mar 25, 2020
3095496
Implement changing axis lim and labels
leungbyr Mar 26, 2020
aff0de2
Implement tab switching
leungbyr Mar 26, 2020
a12d6c2
Implement Dropdown widget
leungbyr Mar 27, 2020
759e157
feat: AxesTool added to wx backend
Mar 30, 2020
84f2f39
feat: added helper function for init toolfig
Mar 31, 2020
379a054
feat: AxesTool added to tk backend
Mar 31, 2020
67b381a
Dropdown now retains latest option at top and has hover effects
leungbyr Apr 1, 2020
0039675
Add label to dropdown
leungbyr Apr 3, 2020
a2422bb
added curves tab implementated but buttons still need to be worked on
KJBBato Apr 4, 2020
94bdf01
Fix canvas not updating issue
leungbyr Apr 5, 2020
afe51ad
Make dropdown scrollable
leungbyr Apr 7, 2020
104b998
Update widgets.py
evannwang Apr 7, 2020
6705d1e
Update widgets.py
evannwang Apr 7, 2020
7a1851e
Fixed line color, face color, edge color and removed some comments
KJBBato Apr 7, 2020
089b881
feat: integrated in backend bases
Apr 7, 2020
2f7a403
Update widgets.py
evannwang Apr 7, 2020
3cbcf00
option labels clear
KJBBato Apr 7, 2020
abb908d
removed confirm and cancel
KJBBato Apr 7, 2020
815ecf5
style: removed comments and whitespace
Apr 7, 2020
0003871
Throw error on invalid args to Dropdown
leungbyr Apr 8, 2020
669375e
Documentation for Axestool and Dropdown
evannwang Apr 8, 2020
dee1107
Fix minor bug with switching tabs with dropdown open
leungbyr Apr 8, 2020
484e950
Update widgets.py
evannwang Apr 7, 2020
7e19ce7
Update widgets.py
evannwang Apr 7, 2020
b63ae9e
Fixed line color, face color, edge color and removed some comments
KJBBato Apr 7, 2020
05bf045
Update widgets.py
evannwang Apr 7, 2020
9039631
option labels clear
KJBBato Apr 7, 2020
7c700bb
removed confirm and cancel
KJBBato Apr 7, 2020
4a97188
style: removed comments and whitespace
Apr 7, 2020
752df05
Throw error on invalid args to Dropdown
leungbyr Apr 8, 2020
f744adf
Documentation for Axestool and Dropdown
evannwang Apr 8, 2020
da82639
style: removed whitespace
Apr 12, 2020
59b0c12
style: removed extra whitespace
Apr 17, 2020
a0cc284
style: removed comments
Apr 17, 2020
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
3 changes: 2 additions & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2670,7 +2670,8 @@ class NavigationToolbar2:
('Pan', 'Pan axes with left mouse, zoom with right', 'move', 'pan'),
('Zoom', 'Zoom to rectangle', 'zoom_to_rect', 'zoom'),
('Subplots', 'Configure subplots', 'subplots', 'configure_subplots'),
(None, None, None, None),
("Customize", "Edit axis, curve and image parameters",
"editor_options", "edit_parameters"),
('Save', 'Save the figure', 'filesave', 'save_figure'),
)

Expand Down
12 changes: 11 additions & 1 deletion lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from matplotlib.backend_managers import ToolManager
from matplotlib._pylab_helpers import Gcf
from matplotlib.figure import Figure
from matplotlib.widgets import SubplotTool
from matplotlib.widgets import SubplotTool, AxesTool
from . import _tkagg

try:
Expand Down Expand Up @@ -585,6 +585,16 @@ def configure_subplots(self):
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
window.grab_set()

def edit_parameters(self):
toolfig = Figure(figsize=(4, 5))
window = tk.Toplevel()
canvas = type(self.canvas)(toolfig, master=window)
toolfig.subplots_adjust(top=0.9)
canvas.tool = AxesTool(self.canvas.figure, toolfig)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
window.grab_set()

def save_figure(self, *args):
filetypes = self.canvas.get_supported_filetypes().copy()
default_filetype = self.canvas.get_default_filetype()
Expand Down
24 changes: 17 additions & 7 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
StatusbarBase, TimerBase, ToolContainerBase, cursors)
from matplotlib.backend_managers import ToolManager
from matplotlib.figure import Figure
from matplotlib.widgets import SubplotTool
from matplotlib.widgets import SubplotTool, AxesTool

try:
import gi
Expand Down Expand Up @@ -565,12 +565,10 @@ def on_notify_filter(*args):
except Exception as e:
error_msg_gtk(str(e), parent=self)

def configure_subplots(self, button):
toolfig = Figure(figsize=(6, 3))
def _init_toolfig(self, title, size):
toolfig = Figure(figsize=size)
canvas = type(self.canvas)(toolfig)
toolfig.subplots_adjust(top=0.9)
# Need to keep a reference to the tool.
_tool = SubplotTool(self.canvas.figure, toolfig)
# toolfig.subplots_adjust(top=0.9)

w = int(toolfig.bbox.width)
h = int(toolfig.bbox.height)
Expand All @@ -582,7 +580,7 @@ def configure_subplots(self, button):
# we presumably already logged a message on the
# failure of the main plot, don't keep reporting
pass
window.set_title("Subplot Configuration Tool")
window.set_title(title)
window.set_default_size(w, h)
vbox = Gtk.Box()
vbox.set_property("orientation", Gtk.Orientation.VERTICAL)
Expand All @@ -592,6 +590,18 @@ def configure_subplots(self, button):
canvas.show()
vbox.pack_start(canvas, True, True, 0)
window.show()
return toolfig

def configure_subplots(self, button):
toolfig = self._init_toolfig("Subplot Configuration Tool", (6, 3))
toolfig.subplots_adjust(top=0.9)
# Need to keep a reference to the tool.
_tool = SubplotTool(self.canvas.figure, toolfig)

def edit_parameters(self, button):
toolfig = self._init_toolfig("Figure options", (4, 5))
# Need to keep a reference to the tool.
_tool = AxesTool(self.canvas.figure, toolfig)

def set_history_buttons(self):
can_backward = self._nav_stack._pos > 0
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,12 @@ def set_window_title(self, title):
class NavigationToolbar2QT(NavigationToolbar2, QtWidgets.QToolBar):
message = QtCore.Signal(str)

toolitems = [*NavigationToolbar2.toolitems]
toolitems.insert(
# Add 'customize' action after 'subplots'
[name for name, *_ in toolitems].index("Subplots") + 1,
("Customize", "Edit axis, curve and image parameters",
"qt4_editor_options", "edit_parameters"))
# toolitems = [*NavigationToolbar2.toolitems]
# toolitems.insert(
# # Add 'customize' action after 'subplots'
# [name for name, *_ in toolitems].index("Subplots") + 1,
# ("Customize", "Edit axis, curve and image parameters",
# "qt4_editor_options", "edit_parameters"))

def __init__(self, canvas, parent, coordinates=True):
"""coordinates: should we show the coordinates on the right?"""
Expand Down
20 changes: 15 additions & 5 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from matplotlib.figure import Figure
from matplotlib.path import Path
from matplotlib.transforms import Affine2D
from matplotlib.widgets import SubplotTool
from matplotlib.widgets import SubplotTool, AxesTool

import wx

Expand Down Expand Up @@ -1167,12 +1167,12 @@ def pan(self, *args):
self.ToggleTool(self.wx_ids['Zoom'], False)
NavigationToolbar2.pan(self, *args)

def configure_subplots(self, *args):
def _init_toolfig(self, title, size):
global FigureManager # placates pyflakes: created by @_Backend.export
frame = wx.Frame(None, -1, "Configure subplots")
frame = wx.Frame(None, -1, title)
_set_frame_icon(frame)

toolfig = Figure((6, 3))
toolfig = Figure(size)
canvas = type(self.canvas)(frame, -1, toolfig)

# Create a figure manager to manage things
Expand All @@ -1184,8 +1184,18 @@ def configure_subplots(self, *args):
sizer.Add(canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
frame.SetSizer(sizer)
frame.Fit()
SubplotTool(self.canvas.figure, toolfig)
frame.Show()
return toolfig

def configure_subplots(self, *args):
# Creates and shows toolfig using helper function
toolfig = self._init_toolfig("Configure subplots", (6, 3))
SubplotTool(self.canvas.figure, toolfig)

def edit_parameters(self, *args):
# Creates and shows toolfig using helper function
toolfig = self._init_toolfig("Figure options", (4, 5))
AxesTool(self.canvas.figure, toolfig)

def save_figure(self, *args):
# Fetch the required filename and file type.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/qt_editor/figureoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def apply_callback(data):
data = _formlayout.fedit(
datalist, title="Figure options", parent=parent,
icon=QtGui.QIcon(
str(cbook._get_data_path('images', 'qt4_editor_options.svg'))),
str(cbook._get_data_path('images', 'editor_options.svg'))),
apply=apply_callback)
if data is not None:
apply_callback(data)
Binary file added lib/matplotlib/mpl-data/images/editor_options.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,32 @@ def test_slider_horizontal_vertical():
assert_allclose(box.bounds, [0, 0, 1, 10/24])


def test_dropdown_select():
ax = get_ax()
options = ['opt', 'opt', 'opt', 'opt', 'opt']
dropdown = widgets.Dropdown(ax, options, '')
def onselect(val):
ax._select_val = val
dropdown.on_select(onselect)
do_event(dropdown, '_click', xdata=0.1, ydata=0.01, button=1)
do_event(dropdown, '_click', xdata=0.1, ydata=0.01, button=1)
assert ax._select_val == 4


def test_dropdown_init_index_invalid():
ax = get_ax()
options = ['opt', 'opt', 'opt', 'opt', 'opt']
with pytest.raises(ValueError):
widgets.Dropdown(ax, options, '', init_index=5)


def test_dropdown_max_height_invalid():
ax = get_ax()
options = ['opt', 'opt', 'opt', 'opt', 'opt']
with pytest.raises(ValueError):
widgets.Dropdown(ax, options, '', max_height=-1)


def check_polygon_selector(event_sequence, expected_result, selections_count):
"""Helper function to test Polygon Selector

Expand Down
Loading