101 lines
3.6 KiB
Python
101 lines
3.6 KiB
Python
import math
|
|
|
|
from PyQt5.QtCore import Qt, QSize
|
|
from PyQt5.QtGui import QPixmap, QIcon
|
|
from PyQt5.QtWidgets import (QDialogButtonBox, QLabel, QVBoxLayout,
|
|
QHBoxLayout, QCheckBox, QGridLayout)
|
|
|
|
from . import hotkeybrushesdialog, dropbutton
|
|
import krita
|
|
|
|
|
|
class UIHotkeyBrushes(object):
|
|
|
|
def __init__(self):
|
|
self.kritaInstance = krita.Krita.instance()
|
|
self.mainDialog = hotkeybrushesdialog.HotkeyBrushesDialog(
|
|
self, self.kritaInstance.activeWindow().qwindow())
|
|
|
|
self.buttonBox = QDialogButtonBox(self.mainDialog)
|
|
self.vbox = QVBoxLayout(self.mainDialog)
|
|
self.hbox = QHBoxLayout(self.mainDialog)
|
|
self.grid = QGridLayout(self.mainDialog)
|
|
self.checkBox = QCheckBox(
|
|
i18n("&Activate previous brush when pressing the shortcut for the "
|
|
"second time"),
|
|
self.mainDialog)
|
|
|
|
self.buttonBox.accepted.connect(self.mainDialog.accept)
|
|
self.buttonBox.rejected.connect(self.mainDialog.reject)
|
|
|
|
self.buttonBox.setOrientation(Qt.Horizontal)
|
|
self.buttonBox.setStandardButtons(
|
|
QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
|
|
|
self.presetChooser = krita.PresetChooser(self.mainDialog)
|
|
|
|
def initialize(self, hotkeybrushes):
|
|
self.hotkeybrushes = hotkeybrushes
|
|
|
|
self.loadButtons()
|
|
|
|
self.vbox.addLayout(self.hbox)
|
|
self.vbox.addLayout(self.grid)
|
|
self.vbox.addWidget(
|
|
QLabel(i18n("Select the brush preset, then click on the button "
|
|
"you want to use to select the preset")))
|
|
self.vbox.addWidget(self.presetChooser)
|
|
|
|
self.checkBox.setChecked(self.hotkeybrushes.activatePrev)
|
|
self.checkBox.toggled.connect(self.setActivatePrev)
|
|
self.vbox.addWidget(self.checkBox)
|
|
|
|
self.vbox.addWidget(self.buttonBox)
|
|
|
|
self.mainDialog.show()
|
|
self.mainDialog.activateWindow()
|
|
self.mainDialog.exec_()
|
|
|
|
def setActivatePrev(self, checked):
|
|
self.hotkeybrushes.activatePrev = checked
|
|
|
|
def loadButtons(self):
|
|
self.hotkeybrushes.buttons = []
|
|
|
|
allPresets = Application.resources("preset")
|
|
relevantActions = list(filter(lambda a: hasattr(a, "preset"), self.hotkeybrushes.actions))
|
|
|
|
for index, item in enumerate(range( 1, 64 )):
|
|
buttonLayout = QVBoxLayout()
|
|
button = dropbutton.DropButton(self.mainDialog)
|
|
button.setObjectName(str(item))
|
|
button.clicked.connect(button.selectPreset)
|
|
button.presetChooser = self.presetChooser
|
|
|
|
action = relevantActions[index]
|
|
|
|
if action and action.preset and action.preset in allPresets:
|
|
p = allPresets[action.preset]
|
|
button.preset = p.name()
|
|
button.setIcon(QIcon(QPixmap.fromImage(p.image())))
|
|
button.setToolTip(f"#{index+1} | {p.name()} \n {action.shortcut().toString()}")
|
|
|
|
buttonLayout.addWidget(button)
|
|
|
|
button_number = math.floor(float(index)/9)
|
|
mod_key_str = "NNNCCCSSS"*9
|
|
tap_amount_str = "123123123"*9
|
|
mod_key = mod_key_str[index]
|
|
tap_amount = tap_amount_str[index]
|
|
row = index % 9
|
|
|
|
label = QLabel(f"#{index+1} | {button_number}{mod_key}{tap_amount}")
|
|
# label = QLabel(
|
|
# action.shortcut().toString())
|
|
label.setAlignment(Qt.AlignLeft)
|
|
buttonLayout.addWidget(label)
|
|
|
|
# self.hbox.addLayout(buttonLayout)
|
|
self.grid.addLayout(buttonLayout, button_number, row)
|
|
self.hotkeybrushes.buttons.append(button)
|