Prevent changing active layer whenever adding a new layer

I am using two windows to view the same drawing with one window dedicated to a particular layer. The problem is whenever I add/group a layer in the other window, the dedicated window will also change active layer to the newly added layer.I looked around and it seems impossible to prevent without changing the source code. Is there a part of the code I can just delete to prevent the active layer from changing whenever adding a new layer(or grouping layers)?

Thank you in advance.

Small toy script that creates a clone layer of current layer in another document, and opens new window and show new document in it.

How to use:

  1. copy & paste script to Krita’s Scripter
  2. activate some target layer on document.
  3. run script
  4. there should be now a second window to target layer

Not sure how happy Krita is about inter-document clone layers (save & load most likely will go bonkers!)

from krita import (
        Krita,)

from PyQt5.QtCore import (
        Qt,)

from PyQt5.QtWidgets import (
        QToolBar,
        QDockWidget,
        QMenuBar,
        QStatusBar,
        QMdiArea,
        QAbstractScrollArea)


def create_layer_view_window():
    app = Krita.instance()
    window = app.activeWindow()
    view = window.activeView()
    src_document = view.document()
    src_node = src_document.activeNode()

    new_document = app.createDocument(
            src_document.width(),
            src_document.height(),
            src_document.name(),
            src_document.colorModel(),
            src_document.colorDepth(),
            src_document.colorProfile(),
            src_document.resolution())

    clone_layer = new_document.createCloneLayer(src_node.name(), src_node)
    new_document.rootNode().addChildNode(clone_layer, None)

    new_window = app.openWindow()
    new_window.addView(new_document)
    new_qwindow = new_window.qwindow()
    new_qwindow.show()

    for child in new_qwindow.children():
        if isinstance(child, (QToolBar, QDockWidget, QMenuBar, QStatusBar)):
            child.hide()

    mdi_area = new_qwindow.centralWidget().findChild(QMdiArea)
    sub_window = mdi_area.currentSubWindow()
    sub_window.setWindowFlag(Qt.FramelessWindowHint, True)
    scroll_area = sub_window.findChild(QAbstractScrollArea)
    scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
    scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)


create_layer_view_window()

/AkiR

2 Likes

Thank you very much! I’ll be using this but this is not exactly what I had in mind. I didn’t mean for it to be an isolated layer and I still want to be able to paint on the window.

My workflow is, for example, I’m on the coloring layer and I want to edit the lineart layer, I can just switch windows and edit it right away then switch back to coloring. Other than layers, the selected brushes and colors are also independent from each window.

  1. switch to lineart layer

  2. pick color black

  3. pick lineart pen

  4. draw

  5. switch back to color layer

  6. pick previous color

  7. pick paintbrush

becomes:

  1. switch to lineart window

  2. draw

  3. switch back to coloring windows

I’m actually using multiple windows(for backgrounds, lineart, hair, etc). I use linux and have each window on workspaces so I can cycle through them pretty easily. The problem with this setup is I have to manually reclick the layers for every window whenever I add/group a new layer because all of them refocuses to the new layer.

Sound like you want to have a a window that “sticks" to specific layer.

Is it correct?

Yes.

As a workaround, I ended up with a global hotkey that sends a keyboard input to all krita windows at once to press the “Activate previously selected layer” shortcut.

1 Like