widgets: use a shared _Buttons class for {Radio,Check}Buttons#30997
widgets: use a shared _Buttons class for {Radio,Check}Buttons#30997timhoffm merged 5 commits intomatplotlib:mainfrom
Conversation
For more consistency and similarity with RadioButtons
c5ee840 to
b1eb725
Compare
timhoffm
left a comment
There was a problem hiding this comment.
Please add an entry to widget_api.rst
|
|
||
|
|
||
| class CheckButtons(AxesWidget): | ||
| class _Buttons(AxesWidget): |
There was a problem hiding this comment.
Please add a docstring.
The class should be treated analogous to _SelectorWidget, including
The class itself is private and may be changed or removed without prior warning.
However, the public API it provides to subclasses is stable and considered
public on the subclasses.
There was a problem hiding this comment.
Please add a docstring.
Done.
story645
left a comment
There was a problem hiding this comment.
I assume that this is just the move things phase and code changes will happen in the follow up? Also thanks for doing this!
Share all the trivial functions which are identical without any further modifications.
|
|
||
| self._useblit = useblit | ||
|
|
||
| self._buttons_ys = np.linspace(1, 0, len(labels)+2)[1:-1] |
There was a problem hiding this comment.
(Answering in a code review in order to explain better)
I assume that this is just the move things phase and code changes will happen in the follow up? Also thanks for doing this!
Correct. In the next PR the _Buttons class will also gain a self._buttons_xs attribute, which will be used when creating the _buttons in _init_props. As for self.labels, they will be created with the algorithm written in the previous PR, but with mtext.Text instanced once etc.
|
This broke some cross-references, but it was hidden by the docs build being broken; I'll fix it in #31020. |
In matplotlib#30997 the classes `RadioButtons` & `CheckButtons` started sharing more code, as they are fundamentally similar. When copy-pasting the methods that were seemingly identical, the `_clicked` method was copied from the original `CheckButtons` class, and there the `self._frames` object was used instead of `self._buttons`. This caused an error when actually using and clicking on buttons created with `RadioButtons`, as the `RadioButtons._frames` doesn't exist - something that unfortunately the tests did not catch. Both `CheckButtons._frames` and `CheckButtons._buttons` are very similar so even before matplotlib#30997 the `CheckButtons._clicked` method could have used `self._checks` and not `self._frames`. Hence this change should be harmless.
|
Another fixup change that I noticed is needed when rewriting #30803 : |
In matplotlib#30997 the classes `RadioButtons` & `CheckButtons` started sharing more code, as they are fundamentally similar. When copy-pasting the methods that were seemingly identical, the `_clicked` method was copied from the original `CheckButtons` class, and there the `self._frames` object was used instead of `self._buttons`. This caused an error when actually using and clicking on buttons created with `RadioButtons`, as the `RadioButtons._frames` doesn't exist - something that unfortunately the tests did not catch. Both `CheckButtons._frames` and `CheckButtons._buttons` are very similar so even before matplotlib#30997 the `CheckButtons._clicked` method could have used `self._checks` and not `self._frames`. Hence this change should be harmless.
In matplotlib#30997 the classes `RadioButtons` & `CheckButtons` started sharing more code, as they are fundamentally similar. When copy-pasting the methods that were seemingly identical, the `_clicked` method was copied from the original `CheckButtons` class, and there the `self._frames` object was used instead of `self._buttons`. This caused an error when actually using and clicking on buttons created with `RadioButtons`, as the `RadioButtons._frames` doesn't exist - something that unfortunately the tests did not catch. Both `CheckButtons._frames` and `CheckButtons._buttons` are very similar so even before matplotlib#30997 the `CheckButtons._clicked` method could have used `self._checks` and not `self._frames`. Hence this change should be harmless.
In matplotlib#30997 the classes `RadioButtons` & `CheckButtons` started sharing more code, as they are fundamentally similar. When copy-pasting the methods that were seemingly identical, the `_clicked` method was copied from the original `CheckButtons` class, and there the `self._frames` object was used instead of `self._buttons`. This caused an error when actually using and clicking on buttons created with `RadioButtons`, as the `RadioButtons._frames` doesn't exist - something that unfortunately the tests did not catch. Both `CheckButtons._frames` and `CheckButtons._buttons` are very similar so even before matplotlib#30997 the `CheckButtons._clicked` method could have used `self._checks` and not `self._frames`. Hence this change should be harmless.
In matplotlib#30997 the classes `RadioButtons` & `CheckButtons` started sharing more code, as they are fundamentally similar. When copy-pasting the methods that were seemingly identical, the `_clicked` method was copied from the original `CheckButtons` class, and there the `self._frames` object was used instead of `self._buttons`. This caused an error when actually using and clicking on buttons created with `RadioButtons`, as the `RadioButtons._frames` doesn't exist - something that unfortunately the tests did not catch. Both `CheckButtons._frames` and `CheckButtons._buttons` are very similar so even before matplotlib#30997 the `CheckButtons._clicked` method could have used `self._checks` and not `self._frames`. Hence this change should be harmless.
RadioButtons: fix self._clicked method (followup to #30997)
PR summary
A preparation refactoring commit for #30803 . Changes include:
PR checklist