Python Document.setModified() missing?

Document has modified() method for asking if document has been changed since last save.
But there are lot of document mehods that fail to set modified flag. (haven’t tested all methods.)

from krita import Krita

# before running
# open / save new document so that modified flag is false.

app = Krita.instance()
doc = app.activeDocument()

print(f"Krita version: {app.version()}")
print(f"before is_modified: {doc.modified()}")

doc.setDocumentInfo(doc.documentInfo() + "\n")
doc.setFramesPerSecond(int(doc.framesPerSecond() + 1))
doc.setFullClipRangeStartTime(doc.fullClipRangeStartTime() + 1)
doc.setFullClipRangeEndTime(doc.fullClipRangeEndTime() + 1)
doc.setFileName(doc.fileName() + ".ILBM")
doc.setName(doc.name()[::-1])

print(f"after is_modified: {doc.modified()}")

output:

==== Warning: Script not saved! ====
Krita version: 4.3.1-alpha (git 4212182)
before is_modified: False
after is_modified: False

No similar bugs exists in tracking. bug tracker
I can add bug to reporting. (if this is a bug)

/AkiR

1 Like

This set modified seems like something that should be done automatically on the C++ side. I know the animation related functionality was added later, so that was probably just missed. You could file a bug report about adding those settings to mark the document as modified.

Bug reported.
https://bugs.kde.org/show_bug.cgi?id=425066

Hmm… It looks like that there is no nice way to force modified flag.

import os
import tempfile

from krita import Krita


app = Krita.instance()
print(f"Krita version: {app.version()}")

new_document = app.createDocument(16, 16, "StillLife", "RGBA", "F32", "", 72.0)
app.activeWindow().addView(new_document)

print(f"before save, is modified: {new_document.modified()}")

temp_dir = tempfile.gettempdir()
temp_file_path = os.path.join(temp_dir, "krita_modified_test.kra")
save_success = new_document.saveAs(temp_file_path)
print(f"save as: {temp_file_path!r}, (save success: {save_success})")

print(f"before create layers, is modified: {new_document.modified()}")

parent_layer = new_document.rootNode()
for depth in range(10):
    child_layer = new_document.createGroupLayer(f"child_{depth}")
    parent_layer.addChildNode(child_layer, None)
    parent_layer = child_layer

print(f"after create layers, is modified: {new_document.modified()}")

output:

==== Warning: Script not saved! ====
Krita version: 4.3.1-alpha (git 4212182)
before save, is modified: False
save as: '/tmp/krita_modified_test.kra', (save success: True)
before create layers, is modified: False
after create layers, is modified: False