Skip to content

Use user-selected format in Tk savefig, rather than inferring it from the filename #24531

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 1 commit into from
Mar 15, 2023

Conversation

daniilS
Copy link
Contributor

@daniilS daniilS commented Nov 21, 2022

PR Summary

This also allows us to sort all extensions in alphabetical order, in line with the other backends, rather than having to put the default option first.

This change required raising the minimum supported version of Tk to 8.5, as discussed in #24450. I also removed a try statement around iconphoto, which should only have failed on Tk < 8.5 - it didn't feel big enough to deserve its own PR, but happy to separate it out if anyone disagrees.

Closes #24450.

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@daniilS daniilS changed the title Tk savefig formats Use user-selected format in Tk savefig, rather than inferring it from the filename Nov 21, 2022
@tacaswell tacaswell added this to the v3.7.0 milestone Nov 21, 2022
@tacaswell
Copy link
Member

I tried to test this locally, but that lead me to discovering that this dialog in broken on Fedora 37 with py311 with tk 8.6.12 with wayland both on this branch and 3.6.2 and with the system Python + building from the py311 branch. I have not chased down which of those is the source of the problem (but if I had to guess I would say wayland....)


This may catch out some people who type in the extension they want without changing the selector? Is that actually true and if so, do we think that is going to be a common problem? We probably should mention it as a behavior change?

@QuLogic
Copy link
Member

QuLogic commented Nov 22, 2022

I tried to test this locally, but that lead me to discovering that this dialog in broken on Fedora 37 with py311 with tk 8.6.12 with wayland both on this branch and 3.6.2 and with the system Python + building from the py311 branch. I have not chased down which of those is the source of the problem (but if I had to guess I would say wayland....)

I don't see any such problem with RPM Matplotlib or main; and I'm not sure what py311 branch you mean.

@daniilS
Copy link
Contributor Author

daniilS commented Nov 22, 2022

This may catch out some people who type in the extension they want without changing the selector? Is that actually true and if so, do we think that is going to be a common problem? We probably should mention it as a behavior change?

I hadn't considered that - I copied the behaviour from the GTK backend, which uses the selected format, but it looks like macosx and Qt ignore the selected format and just use the filename, and wx uses the selected format but warns if it differs from the filename. I'm not sure which behaviour is most intuitive - even on default Windows programs, turns out mspaint uses the selected format, while wordpad uses the filename.

@tacaswell
Copy link
Member

by py311, I mean the v3.11 branch from CPython. If Elliott can not reproduce this I'll assume this is a local problem....

@QuLogic
Copy link
Member

QuLogic commented Nov 23, 2022

OK, I can reproduce in ipython when calling plt.ion(). However, this is broken with Fedora Python 3.11 on Wayland, and conda Python 3.8 on X11, so it's unrelated to either of those, and also unrelated to this PR.

@tacaswell
Copy link
Member

tacaswell commented Nov 23, 2022

Wx warning is my favorite behavior (it tells the user they are doing something ambiguous and we have taken a guess at what they meant), all of the backends should probably do that.

As for which way it breaks:

  • the case for making them all the same (no matter which way) is about consistency (which may catch someone out when they change backends), the case against is that it is going to change behavior and probably catch someone out
  • the case for leaving them all as they are the opposite

As for which way makes more sense:

  • if you follow the format, then the user can drop writing the extension into the text box and we treat format as prescriptive that happens to filter the UI
  • if you follow the filename, then we do what the user asked for and the format in the UI is "just" a file filter.

@anntzer
Copy link
Contributor

anntzer commented Nov 23, 2022

FWIW I much prefer following whatever the user typed (which is qt's behavior); as an example, inkscape forces you (or at least used to, haven't checked recently) to go through the combobox which I find supremely annoying (especially when there are many, many formats supported and you need to figure out where is the one you want).

@tacaswell tacaswell modified the milestones: v3.7.0, v3.8.0 Dec 15, 2022
@tacaswell
Copy link
Member

I pushed this to 3.8 because we need to sort out which of the 3 behaviors is "right".

@daniilS
Copy link
Contributor Author

daniilS commented Dec 16, 2022

Having spoken to some others and looked at how different software behaves, I now also think it's best to have the typed extension take priority over the dropdown, so keeping the existing behaviour. I've updated the PR, so now it only uses the dropdown selection if the filename contains no extension, and also correctly sorts the extensions in alphabetical order.

@jklymak
Copy link
Member

jklymak commented Jan 30, 2023

ping @anntzer @tacaswell for new behaviour change.

<optional_dependencies>` are being bumped:

+------------+-----------------+---------------+
| Dependency | min in mpl3.6 | min in mpl3.7 |
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
| Dependency | min in mpl3.6 | min in mpl3.7 |
| Dependency | min in mpl3.7 | min in mpl3.8 |

@tacaswell
Copy link
Member

👍🏻 to this change, but I think it needs a behavior change note.

@anntzer
Copy link
Contributor

anntzer commented Jan 31, 2023

Ditto, the new behavior looks good to me.

@jklymak
Copy link
Member

jklymak commented Feb 2, 2023

@daniilS can you handle the behaviour change? Otherwise this looks good to go...

@daniilS daniilS force-pushed the tk_savefig_formats branch 2 times, most recently from 2d9ff14 to 6b28bef Compare March 1, 2023 14:45
@daniilS
Copy link
Contributor Author

daniilS commented Mar 1, 2023

@jklymak apologies for the delay, behaviour change note added & api note updated to 3.8

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

A rebase should fix the documentation build.

Also, the default file name includes .png, which means you can't simply change the type and get a different type, as the filename overrides. If would be nice if (extension of text == old filetype) then the extension were changed to the new type. Or perhaps the extension could just not be added.

Co-Authored-By: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@daniilS daniilS force-pushed the tk_savefig_formats branch from 11b1854 to b876de8 Compare March 8, 2023 18:26
@daniilS
Copy link
Contributor Author

daniilS commented Mar 8, 2023

Also, the default file name includes .png, which means you can't simply change the type and get a different type, as the filename overrides. If would be nice if (extension of text == old filetype) then the extension were changed to the new type. Or perhaps the extension could just not be added.

Good point - Windows (and I think MacOS, but not sure) automatically edits the filename when changing the dropdown selection, but the Tk implementation of the dialog on Linux does not. Not giving an extension by default seems like the best solution to me.

@daniilS daniilS requested a review from QuLogic March 13, 2023 23:35
@QuLogic QuLogic merged commit ac32c78 into matplotlib:main Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MNT]: Fix or drop support for Tk 8.4
6 participants