Skip to content

dynamically finding the backend preferred format for button images #9811

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

Merged
merged 5 commits into from
Nov 25, 2017

Conversation

fariza
Copy link
Member

@fariza fariza commented Nov 18, 2017

PR Summary

The Tools used by Toolmanager assumed every backend understood .png files for the button images.
This is not the case, for example tk works with png in linux but not on mac

This pr fixes this by asking each backend for it's preferred image format

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

"""
Get the preferred image extension

Return
Copy link
Contributor

Choose a reason for hiding this comment

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

Returns.

if os.path.isfile(fname):
return fname

def btn_image_extension(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

"preferred_image_extension"?

Copy link
Member Author

Choose a reason for hiding this comment

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

prone to confusion?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not actually a preference, it is matter of "does it work?"

Copy link
Contributor

@anntzer anntzer Nov 19, 2017

Choose a reason for hiding this comment

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

supported_...
(it's not as if you have to repeat this name again and again many places through the codebase so you may as well avoid abbreviating it).

Copy link
Member

Choose a reason for hiding this comment

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

could we get away with just having a class-level attribute of _icon_extension ?

Copy link
Contributor

Choose a reason for hiding this comment

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

probably would work too...

Copy link
Member Author

Choose a reason for hiding this comment

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

That was my first idea, but I didn't like creating a property with a raise AttributeError in the base class.
But i guess you're right, it is alot easier and cleaner for the final implementation of the backend

Copy link
Contributor

Choose a reason for hiding this comment

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

Make it None on the base class which will make it raise a TypeError when fetching the attribute if not overridden?

Copy link
Member

Choose a reason for hiding this comment

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

Or default to 'png'?

@anntzer
Copy link
Contributor

anntzer commented Nov 19, 2017

FWIW recent tkinters should support png out of the box (https://stackoverflow.com/a/27601573/378080).

@tacaswell tacaswell added this to the v2.2 milestone Nov 19, 2017
@fariza
Copy link
Member Author

fariza commented Nov 19, 2017

@tacaswell I changed it to a class attribute as suggested, I think it is cleaner this way

@anntzer
Copy link
Contributor

anntzer commented Nov 19, 2017

Repro'ing my comment that got folded when the code was patched away:

Make it None on the base class which will make it raise a TypeError when fetching the attribute if not overridden?

@tacaswell
Copy link
Member

I think it is ok to leave it as 'png' as the default extension as well.

@fariza
Copy link
Member Author

fariza commented Nov 19, 2017

Done!, added a default format

@dstansby
Copy link
Member

I think this will need a manual rebase against current master for circleCI to work.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

Rebasing on current master so that circle bulids would be good, but not going to hold the PR over that.

@dstansby dstansby merged commit ba4142a into matplotlib:master Nov 25, 2017
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants