`Document::close()` does not close a tab when the file is modified and "Cancel" is clicked

Hello, I found a weird behavior of Document::close() when I was writing a Python plugin for Krita.

Reproduction

  1. Open a Krita
  2. Create a document
  3. Draw something on the document.
  4. Run the following script with the Scripter.
from krita import Krita

Krita.instance().activeDocument().close()
  1. A dialog to confirm whether to actually close or not will show. If you choose to cancel, the same dialog will appear, and after selecting cancel again, the document will be closed, but the tab will remain.

What I expect are:

If the document is modified, you should save it first. There will be no prompt for saving.

  • If a dialog appears (which is against the current API doc), it should appear once.
  • The tab is closed too when a document is closed.

Are those expected behaviors? Did I miss something?

Krita usage log

04 Jun 2022 23:47:49 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git b123708), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 11776


04 Jun 2022 23:47:49 +0900: Style: fusion. Available styles: Windows, Fusion
04 Jun 2022 23:47:49 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.0.8, at 土 6月 4 23:12:15 2022
04 Jun 2022 23:56:40 +0900: CLOSING SESSION

SESSION: 04 Jun 2022 23:56:42 +0900. Executing krita

Krita Version: 5.0.8, Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 14040


04 Jun 2022 23:56:42 +0900: Style: fusion. Available styles: Windows, Fusion
04 Jun 2022 23:56:42 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.0.8, at 土 6月 4 23:12:15 2022
04 Jun 2022 23:56:47 +0900: CLOSING SESSION

SESSION: 04 Jun 2022 23:56:56 +0900. Executing krita

Krita Version: 5.0.8, Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 14538


04 Jun 2022 23:56:56 +0900: Style: fusion. Available styles: Windows, Fusion
04 Jun 2022 23:56:56 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.0.8, at 土 6月 4 23:12:15 2022
04 Jun 2022 23:57:01 +0900: CLOSING SESSION

SESSION: 04 Jun 2022 23:57:03 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git b123708), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 14817


04 Jun 2022 23:57:03 +0900: Style: fusion. Available styles: Windows, Fusion
04 Jun 2022 23:57:03 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.0.8, at 土 6月 4 23:12:15 2022
04 Jun 2022 23:57:11 +0900: CLOSING SESSION

SESSION: 05 Jun 2022 11:05:37 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 19529


05 Jun 2022 11:05:37 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:05:37 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.0.8, at 土 6月 4 23:12:15 2022
05 Jun 2022 11:05:51 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:05:51 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpoa6i_9jw.tga. Real location: /tmp/tmpoa6i_9jw.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:05:51 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpoa6i_9jw.tga. Real location: /tmp/tmpoa6i_9jw.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:05:51 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpoa6i_9jw.tga. Real location: /tmp/tmpoa6i_9jw.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:06:02 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpoa6i_9jw.tga. Real location: /tmp/tmpoa6i_9jw.tga. Batchmode: 0. Configuration:

1 2 false false true

KRITA DID NOT CLOSE CORRECTLY

SESSION: 05 Jun 2022 11:10:04 +0900. Executing /home/hiroki/kritadev/install/bin/krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 22290


05 Jun 2022 11:10:04 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:10:07 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.0.8, at 土 6月 4 23:12:15 2022
05 Jun 2022 11:10:40 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:10:40 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmp203ktkw6.tga. Real location: /tmp/tmp203ktkw6.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:10:40 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmp203ktkw6.tga. Real location: /tmp/tmp203ktkw6.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:10:40 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmp203ktkw6.tga. Real location: /tmp/tmp203ktkw6.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:10:44 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmp203ktkw6.tga. Real location: /tmp/tmp203ktkw6.tga. Batchmode: 0. Configuration:

1 2 false false true

KRITA DID NOT CLOSE CORRECTLY

SESSION: 05 Jun 2022 11:11:50 +0900. Executing /home/hiroki/kritadev/install/bin/krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 23274


05 Jun 2022 11:11:50 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:11:53 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.0.8, at 土 6月 4 23:12:15 2022
05 Jun 2022 11:11:58 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:11:58 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpcu2827z6.tga. Real location: /tmp/tmpcu2827z6.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:11:58 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpcu2827z6.tga. Real location: /tmp/tmpcu2827z6.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:11:58 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpcu2827z6.tga. Real location: /tmp/tmpcu2827z6.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:12:14 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpcu2827z6.tga. Real location: /tmp/tmpcu2827z6.tga. Batchmode: 0. Configuration:

1 2 false false true

KRITA DID NOT CLOSE CORRECTLY

SESSION: 05 Jun 2022 11:13:03 +0900. Executing /home/hiroki/kritadev/install/bin/krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 24460


05 Jun 2022 11:13:03 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:13:06 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.0.8, at 土 6月 4 23:12:15 2022
05 Jun 2022 11:13:11 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:13:11 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpjk_qzp0_.tga. Real location: /tmp/tmpjk_qzp0_.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:13:11 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpjk_qzp0_.tga. Real location: /tmp/tmpjk_qzp0_.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:13:11 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpjk_qzp0_.tga. Real location: /tmp/tmpjk_qzp0_.tga. Batchmode: 0. Configuration:

1 2 false false true

05 Jun 2022 11:13:32 +0900: Converting from application/x-krita to image/x-tga. Location: /tmp/tmpjk_qzp0_.tga. Real location: /tmp/tmpjk_qzp0_.tga. Batchmode: 0. Configuration:

1 2 false false true

KRITA DID NOT CLOSE CORRECTLY

SESSION: 05 Jun 2022 11:16:31 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 26472


05 Jun 2022 11:16:31 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:16:31 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.0.8, at 土 6月 4 23:12:15 2022
05 Jun 2022 11:16:52 +0900: CLOSING SESSION

SESSION: 05 Jun 2022 11:16:53 +0900. Executing krita

Krita Version: 5.0.2, Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 27226


05 Jun 2022 11:16:53 +0900: Style: fusion. Available styles: Windows, Fusion

KRITA DID NOT CLOSE CORRECTLY

SESSION: 05 Jun 2022 11:16:56 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 27309


05 Jun 2022 11:16:56 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:16:57 +0900: Database is up to date. Version: 0.0.15, created by Krita 5.0.2, at 日 6月 5 11:16:55 2022
05 Jun 2022 11:17:28 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:17:35 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:17:48 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:17:56 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:19:34 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:19:43 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:21:06 +0900: CLOSING SESSION

SESSION: 05 Jun 2022 11:21:07 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 32649


05 Jun 2022 11:21:07 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:21:07 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.1.0-prealpha, at 日 6月 5 11:16:57 2022
05 Jun 2022 11:21:13 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1

KRITA DID NOT CLOSE CORRECTLY

SESSION: 05 Jun 2022 11:25:10 +0900. Executing krita --help

Krita Version: 5.0.2, Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 7477


05 Jun 2022 11:25:10 +0900: Style: fusion. Available styles: Windows, Fusion
+0900: CLOSING SESSION
05 Jun 2022 11:27:42 +0900: CLOSING SESSION

SESSION: 05 Jun 2022 11:27:43 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 13085


05 Jun 2022 11:27:43 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:27:44 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.1.0-prealpha, at 日 6月 5 11:16:57 2022
05 Jun 2022 11:28:05 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:36:23 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:36:39 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:45:57 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:46:00 +0900: CLOSING SESSION

SESSION: 05 Jun 2022 11:46:01 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 25588


05 Jun 2022 11:46:01 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:46:01 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.1.0-prealpha, at 日 6月 5 11:16:57 2022
05 Jun 2022 11:46:08 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:46:37 +0900: CLOSING SESSION

SESSION: 05 Jun 2022 11:46:38 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 26230


05 Jun 2022 11:46:38 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:46:39 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.1.0-prealpha, at 日 6月 5 11:16:57 2022
05 Jun 2022 11:46:44 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:47:49 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:49:41 +0900: CLOSING SESSION

SESSION: 05 Jun 2022 11:49:44 +0900. Executing ./krita --version

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 26962


05 Jun 2022 11:49:44 +0900: Style: fusion. Available styles: Windows, Fusion
+0900: CLOSING SESSION

SESSION: 05 Jun 2022 11:49:48 +0900. Executing ./krita --version

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 27039


05 Jun 2022 11:49:48 +0900: Style: fusion. Available styles: Windows, Fusion
+0900: CLOSING SESSION

SESSION: 05 Jun 2022 11:53:25 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 27527


05 Jun 2022 11:53:25 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:53:26 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.1.0-prealpha, at 日 6月 5 11:16:57 2022
05 Jun 2022 11:54:10 +0900: CLOSING SESSION

SESSION: 05 Jun 2022 11:54:11 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 29145


05 Jun 2022 11:54:11 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:54:11 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.1.0-prealpha, at 日 6月 5 11:16:57 2022
05 Jun 2022 11:54:15 +0900: Created image “無題”, 48 * 48 pixels, 300 dpi. Color model: 8-ビット整数/チャンネル RGB/アルファ (sRGB-elle-V2-srgbtrc.icc). Layers: 1
05 Jun 2022 11:55:23 +0900: CLOSING SESSION

SESSION: 05 Jun 2022 11:55:26 +0900. Executing ./krita

Krita Version: 5.1.0-prealpha (git d335b6f), Qt version compiled: 5.15.3, loaded: 5.15.3. Process ID: 32607


05 Jun 2022 11:55:26 +0900: Style: fusion. Available styles: Windows, Fusion
05 Jun 2022 11:55:26 +0900: Database is up to date. Version: 0.0.16, created by Krita 5.1.0-prealpha, at Sun Jun 5 11:16:57 2022
05 Jun 2022 11:55:34 +0900: Created image “Unnamed”, 48 * 48 pixels, 300 dpi. Color model: 8-bit integer/channel RGB/Alpha (sRGB-elle-V2-srgbtrc.icc). Layers: 1

Version: 5.1.0-prealpha (git d335b6f)

The document is “closed”, the view is not. So you are left with an empty view.

There was most likely changes with how the document close is done, hence the popup appears. And when you cancel, the document closes but leaves the view.

That is undocumented behavior, yes.

I think you need to do the batch mode to bypass questions.

Thank you for your replies. I’ll look into the view and batch mode.