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

Python: hiding and showing layers doesn't update the view

Tags: None
(comma "," separated)
saedjubarin
Registered Member
Posts
58
Karma
0
I'm working on a python plugin extension to help me out with animated brush creation.

At the moment it provides two functions, start and next.

Start hides all layers except the "first one" and selects the "first one".
Next hides the active layer, shows the next layer and selects the next layer.

Works fine except that it doesn't update in the view. In other words, layers get hidden, visible and selected in the right manner, but the view of the canvas does not change. Is there something I should be doing to update the view?

Heres some code:
Code: Select all
from krita import Extension,  Krita

class BrushAnimator(Extension):

    def __init__(self, parent):
        #Always initialise the superclass.
        #This is necessary to create the underlying C++ object
        super().__init__(parent)
        self.current = "init"

    def setup(self):
        pass

    def createActions(self, window):
        action_next = window.createAction("ba_next", "Brush Animator: Next","tools/scripts")
        # parameter 1 =  the name that Krita uses to identify the action
        # parameter 2 = the text to be added to the menu entry for this script
        # parameter 3 = location in Krita menu to put this script entry
        action_next.triggered.connect(self._next)
        action_start = window.createAction("ba_start", "Brush Animator: Start","tools/scripts")
        action_start.triggered.connect(self.start)
       
    def _next(self):
        print("Brush Animator: Next")
        if self.current != "init":
            n_nodes = len(self.toplevel)
            self.toplevel[self.current%n_nodes].setVisible(False)
            self.current = (self.current + 1) %n_nodes
            self.toplevel[self.current].setVisible(True)
            self.doc.setActiveNode(self.toplevel[self.current])

    def start(self):
        print("Brush Animator: Start")
        self.doc = app.activeDocument()
        self.toplevel = self.doc.topLevelNodes()
        self.current = 0
        for node in self.toplevel:
            node.setVisible(False)
        self.toplevel[self.current].setVisible(True)
        self.doc.setActiveNode(self.toplevel[self.current])

       
# And add the extension to Krita's list of extensions:
app=Krita.instance()
extension=BrushAnimator(parent=app) #instantiate your class
app.addExtension(extension)
saedjubarin
Registered Member
Posts
58
Karma
0
Document.refreshProjection() solved it


Bookmarks



Who is online

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