Add more Python API calls for Animation
ClosedPublic

Authored by scottpetrovic on Oct 27 2018, 4:13 PM.

Details

Reviewers
rempt
Group Reviewers
Krita
Summary

This patch adds some more ability to do animation related things via the Python API

Mostly getting and setting animation docker variables such as the start time, end time, current playhead time, and frame rate

I am working on a plugin and needed to set the frame rate, but thought I would add a few extra things while I was at it.

The one thing I am not sure about is if we need an API call for "Show in Timeline". I imagine that is available as an action, so maybe we don't need that as a separate python API call on the Node class. It is a toggle though on the UI, so not sure if you can explicitly set "show in timeline" on or off through the action.

This also should close out this feature request that was wanting an API call for getting and setting the current time...
https://bugs.kde.org/show_bug.cgi?id=391666

Test Plan

Start Krita , create a new document. Run this python script that calls all the new API methods and outputs some things to the console. You should also be able to see the UI elements update on the animation docker.

import sys
from krita import *

for doc in Krita.instance().documents():
    
    activeLayer = doc.activeNode()  
    
    print( activeLayer.animated())
    activeLayer.enableAnimation()
    
    print("show in timeline initial: ", activeLayer.showInTimeline() )
    activeLayer.setShowInTimeline(1)
    print("show in timeline after set: ", activeLayer.showInTimeline() )

    # testing new Animation API calls
    # all the new calls are right off the document class    
    
    doc.setFramesPerSecond(24)
    print("grabbing frame rate: ", doc.framesPerSecond())


    doc.setFullClipRangeStartTime(0)
    print("grabbing clip range start time: ", doc.fullClipRangeStartTime())


    doc.setFullClipRangeEndTime(300)
    print("grabbing clip range end time: ", doc.fullClipRangeEndTime())


    print("grabbing animation length: ", doc.animationLength())

    doc.setPlayBackRange(20, 45)
    print("grabbing playback range: ", doc.playBackStartTime(), " ", doc.playBackEndTime() ) 
    
    
    doc.setCurrentTime(143)
    print("grabbing clip range end time: ", doc.currentTime())

Diff Detail

Repository
R37 Krita
Lint
Lint Skipped
Unit
Unit Tests Skipped
scottpetrovic created this revision.Oct 27 2018, 4:13 PM
Restricted Application added a project: Krita. · View Herald TranscriptOct 27 2018, 4:13 PM
scottpetrovic requested review of this revision.Oct 27 2018, 4:13 PM
scottpetrovic edited the summary of this revision. (Show Details)
rempt requested changes to this revision.Oct 29 2018, 12:05 PM
rempt added a subscriber: rempt.
rempt added inline comments.
libs/libkis/Document.cpp
869

No, please don't do this. Scripts should also run when there's no active view. The right way to get the image in the Document class is to use the image in the embedded KisDocument:

if (!d->document) return false;
if (!d->document->image()) return false;
d->document->image()->animationInterface()->framerate();
This revision now requires changes to proceed.Oct 29 2018, 12:05 PM

I changed all the checks to return the document instead of the active view.

scottpetrovic marked an inline comment as done.Oct 29 2018, 2:02 PM
rempt accepted this revision.Oct 29 2018, 2:36 PM
This revision is now accepted and ready to land.Oct 29 2018, 2:36 PM
scottpetrovic closed this revision.Oct 29 2018, 3:05 PM

Thanks for the review @rempt

Just pushed it out. Closing this ticket.