esternin / eXtrema

https://www.physics.brocku.ca/Labs/extrema/
GNU General Public License v2.0
6 stars 1 forks source link

Properly set and remember paper settings in Print dialog #29

Closed esternin closed 3 years ago

esternin commented 3 years ago

File -> Print currently opens up with a ~/Documents/output.pdf, A4, Portrait, always, ignoring both the locale settings (LC_PAPER?) and the selection made by the user on the previous Print.

vadz commented 3 years ago

Sorry, bad news, this seems to be totally broken in wxGTK :-(

The code is already there, but we just don't get most of the values entered into the dialog somehow, including the paper size (nor even the orientation). I'm not sure if this can be fixed, but in any case it would have to be done inside wxGTK itself and so wouldn't help with wx 3.0.5 used currently.

All I can do right now is to set the initial paper size correctly based on locale, but it still won't be preserved correctly.

esternin commented 3 years ago

I do not quite get it, I thought Windows, too, knew about locales? The check maybe different, but the selection after the check should be universal?

Let me get this straight: since the saving of the selection is done in the GTK Print dialog, we never get back what the user decided on for a particular print job, so cannot save it to restore it later, but we can always SET it before calling GTK Print, based on locale? So that's half-good news, no? Maybe we can also SET the orientation, not based on what the last print job was but on the current H/W ratio (GET ASPECTRATIO) for our window/subwindow, and set it to landscape if <1 and portrait if >=1 ?

Also can we SET the default directory for output.pdf to be the current directory (where extrema was launched) and not always ~/Documents/ ? In any case, ~/ would be a better default than ~/Documents.

vadz commented 3 years ago

I do not quite get it, I thought Windows, too, knew about locales? The check maybe different, but the selection after the check should be universal?

Yes, but we don't have a Windows version yet, so I didn't do it there. Using LC_PAPER wouldn't be useful there anyhow.

Let me get this straight: since the saving of the selection is done in the GTK Print dialog, we never get back what the user decided on for a particular print job, so cannot save it to restore it later, but we can always SET it before calling GTK Print, based on locale? So that's half-good news, no? Maybe we can also SET the orientation, not based on what the last print job was but on the current H/W ratio (GET ASPECTRATIO) for our window/subwindow, and set it to landscape if <1 and portrait if >=1 ?

Yes, we can do this.

Also can we SET the default directory for output.pdf to be the current directory (where extrema was launched) and not always ~/Documents/ ? In any case, ~/ would be a better default than ~/Documents.

Not sure, I'd have to look into this if it's important.

vadz commented 3 years ago

I think I've found a way to make this work, we need to keep a separate wxPageSetupDialogData. I'll update #32 with more changes soon.

vadz commented 3 years ago

To give more details, there is a separate "Page Setup" dialog in GTK which can be used to select the page size and orientation. Unfortunately it needs to be invoked separately, i.e. I still can't see a way to get this information from the "Print" dialog itself. So the idea would be to

  1. Use the appropriate paper size by default (as already done).
  2. Use the appropriate orientation by default.
  3. Add new "Page Setup" menu item allowing to change them and remember them.
  4. Save page setup data on exit and restore it next time.
  5. And, of course, use this page setup data when printing by default (although there is still a question of which orientation to use by default, the saved one or the one corresponding to the current aspect ratio?).

Please let me know if you have any comments, otherwise I'll try to implement this soon.

esternin commented 3 years ago

My Print dialog has two tabs, the second being image

That's the one I would like to pre-populate with reasonable defaults, depending on locale and current aspect ratio.

  1. if we are saving, that should override the defaults, of course.
vadz commented 3 years ago

I've found a way to get the missing information from this tab, finally, but doing this requires changing wxWidgets, of course. I'll do it for 3.1.6, and this could probably be backported to 3.0.6 too if you think it's worth it.

Again, this is only about saving this information, setting it does work. But, in fact, I don't know if it's really that important to bother saving anything right now, as the only piece of information we really need to save is the paper size and this will probably be the same as auto-detected (from locale) value in 90% of the cases. Notably, saving the orientation doesn't seem useful if we're going to always override it using the current aspect ratio, is it?

vadz commented 3 years ago

Oh, and I've also found a way to specify the file path to use for "Print to file", but this requires changes to wx too, of course, so I'm not sure if you're really interested in this at this stage, as it won't help with the version using system libraries under Ubuntu -- but could be useful for a future version using Snap or whatever, where we'd have to use our own build of the library anyhow.

esternin commented 3 years ago

I've found a way to get the missing information from this tab, finally, but doing this requires changing wxWidgets, of course. I'll do it for 3.1.6, and this could probably be backported to 3.0.6 too if you think it's worth it.

We can wait for 3.1.6, no urgent need.

Again, this is only about saving this information, setting it does work.

This is the most important part.

But, in fact, I don't know if it's really that important to bother saving anything right now, as the only piece of information we really need to save is the paper size and this will probably be the same as auto-detected (from locale) value in 90% of the cases. Notably, saving the orientation doesn't seem useful if we're going to always override it using the current aspect ratio, is it?

Correct, the orientation on paper will most of the time agree with the orientation on screen, and in those rare occasions when one needs to override it (a landscape plot on a portrait page is reasonably common), it's a split-second delay, one of two selector. As opposed to paper size, because the drop down there on my system is about 200 items long instead of just 2, with US Letter three pages down. Hitting it is a many-click process, extremely annoying.

esternin commented 3 years ago

Oh, and I've also found a way to specify the file path to use for "Print to file", but this requires changes to wx too, of course, so I'm not sure if you're really interested in this at this stage, as it won't help with the version using system libraries under Ubuntu -- but could be useful for a future version using Snap or whatever, where we'd have to use our own build of the library anyhow.

Again, if the wxGTK is eventually fixed to remember the filename used the last time, as it does for any other application, the need for setting it for the first use will abate. But I do find it strange that its default is not to a directory that is the current one, but a fixed location at ~/Documents. It must be coming from wx, since GTK print dialog from other programs does remember the last filename used, even from another program; this is what alerted me to this being different from the expected behaviour.

esternin commented 3 years ago

I merged the orientation change, but the size is not yet in. Did you want to change your pull request to use wxLocale (that is not yet available in 3.0.5)? Or do we stick with the current workaround?

vadz commented 3 years ago

No, I don't think it's worth using wxLocale for this, I'm almost sure this is not needed under Windows anyhow because the correct paper size is selected automatically there. This really is Unix-specific, so the current version should be fine IMHO.

esternin commented 3 years ago

Well, on Chromebook (debian/wayland), /etc/default/locale does not contain an LC_PAPER line, and it does not get added by update-locale.

I had to add it by hand, and stop/restart termina (the Linux VM) before it caught on. What is interesting, though, is that the default location of the output file is the current directory where extrema was launched from.

But I am happy to merge as is, and close this issue, unless you want to keep it around as a reminder of future improvements.

vadz commented 3 years ago

Sorry, I made a stupid mistake, LC_PAPER is just an override and we have to fall back on LC_ALL if it's not defined, of course. And, moreover, we shouldn't be using the environment at all, but use setlocale() function which does it for us. Don't know what I was thinking, sorry again -- will fix in a moment.

vadz commented 3 years ago

The LC_PAPER problem is fixed in 58f8bf82f48251730098fd93ff46cbe542d3d8ea and I've implemented remembering print data in aebad5cb6b829d7bc5fea64bbb385e1c3996ced6, and I think it's all we can do for now.

I've also fixed the problem with not getting back the paper size from the dialog in wx itself, but this will only work with 3.1.6+.

I'm not sure if you want to keep this open for possible future enhancements (e.g. we could still add a separate "Page Setup" dialog) or if this should be just closed -- so I leave it to you to decide it.

esternin commented 3 years ago

I think the only remaining puzzle is why Print to file defaults differently on different platforms: strictly to ~/Documents/output.pdf on some, and current_directory/output.pdf on others.

I'll consider it a quirk of the GTK, and it's not worth pursuing at this stage, I am closing this. The changes have made it quite convenient to use.