Is it possible to confirm transform through python code, please?

I’ve been wondering for a while now trying to figure out a way that’s not horribly hacky.

Does anyone please know a way how to confirm transformation when transform tool is selected and used (ctrl + T)?

Thank you very much for an advice. :slight_smile:

I can’t find a proper way.

So the way I made it was through buttons in tool options (even if it’s floating or hidden).
It’s not the nicest way but it seems to work for me. Need to test it on windows and other platforms but so far works in linux just fine.

        # Get ToolBox
        for docker in Krita.instance().dockers():
            if docker.objectName() == "ToolBox":
                break

        tools = docker.findChildren(QToolButton)

        # Get the active tool
        for tool in tools:
            if tool.isChecked():
                break

        # Reset/Confirm works only if transform tool is selected (Ctrl+T)
        if tool.objectName() != "KisToolTransform":
            return

        ############################################################
        # Get the transform tool options accept and cancel buttons
        ############################################################
        buttons = {"apply": None, "reset": None}

        # Get Tool Options
        for docker in Krita.instance().dockers():
            if docker.objectName() == "sharedtooldocker":
                break
                
        # Get apply or reset (or any other button I assume)
        # still no info which is which here
        # This part could be omitted, only one of the children is needed
        # to get the parent later, I'm keeping this as a 2 way
        # check since apply and reset seem to be the only ones with
        # empty objectName
        for button in docker.findChildren(QPushButton):
            if button.objectName() == "":
                break

        # Get apply and/or reset button - this way you avoid translation problems with button.text()
        for button in button.parent().buttons():
            if button.parent().buttonRole(button) == QDialogButtonBox.ApplyRole:
                buttons["apply"] = button
            elif button.parent().buttonRole(button) == QDialogButtonBox.ResetRole:
                buttons["reset"] = button


        # This confirms the transformation
        buttons["apply"].click()
        # This resets the transformation 
        buttons["reset"].click()

EDIT
The other option I came up with is to post the Key_enter event but I have no idea what receives/handles the events in Krita and/or if python even has access to it (but it’s a 2 lines of code so it could eventually reduce the code down if someone knows, please let me know which object to use) ;).

EDIT2
Ehh… I didn’t realize there’s a translation on button.text property.
Made an adjustment to the code to get the buttons hopefully properly this time.
(technically the part

1 Like