I want to be able to either: have my script run after the window is done. Or just directly do what I want it to do without the window popup in the first place.
I can’t find information on how to call the ‘Seperate Image…’ without a popup. When I call the function with batchmode enabled it pops up anyway
My only other idea was to get keypresses somehow but I don’t think that is supported?
Following auto accepts separate dialog. (You might want to find dialogs radio/check buttons, and change values before accepting…)
from krita import Krita
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication
def do_separation():
def _do_after():
separate_dialog = QApplication.activeModalWidget()
# ToDo: find QCheckBox & QRadioButton widgets and set values...
separate_dialog.accept()
app = Krita.instance()
separate_action = app.action('separate')
QTimer.singleShot(0, _do_after) # call _do_after, separate dialog is active
separate_action.trigger()
do_separation()
@AkiR Thank you for your answer, it was very helpful!
For the ToDo part of your comment, is it something along these lines? Or - ignoring the fact that it iterates the widget tree every time to check a box - is there a more elegant/correct way I should be doing it?
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QCheckBox
from PyQt5.QtCore import QObject
from typing import cast
def find_widget(inParentWidget, inName):
if inParentWidget.objectName() == inName:
return inParentWidget
for widget in inParentWidget.children():
widget = find_widget(widget, inName)
if widget:
return widget
return None
def set_checked(inDialog, inName, inChecked):
widget = find_widget(inDialog, inName)
if not widget:
raise Exception(f"{inDialog} has no widget named {inName}")
if isinstance(widget, QCheckBox):
checkbox = cast(QCheckBox, widget)
checkbox.setChecked(inChecked)
else:
raise Exception(f"{widget} is not a QCheckBox")
def split_layer(inDoc):
def _do_after():
dialog = QApplication.activeModalWidget()
set_checked(dialog, "chkCreateGroupLayer", True)
set_checked(dialog, "chkSeparateGroupLayers", False)
set_checked(dialog, "chkAlphaLock", False)
dialog.accept()
splitAction = Krita.instance().action("layersplit")
QTimer.singleShot(0, _do_after)
splitAction.trigger()