Fix resource names
In beginner lesson 13: Resources https://scripting.krita.org/lessons/resources
Under the heading: Accessing resources
The code example:
# working resources
print(Krita.instance().resources('brushes')) # brush image tips
print(Krita.instance().resources('gradients'))
print(Krita.instance().resources('patterns'))
print(Krita.instance().resources('workspaces'))
print(Krita.instance().resources('paintoppresets')) # brush preset
print(Krita.instance().resources('palettes')) # color palettes
# not working right now (could also be spelled wrong)
print(Krita.instance().resources('gamutmasks'))
print(Krita.instance().resources('svgsymbols'))
print(Krita.instance().resources('windowLayouts'))
print(Krita.instance().resources('layerstyles'))
print(Krita.instance().resources('sessions'))
print(Krita.instance().resources('tasksets'))
Returns:
==== Warning: Script not saved! ====
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
At the bottom of the resources lesson, there's a link to: https://api.kde.org/krita/html/classView.html
Searching for "resource" in the top left search input box.
Found this page: https://api.kde.org/krita/html/classResource.html
With this example:
allPresets = Application.resources("preset")
for preset in allPresets:
print(preset.name())
Running it in the Krita Scripter window, shows the error message:
AttributeError: 'str' object has no attribute 'name'
In file: In function: at line: 3. Line with error:
Removing .name()
in the print statement:
allPresets = Application.resources("preset")
for preset in allPresets:
print(preset)
Shows lots of brush preset names:
a) Eraser Circle
a) Eraser Small
a) Eraser Soft
b) Airbrush Soft
b) Basic-1
...
Searching for "preset" (with double quotes), on the Krita repository: https://invent.kde.org/graphics/krita
Found this file: https://invent.kde.org/graphics/krita/-/blob/master/libs/libkis/Krita.cpp#L287
Where it lists similar names to the first six lines in lesson thirteens code example:
if (type == "pattern") {
...
else if (type == "gradient") {
...
else if (type == "brush") {
...
else if (type == "palette") {
...
else if (type == "workspace") {
...
else if (type == "preset") {
...
The code example returns resources for all six of these names:
print(Krita.instance().resources('brush')) # brush image tips
print(Krita.instance().resources('gradient'))
print(Krita.instance().resources('pattern'))
print(Krita.instance().resources('workspace'))
print(Krita.instance().resources('preset')) # brush preset
print(Krita.instance().resources('palette')) # color palettes
For example:
- "brush", shows:
{'3_eroded': <PyKrita.krita.Resource object at 0x000001D738BCAF70>, 'A -2 Sparkle 3': <PyKrita.krita.Resource object at 0x000001D738BCAEE0> ...
- "gradient" shows:
{'0. Foreground to Background': <PyKrita.krita.Resource object at 0x000001D728AF5160>, '1. Foreground to Transparent': <PyKrita.krita.Resource object at 0x000001D728AF5040> ...
- etc.
The other six resources don't seem to work with shorter names.
Maybe the Krita.instance().resources()
command only returns resources for the six that are defined in: https://invent.kde.org/graphics/krita/-/blob/master/libs/libkis/Krita.cpp#L287