Hi
@halla
I’m testing annotations, an I have 2 remarks
The first one
I think it’s a bug.
But maybe I use annotation in an incorrect way but…
Here the code of my test:
from krita import *
fileName="/home/grum/Temporaire/test.kra"
doc = Krita.instance().createDocument(300, 300, "Test", "RGBA", "U8", "", 300.0)
#Krita.instance().activeWindow().addView(doc)
for i in range(3):
text=f"{i}={i*' * '}"
doc.setAnnotation(f'test{i}', f"description {i}", QByteArray(text.encode()))
print("-set------------")
for annotation in doc.annotationTypes():
print("annotation: ", annotation, "description: ", doc.annotationDescription(annotation))
ba=doc.annotation(annotation)
print(bytes(ba).decode())
doc.saveAs(fileName)
doc.close()
doc=Krita.instance().openDocument(fileName)
print("-loaded------------")
for annotation in doc.annotationTypes():
print("annotation: ", annotation, "description: ", doc.annotationDescription(annotation))
ba=doc.annotation(annotation)
print(bytes(ba).decode())
doc.close()
Result is:
-set------------
annotation: test0 description: description 0
0=
annotation: test1 description: description 1
1= *
annotation: test2 description: description 2
2= * *
-loaded------------
annotation: test2 description: description 2
2= * *
annotation: test1 description: description 1
annotation: test0 description: description 0
As you can see:
- Annotations are OK when just created
- Annotations are KO after document is loaded
– annotation identifier is OK
– annotation description is OK
– annotation data are KO; only the last one is loaded
Looking kra file, everything is OK (maindoc.xml + all annotations files contains expected data)
So it’s seems problem is during file loading, only the last annotation content is loaded.
=> Do I open a bug? as it’s still in prealpha…
The second one
Open a file
Set and/or remove annotation
File is considered as not modified/
Then close the file, all annotations changes are lost
I think it’s not possible to add annotation in undo/redo stack, but at least when annotations are modified, file status should be changed to “modified”, otherwise:
- that’s sure, some plugin annotations will be lost
- plugins developers will try dirty and tricky things to force file to be in “modified” status…
Otherwise, it’s very simple to use 
Grum999
