Skip to content
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

Return filename from save_figure #27766

Merged
merged 21 commits into from
Oct 28, 2024
Merged

Return filename from save_figure #27766

merged 21 commits into from
Oct 28, 2024

Conversation

Zybulon
Copy link
Contributor

@Zybulon Zybulon commented Feb 10, 2024

Closes #27744

PR summary

This PR adresses issue #27744.
save_figure functions from the NavigationToolbar return the filename of the saved figure.
If no figure is save then it returns None.
For GTK4 backend and Web backend I could not get the filename so the function still returns None.

PR checklist

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@Zybulon Zybulon force-pushed the main branch 5 times, most recently from 62fe3f4 to 1ec4655 Compare February 10, 2024 15:19
@Zybulon Zybulon marked this pull request as ready for review February 10, 2024 16:16
@tacaswell tacaswell added this to the v3.9.0 milestone Feb 10, 2024
@tacaswell
Copy link
Member

We can probably use a closure / nonlocal with the gtk response callback, but I'm not sure if dialog.show() blocks until the window is closed or return immediately. If it blocks then we can get the the filename out of that one too.

I agree we the webagg one looks like a big lift because I don't think we currently have a response back over the websocket. Even if we added that, it is not super clear it would be useful as the filesystems that the client (in a browser possibly on a different machine) is in general not the filesystem that the server sees. There is also a good case we should not leak anything about the client file system back to the server.

@tacaswell
Copy link
Member

If we want to differentiate between "I did not save a file" and "I can not tell you if a file was saved" we could return a different sentinel in the "I did not save a file case". The simplest thing (from an implement ion point of view...typing this proposal would be hard) would be to add NO_FILE_SAVED = object() as a class attribute on NavigationToolbar2 and return that if no file is saved.

@Zybulon
Copy link
Contributor Author

Zybulon commented Feb 10, 2024

That is a good idea. I'll do that.

@Zybulon
Copy link
Contributor Author

Zybulon commented Feb 10, 2024

Usually the FileDialogs (from Qt, Gtk etc...) return None when no file is selected. To be consistent with this behavior, I propose returning None when no file is saved and a class attribute UNKNOWN_SAVED_STATUS = object() when the status is unknown. What do you think ?

@Zybulon Zybulon marked this pull request as draft February 11, 2024 09:15
@Zybulon Zybulon force-pushed the main branch 8 times, most recently from f8a3028 to c474811 Compare February 11, 2024 15:52
@Zybulon Zybulon force-pushed the main branch 3 times, most recently from 64b6642 to 20c4e55 Compare May 20, 2024 06:59
@Zybulon Zybulon marked this pull request as draft May 20, 2024 16:22
@Zybulon Zybulon marked this pull request as ready for review May 20, 2024 16:23
@Zybulon
Copy link
Contributor Author

Zybulon commented May 20, 2024

Hello,
Sorry for the delay. I think the pull request is ready for review when someone has time to do so.

@Zybulon Zybulon marked this pull request as draft June 29, 2024 09:42
@Zybulon Zybulon marked this pull request as ready for review June 29, 2024 09:42
@tacaswell tacaswell closed this Oct 11, 2024
@tacaswell tacaswell reopened this Oct 11, 2024
@tacaswell
Copy link
Member

"power-cycled" to re-trigger CI.

@QuLogic
Copy link
Member

QuLogic commented Oct 12, 2024

Unfortunately, this is failing on the newly-added test.

@tacaswell
Copy link
Member

The failure is gtk setting itself up on python313:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
200

201
self = <matplotlib.backends.backend_gtk3.FigureManagerGTK3 object at 0x7f08a8dab770>
202
canvas = <backend_gtk3agg.FigureCanvasGTK3Agg object at 0x7f08a7f86c00 (matplotlib+backends+backend_gtk3agg+FigureCanvasGTK3Agg at 0x563ca08d20f0)>
203
num = 1
204

205
    def __init__(self, canvas, num):
206
        self._gtk_ver = gtk_ver = Gtk.get_major_version()
207
    
208
        app = _create_application()
209
        self.window = Gtk.Window()
210
        app.add_window(self.window)
211
        super().__init__(canvas, num)
212
    
213
        if gtk_ver == 3:
214
>           self.window.set_wmclass("matplotlib", "Matplotlib")
215
E           SystemError: <slot wrapper '__getattribute__' of 'module' objects> returned a result with an exception set
216

217
lib/matplotlib/backends/_backend_gtk.py:146: SystemError

@timhoffm timhoffm merged commit ff262a1 into matplotlib:main Oct 28, 2024
62 of 67 checks passed
@timhoffm
Copy link
Member

Thanks @Zybulon and congratulations on your first contribution to Matplotlib. 🎉 We hope to hear from you again!

@QuLogic
Copy link
Member

QuLogic commented Oct 29, 2024

The failing tests were not fixed yet...

@timhoffm
Copy link
Member

timhoffm commented Oct 29, 2024

which one? I thought the gtk3 python313 issue mentioned above is unrelated - Ok, my understanding: While it is unrelated, the intoduced test exercises a new gtk3 code path, which is broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

[ENH]: save_figure returns image fullpath
5 participants