Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Backend class for better code reuse between backend modules#8773

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 1 commit intomatplotlib:masterfromanntzer:backend-class
Jul 24, 2017

Conversation

anntzer
Copy link
Contributor

This is the second part of#8771, split out for simpler review (note that it also includes the first part, which is the object of#8772; thus, I would suggest specifically looking at the diff of thelast commit).

Currently, backend modules need to define a number of classes (FigureCanvas,FigureManager) and functions (new_figure_manager,new_figure_manager_given_figure,show,draw_if_interactive) with specified names, which leads to some serious copy-pasting between the modules, as well as seemingly unused imports (see e.g. "not used" comment in backend_qt5agg.py). Instead, use a class-based approach: the_Backend class can be subclassed to define these functions (and provides some templates for them); then a special decorator re-exports the attributes and methods of the_Backend class to the backend-defining module.

@anntzeranntzer changed the titleBackend classBackend class for better code reuse between backend modulesJun 18, 2017
@anntzeranntzer mentioned this pull requestJun 18, 2017
6 tasks
@anntzeranntzerforce-pushed thebackend-class branch 5 times, most recently frombf03f1e to544823aCompareJune 18, 2017 22:23
@tacaswell
Copy link
Member

How does this interact with#4143 ?

FigureManager = FigureManagerPgf


def draw_if_interactive():
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a class method on the preceding class?

Copy link
ContributorAuthor

@anntzeranntzerJun 19, 2017
edited
Loading

Choose a reason for hiding this comment

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

Either way istechnically fine (this def will just override the one exported by the decorator) but actually I can just leave trigger_manager_draw as None and this way we'll get a do-nothing draw_if_interactive.

@tacaswell
Copy link
Member

Given how disruptive this change could be, I am surprisingly 👍 on this 😄 .

This is a very elegant solution to a problem that has been bugging me for years.

@tacaswell
Copy link
Member

And to answer my own question, I think this is mostly orthogonal.

@anntzer
Copy link
ContributorAuthor

Re#4143 (MEP27): this doesn't really change anything, MEP27 can still go in (modulo conflicts, but they're already there anyways) (and I don't really have an opinion regarding MEP27). This is really just a way to 1. use some private "templates" to define helper functions and 2. dofrom other_backend import draw_if_interactive, show, ... without appearing to have a bunch of unneeded imports.

@anntzeranntzerforce-pushed thebackend-class branch 3 times, most recently from811b2d0 to05aae1eCompareJune 19, 2017 05:48
@anntzeranntzer mentioned this pull requestJun 19, 2017
# each draw command. Instead, we mark the figure as invalid, so that it
# will be redrawn as soon as the event loop resumes via PyOS_InputHook.
# This function should be called after each draw event, even if
# matplotlib is not running interactively.
Copy link
Member

Choose a reason for hiding this comment

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

This comment, taken from the original, has me puzzled. It seems to be contradicted by the code, which does nothing unlessis_interactive() returns True. This is not changed by your refactor, so if the comment is misleading now, then it was also misleading before; or I am just missing its point in both cases.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I'm going to leave it as it is for now...

@efiring
Copy link
Member

I certainly welcome the reduced duplication (which always bothered me also) and reduced LOC. And the removal of some cruft, like the import of ctypes!

@tacaswelltacaswell added this to the2.1 (next point release) milestoneJun 19, 2017
@anntzeranntzerforce-pushed thebackend-class branch 2 times, most recently from795c171 to1c3da14CompareJune 20, 2017 19:28
@anntzeranntzerforce-pushed thebackend-class branch 2 times, most recently froma422dca to2254671CompareJuly 1, 2017 22:50
@tacaswell
Copy link
Member

@anntzer can you rebase this now that#8772 is in?

@anntzer
Copy link
ContributorAuthor

done

Copy link
Contributor

@dopplershiftdopplershift left a comment

Choose a reason for hiding this comment

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

Looks like a nice clean up. I don't see anything that bothers me.

@tacaswell
Copy link
Member

I am going to give this one more read through before pushing the merge button myself, but happy if someone else also reviews this and merges.

@anntzer
Copy link
ContributorAuthor

Rebased.

@tacaswelltacaswell merged commita5d9254 intomatplotlib:masterJul 24, 2017
@anntzeranntzer deleted the backend-class branchJuly 24, 2017 18:26
@jklymakjklymak mentioned this pull requestDec 14, 2017
@anntzeranntzer mentioned this pull requestMar 5, 2018
6 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@efiringefiringefiring left review comments

@tacaswelltacaswelltacaswell approved these changes

@dopplershiftdopplershiftdopplershift approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v2.1
Development

Successfully merging this pull request may close these issues.

4 participants
@anntzer@tacaswell@efiring@dopplershift

[8]ページ先頭

©2009-2025 Movatter.jp