DistributedProofreaders/guiguts-py

An edited project can be closed withoiut a save file warning

Closed this issue · 10 comments

okrick commented

Steps:

  1. Open and edit a project.
  2. Right click on the GG2 icon on the Windows taskbar.
  3. Select Close all Windows.
  4. The project immediately closes without a save warning.

Every other method I could think of for closing the edited project (Alt-F4, File menu options, title bar close button) correctly resulted in a warning to save the changes. GG1 does issue a warning except when the Perl icon is closed.

Thanks Rick - can I ask how you are running GG2.
I have a terminal window that I type guiguts in when I want to run the latest released alpha version (as opposed to the development version which I run in a different way). When I right click on the GG2 icon, my menu doesn't say Close All Windows if I only have one version of GG2 running. I can close guiguts from there, but it does check if I want to save.

If I run Guiguts twice, by starting two terminal windows and typing guiguts in each one, I can get a Close All Windows menu entry, but it asks me the "do you want to save" question for each of the two GG2 windows.

So, hopefully you can give me a bit more info that will help me to reproduce it.

okrick commented

I use a shortcut with the target=C:\Users\okric\AppData\Local\Programs\Python\Python311\Scripts\guiguts.exe -r1

I don't open two windows for GG2. When I hover over the GG2 icon in the taskbar I see two windows. One for GG2 itself and one for the Guiguts.shortcut.

okrick commented

OK, if I close the GG2 window by hovering over the taskbar icon and then moving to close the GG2 window by itself I do get a save warning. If I close the guiguts.shortcut window then both windows close without a save warning.

OK - I have reproduced it, though it's not exactly as you describe. See screenshot below.
I get two separate icons as you can see, the left being the "terminal window" (or shortcut), and the right being the GG2 one.
For some reason yours sound like they are combined into one icon. As you've just mentioned while I was composing this, if I quit by using the GG icon, I do get a warning, but if I quit by using the terminal/shortcut window, then they close without warning.

This is the same behavior as you described for GG1 - if you kill off the process that is running GG1 (or GG2) it seems that GG1/2 die before they get a chance to warn you. I'll have a look to see if there's a way round that, but there may well not be a practical fix for it, since we are stopping GG2 in an unexpected/uncontrolled way.

image

Note to self: looks at the signal module: https://docs.python.org/3/library/signal.html#signal.SIGTERM
Maybe it can trap the attempt to kill the python process?

okrick commented

I was curious as to why the shortcut window persists. I have shortcuts for other programs and the shortcut gets closed when the program opens.

okrick commented

That's odd. I created a batch file with the command C:\Users\okric\AppData\Local\Programs\Python\Python311\Scripts\guiguts.exe -r1. It works the same as the shortcut and leaves a cmd window open which shuts GG2 down without a save warning.

Is GG2 an exe file or a Python script?

Thanks for the extra info @okrick - see the bottom of this post for a possible solution if the rest of the post is too long!

I was able to reproduce exactly your original question about "Close all windows" by setting my shortcut to start minimized instead of in a normal window.

GG2 is written in Python.

If you are curious, I think if you go to somewhere like
C:\Users\okric\AppData\Local\Programs\Python\Python311\Lib\site-packages
you would see a guiguts folder with all the installation files including the python.

I believe when you pip install guiguts, it creates a very small guiguts.exe (which is the one you have linked your shortcut too) and all that does is start up the python interpreter to run the guiguts python script.

I have looked at whether it's easy to catch the terminating signal within guiguts and to ask you the "save?" question before exiting. While I was able to catch some signals (such as using Ctrl+C in a shell window running guiguts) I wasn't able to catch anything that happens when exiting the parent command window.

Solution

However, if you change your shortcut to the following, you don't get an extra command window, and when you quit it by right clicking the icon in the taskbar, it asks you nicely whether you want to save. Let me know if it works for you.
C:\Users\okric\AppData\Local\Programs\Python\Python311\pythonw.exe -m guiguts -r1

(If curious, what the above shortcut is doing is running the python executable instead of the little guiguts executable, but telling python to load the guiguts module. The "w" in "pythonw.exe" rather than plain "python.exe" means run python without the command window)

okrick commented

That shortcut works. Only one window is opened, and it prompts for saving when closed from a right-click selection on the taskbar icon.

Thank you.

Reasonable solution found.