Krita Source Code Documentation
Loading...
Searching...
No Matches
uitenbrushes.py
Go to the documentation of this file.
1# SPDX-License-Identifier: CC0-1.0
2
3try:
4 from PyQt6.QtCore import Qt
5 from PyQt6.QtGui import QPixmap, QIcon
6 from PyQt6.QtWidgets import (QDialogButtonBox, QLabel, QVBoxLayout,
7 QHBoxLayout, QCheckBox)
8except:
9 from PyQt5.QtCore import Qt
10 from PyQt5.QtGui import QPixmap, QIcon
11 from PyQt5.QtWidgets import (QDialogButtonBox, QLabel, QVBoxLayout,
12 QHBoxLayout, QCheckBox)
13from . import tenbrushesdialog, dropbutton
14from krita import Krita, PresetChooser
15from builtins import i18n, Application
16
17
18class UITenBrushes(object):
19
20 def __init__(self):
23 self, self.kritaInstance.activeWindow().qwindow())
24
25 self.buttonBox = QDialogButtonBox(self.mainDialog)
26 self.vbox = QVBoxLayout(self.mainDialog)
27 self.hbox = QHBoxLayout(self.mainDialog)
28
29 self.checkBoxActivatePrev = QCheckBox(
30 i18n("&Activate previous brush preset when pressing the shortcut for the "
31 "second time"),
32 self.mainDialog)
33
34 self.checkBoxAutoBrush = QCheckBox(
35 i18n("&Select freehand brush tool when pressing a shortcut"),
36 self.mainDialog)
37
38 self.checkBoxShowMessage = QCheckBox(
39 i18n("Show on-canvas &popup message when activating brush preset"),
40 self.mainDialog)
41
42 self.buttonBox.accepted.connect(self.mainDialog.accept)
43 self.buttonBox.rejected.connect(self.mainDialog.reject)
44
45 self.buttonBox.setOrientation(Qt.Orientation.Horizontal)
46 self.buttonBox.setStandardButtons(
47 QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
48
49 self.presetChooser = PresetChooser(self.mainDialog)
50
51 def initialize(self, tenbrushes):
52 self.tenbrushes = tenbrushes
53
54 self.loadButtons()
55
56 self.vbox.addLayout(self.hbox)
57 self.vbox.addWidget(
58 QLabel(i18n("Select the brush preset, then click on the button "
59 "you want to use to select the preset.")))
60 self.vbox.addWidget(
61 QLabel(i18n("Shortcuts are configurable through the <i>Keyboard Shortcuts</i> "
62 "interface in Krita's settings.")))
63
64 self.vbox.addWidget(self.presetChooser)
65
66 self.checkBoxActivatePrev.setChecked(self.tenbrushes.activatePrev)
68 self.vbox.addWidget(self.checkBoxActivatePrev)
69
70 self.checkBoxAutoBrush.setChecked(self.tenbrushes.autoBrush)
72 self.vbox.addWidget(self.checkBoxAutoBrush)
73
74 self.checkBoxShowMessage.setChecked(self.tenbrushes.showMessage)
76 self.vbox.addWidget(self.checkBoxShowMessage)
77
78 self.vbox.addWidget(self.buttonBox)
79
80 self.mainDialog.show()
81 self.mainDialog.activateWindow()
82 self.mainDialog.exec()
83
84 def setActivatePrev(self, checked):
85 self.tenbrushes.activatePrev = checked
86
87 def setAutoBrush(self, checked):
88 self.tenbrushes.autoBrush = checked
89
90 def setShowMessage(self, checked):
91 self.tenbrushes.showMessage = checked
92
93 def loadButtons(self):
94 self.tenbrushes.buttons = []
95
96 allPresets = Application.resources("preset")
97
98 for index, item in enumerate(['1', '2', '3', '4', '5',
99 '6', '7', '8', '9', '0']):
100 buttonLayout = QVBoxLayout()
101 button = dropbutton.DropButton(self.mainDialog)
102 button.setObjectName(item)
103 button.clicked.connect(button.selectPreset)
104 button.presetChooser = self.presetChooser
105
106 action = Application.action("activate_preset_" + item)
107
108 preset = self.tenbrushes.selectedPresets[index] if index < len(self.tenbrushes.selectedPresets) else None
109
110 if action and preset and preset in allPresets:
111 p = allPresets[preset]
112 button.preset = p.name()
113 button.setIcon(QIcon(QPixmap.fromImage(p.image())))
114
115 buttonLayout.addWidget(button)
116
117 label = QLabel(
118 action.shortcut().toString())
119 label.setAlignment(Qt.AlignmentFlag.AlignHCenter)
120 buttonLayout.addWidget(label)
121
122 self.hbox.addLayout(buttonLayout)
123 self.tenbrushes.buttons.append(button)
static Krita * instance()
instance retrieve the singleton instance of the Application object.
Definition Krita.cpp:390