8000 Minor RectangleSelector refactors by dstansby · Pull Request #22146 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Minor RectangleSelector refactors #22146

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

Closed
wants to merge 2 commits into from
Closed

Conversation

dstansby
Copy link
Member
@dstansby dstansby commented Jan 7, 2022

I'm trying to get my head around some odd failures in #21945. As part of that process, here's some minor refactoring that improves readability of the RectangleSelector code and reduces a bit of duplication.

if self._selection_completed:
# Call onselect, only when the selection is already existing
self.onselect(self._eventpress, self._eventrelease)
self._selection_completed = False
self.clear()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change intended here? It's not a refactoring but changes code, e.g. clear() calls update() and then we call update again below in 3501.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember what is the purpose of the visible attribute but another consequence of using clear is that it changes the value of the visible attribute from True to False and I am not sure if this desirable - this would need to be checked.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record: it seems that the visible attribute is only used by the selector itself (and should be private) and it is reset in _press, so the point I made here is not an issue!

Copy link
Member
@ericpre ericpre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this code block is only used in a method which is not very long, I am not convinced that creating a separate method make the code more readable: this is about balancing redirection and adding more method versus shorten the code of where it is used, which in this case, I find subjective!

if self._selection 8000 _completed:
# Call onselect, only when the selection is already existing
self.onselect(self._eventpress, self._eventrelease)
self._selection_completed = False
self.clear()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember what is the purpose of the visible attribute but another consequence of using clear is that it changes the value of the visible attribute from True to False and I am not sure if this desirable - this would need to be checked.

@@ -3005,6 +3005,19 @@ def _press(self, event):

return False

def _selector_too_small(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be a property?

@dstansby
Copy link
Member Author
dstansby commented Jan 8, 2022

Perhaps I was too hasty in opening this PR, and the changes make more sense in the context of #21945. I think I'll close this, fix up #21945 by itself, and apologise for the noise.

@dstansby dstansby closed this Jan 8, 2022
@dstansby dstansby deleted the rect-refact branch January 8, 2022 12:30
@ericpre
Copy link
Member
ericpre commented Jan 8, 2022

I fully appreciate that the selector are not easy to read and I am really looking forward for when we can remove the drawtype argument and all the clean up that goes with it! :)

@dstansby
Copy link
Member Author
dstansby commented Jan 8, 2022

😆 couldn't agree more!

@QuLogic QuLogic removed this from the v3.6.0 milestone Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0