Please, I’d like to set position_lock = True on trigger (key down) and when the key is released I’d like to turn it back to False but I have no idea how to handle the key press. Right now it works only once (since triggers goes off but I don’t have anything to handle the release).
I’m also not familiar with Python at all so the code is probably strange (I don’t think I’m using the self keyword properly) sry for that. I tried defining a keyReleaseEvent but honestly I have no idea how to do it to make it work.
I’d really appreciate your advice. Thank you very much.
So far I have this
from krita import *
from PyQt5.QtWidgets import *
import math
class CustomCanvasRotationExtension(Extension):
def __init__(self,parent):
super().__init__(parent)
def createActions(self,window):
self.c_rotation = window.createAction("c_rotation", "Custom Canvas Rotation", "tools/scripts")
self.c_rotation.setAutoRepeat(True)
self.position = QCursor.pos()
self.position_lock = False
self.safe_buffer = 30
self.iii = 0
# krita = Krita.instance()
# self.canvas = Krita.instance().activeWindow().activeView().canvas()
@self.c_rotation.triggered.connect
def on_trigger():
canvas = Krita.instance().activeWindow().activeView().canvas()
# self.canvas doesn't work, no idew why, need to check what self actually means
if not self.position_lock:
self.position = QCursor.pos()
self.position_lock = True
distance = math.sqrt( math.pow((QCursor.pos().x() - self.position.x()), 2) + math.pow((QCursor.pos().y() - self.position.y()), 2) )
if distance > self.safe_buffer:
canvas.setRotation(self.iii)
self.iii += 3
# canvas.resetRotation()
def setup(self):
pass
Krita.instance().addExtension(CustomCanvasRotationExtension(Krita.instance()))
I’m just dumb and this is proving to be a challenge as expected though for such a small functionality gain that I’m starting to doubt myself xD