Skip to content

get_default_filename modifies user-supplied title for save dialog #7824

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
MG67Yjkkljd opened this issue Jan 14, 2017 · 9 comments
Closed

get_default_filename modifies user-supplied title for save dialog #7824

MG67Yjkkljd opened this issue Jan 14, 2017 · 9 comments
Milestone

Comments

@MG67Yjkkljd
Copy link

To help us understand and resolve your issue, please fill out the form to the best of your ability. You can feel free to delete the sections that do not apply.

Bug report

Bug summary

The default name for the save dialog is based upon the window/figure title. This is good as it's the only means by which a user's script can influence the default filename.

If the user's title has spaces in it then they are converted to underscores. This modification is not good as it changes the user's intended name but it may be necessary due to some Apps on some OSs not being able to handle spaces in paths.

The bigger problem is that the user- supplied title is ALWAYS converted to lower-case. This is VERY bad. If a user supplies a title that is valid for the OS they are using then they DO NOT expect it to be modified! In our case we have auto-generated filenames 40 or more chars in length with mixed case and it is impractical for the user to re-type this in every time.

If this is not fixed then it is essential to add a function by which the user can set the default name in some other manner.

Code for reproduction
a)

 fig = plt.gcf()
 fig.canvas.set_window_title("Auto_Generated_Very_Specific_Title_That_Is_Very_Annoying_To_ReType")

plt.plot()

b) Manually adjust plot to suit.
c) Click 'save' button.

Actual outcome

Default filename is:
'auto_generated_very_specific_title_that_is_very_annoying_to_retype'

Expected outcome

'Auto_Generated_Very_Specific_Title_That_Is_Very_Annoying_To_ReType'

Matplotlib version

Latest

@efiring
Copy link
Member

efiring commented Jan 14, 2017

I agree. I don't see any reason for the conversion. It looks like fixing it is a matter of deleting the .lower() from a single line in backend_bases.py, in FigureCanvasBase.get_default_filename. Would you like to submit a pull request to do that?

@NelleV
Copy link
Member

NelleV commented Jan 14, 2017

I think the reason for the lower case is that some OSs don't support capitalization of filenames (OSX?).
I'm still think it is perfectly fine deleting the .lower() :)

@efiring
Copy link
Member

efiring commented Jan 14, 2017

OSX HFS+ by default, and Windows always, are case-preserving but not case-sensitive. With OSX one can reformat the HFS+ filesystem to be case-sensitive. I am not aware of any OS or filesystem that rejects names with upper-case letters.

@jkseppan
Copy link
Member

The lowercasing was introduced (or apparently reintroduced) my @mspacek in commit c090a9c, which fixed something in the qt4 backend. I wonder if that backend has a problem with mixed-case filenames?

@efiring
Copy link
Member

efiring commented Jan 14, 2017

That's hard to imagine, but there must have been a reason for the reversion. The PR is #908.

@mspacek
Copy link
Contributor

mspacek commented Jan 14, 2017

When I made the changes in PR #908, I left the .lower() in because I remember being told somewhere by someone that we wanted to keep default filenames as lowercase. I personally think it's better for the default filename to preserve case. So yes, all that's required is to remove the .lower()

@jkseppan
Copy link
Member

I agree, let's remove the .lower(). I would prefer keeping spaces instead of transforming them to underscores but filenames with spaces tend to cause surprising problems in some environments.

What happens if there is a slash or a colon in the figure title? One of these is forbidden in file names in most environments. Or how about some emoji outside the Unicode BMP?

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jan 14, 2017
@tacaswell
Copy link
Member

efiring added a commit that referenced this issue Jan 18, 2017
FIX Preserve title case when saving through GUI (issue #7824)
QuLogic pushed a commit that referenced this issue Jan 30, 2017
FIX Preserve title case when saving through GUI (issue #7824)
@anntzer
Copy link
Contributor

anntzer commented Aug 31, 2017

Closed by #7865.

@anntzer anntzer closed this as completed Aug 31, 2017
@QuLogic QuLogic modified the milestones: v2.0.1, 2.1 (next point release) Aug 31, 2017
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

No branches or pull requests

8 participants