This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Anyone have Python example: copy selection ?

Tags: None
(comma "," separated)
hulmanen
Registered Member
Posts
33
Karma
1
Hi, I'm trying to dip my toes into using Python in Krita a little. I have little idea where to even start with basics - I've found examples of how to clone layers, export them to files etc, but I can't seem to get from there to what I want to do. Does anyone have an example of what I suppose should be a fairly simple task: Copying the merged pixel data of all visible layers in a document, within a selection, to another document?

I'd appreciate any help!
User avatar
halla
KDE Developer
Posts
5092
Karma
20
OS
You could try to get the copy_merged action from the Krita object and trigger it. That would place the paste on the clipboard. Then in a new document, get the edit_paste action and trigger that. I haven't tried it yet, though!
saedjubarin
Registered Member
Posts
58
Karma
0
That is:
Code: Select all
app = Krita.instance()
app.action('copy_merged').trigger()
app.action('paste_new').trigger()


Not exactly playing with pixelData though. You could copy_merged, edit_paste or paste_layer_from_clipboard, find the layer from app.activeDocument() with app.activeDocument().topLevelNodes()[-1] or app.activeDocument().nodeByName() and those nodes have members called pixelData.

This might seem like basics, but for searching through pykrita I do something like this:

Code: Select all
app = Krita.instance()
print("\nKrita.instance():\n",dir(app))
print("\nKrita.instance().actions()[0]:\n",dir(app.actions()[0]))
print("\nsorted([action.objectName() for action in Krita.instance().actions()]):\n", sorted([action.objectName() for action in app.actions()]))
doc = app.activeDocument()
print("\nKrita.instance().activeDocument():\n", dir(doc))
win = app.activeWindow()
print("\nKrita.instance().activeWindow():\n", dir(win))
view = win.activeView()
print("\nKrita.instance().activeWindow().activeView():\n", dir(view))
saedjubarin
Registered Member
Posts
58
Karma
0
Look heres a lot of the information you need: https://forum.kde.org/viewtopic.php?f=156&t=156407&p=410512&hilit=selection#p410533

No wonder you didn't find it by yourself though, the topic has a vague title.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Evergrowing, Google [Bot], rblackwell