78 lines
3.3 KiB
Python
78 lines
3.3 KiB
Python
|
|
from PyQt5.QtCore import pyqtSlot
|
||
|
|
from functools import partial
|
||
|
|
from krita import Krita, Extension
|
||
|
|
from PyQt5.QtGui import QPixmap, QIcon
|
||
|
|
from PyQt5.QtWidgets import QToolButton, QWidget
|
||
|
|
|
||
|
|
class Psopacitycontrols(Extension):
|
||
|
|
|
||
|
|
def __init__(self, parent):
|
||
|
|
super().__init__(parent)
|
||
|
|
self.defaultOpacityList = [0.03, 0.07, 0.15, 0.24, 0.65, 0.75, 0.9, 0.9, 0.9, 0.9]
|
||
|
|
|
||
|
|
def setup(self):
|
||
|
|
pass
|
||
|
|
|
||
|
|
def msg(self, msg: str, pixmap: QPixmap):
|
||
|
|
try:
|
||
|
|
Application.activeWindow().activeView().showFloatingMessage(msg, QIcon(pixmap), 1000, 2)
|
||
|
|
except Extension as e:
|
||
|
|
print("psopacitycontrols error:",e)
|
||
|
|
|
||
|
|
def createActions(self, window):
|
||
|
|
for i, item in enumerate(['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']):
|
||
|
|
action = window.createAction(
|
||
|
|
"set_opacity_number-" + item,
|
||
|
|
str(f"Set opacity {item}"), "")
|
||
|
|
action.triggered.connect(partial(self.setOpacity, False, self.defaultOpacityList[i]))
|
||
|
|
action = window.createAction(
|
||
|
|
"set_flow_number-" + item,
|
||
|
|
str(f"Set flow {item}"),"")
|
||
|
|
action.triggered.connect(partial(self.setOpacity, True, self.defaultOpacityList[i]))
|
||
|
|
action = window.createAction(
|
||
|
|
f"set_reset",
|
||
|
|
f"Reset flow/opacity/blendmode to default", "")
|
||
|
|
action.triggered.connect(partial(self.setOpacity, True, 1.0, True))
|
||
|
|
|
||
|
|
def setOpacity(self, flow, amount, reset=False):
|
||
|
|
window = Application.activeWindow()
|
||
|
|
currentPreset = window.views()[0].currentBrushPreset()
|
||
|
|
if window and window.views():
|
||
|
|
if self.find_my_current_tool().objectName() == "KritaShape/KisToolBrush":
|
||
|
|
if reset:
|
||
|
|
self.msg(f"RESET BRUSH", QPixmap.fromImage(currentPreset.image()))
|
||
|
|
window.views()[0].setPaintingOpacity(1.0)
|
||
|
|
window.views()[0].setPaintingFlow(1.0)
|
||
|
|
window.views()[0].setCurrentBlendingMode("")
|
||
|
|
elif flow:
|
||
|
|
self.msg(f"FLOW {amount*100}%", QPixmap.fromImage(currentPreset.image()))
|
||
|
|
window.views()[0].setPaintingFlow(amount)
|
||
|
|
else:
|
||
|
|
self.msg(f"OPACITY {amount*100}%", QPixmap.fromImage(currentPreset.image()))
|
||
|
|
window.views()[0].setPaintingOpacity(amount)
|
||
|
|
else:
|
||
|
|
currentDoc = Krita.instance().activeDocument()
|
||
|
|
currentLayer = currentDoc.activeNode()
|
||
|
|
if reset: amount = 1.0
|
||
|
|
self.msg(f"LAYER {amount * 100}%", QPixmap.fromImage(currentPreset.image()))
|
||
|
|
currentLayer.setOpacity(int(amount*255))
|
||
|
|
currentDoc.refreshProjection()
|
||
|
|
|
||
|
|
def find_tool_box(self, qwindow):
|
||
|
|
for qobj in qwindow.findChildren(QWidget):
|
||
|
|
if qobj.metaObject().className() == "KoToolBox":
|
||
|
|
return qobj
|
||
|
|
|
||
|
|
def find_active_tool(self, qtoolbox):
|
||
|
|
for qobj in qtoolbox.findChildren(QToolButton):
|
||
|
|
if qobj.metaObject().className() == "KoToolBoxButton":
|
||
|
|
if qobj.isChecked():
|
||
|
|
return qobj
|
||
|
|
|
||
|
|
def find_my_current_tool(self):
|
||
|
|
app = Krita.instance()
|
||
|
|
qwindow = app.activeWindow().qwindow()
|
||
|
|
tool_box = self.find_tool_box(qwindow)
|
||
|
|
tool = self.find_active_tool(tool_box)
|
||
|
|
return tool
|