Changeset View
Changeset View
Standalone View
Standalone View
plugins/python/tenbrushes/uitenbrushes.py
1 | ''' | 1 | # This script is licensed CC 0 1.0, so that you can learn from it. | ||
---|---|---|---|---|---|
2 | This script is licensed CC 0 1.0, so that you can learn from it. | | |||
3 | 2 | | |||
4 | ------ CC 0 1.0 --------------- | 3 | # ------ CC 0 1.0 --------------- | ||
5 | 4 | | |||
6 | The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. | 5 | # The person who associated a work with this deed has dedicated the | ||
6 | # work to the public domain by waiving all of his or her rights to the | ||||
7 | # work worldwide under copyright law, including all related and | ||||
8 | # neighboring rights, to the extent allowed by law. | ||||
7 | 9 | | |||
8 | You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. | 10 | # You can copy, modify, distribute and perform the work, even for | ||
11 | # commercial purposes, all without asking permission. | ||||
9 | 12 | | |||
10 | https://creativecommons.org/publicdomain/zero/1.0/legalcode | 13 | # https://creativecommons.org/publicdomain/zero/1.0/legalcode | ||
11 | ''' | 14 | | ||
12 | from PyQt5.QtCore import Qt, QSize | 15 | from PyQt5.QtCore import Qt | ||
13 | from PyQt5.QtGui import QPixmap, QIcon | 16 | from PyQt5.QtGui import QPixmap, QIcon | ||
14 | from PyQt5.QtWidgets import (QDialogButtonBox, QLabel, QVBoxLayout, QHBoxLayout, QCheckBox) | 17 | from PyQt5.QtWidgets import (QDialogButtonBox, QLabel, QVBoxLayout, | ||
18 | QHBoxLayout, QCheckBox) | ||||
15 | from . import tenbrushesdialog, dropbutton | 19 | from . import tenbrushesdialog, dropbutton | ||
16 | import krita | 20 | import krita | ||
17 | 21 | | |||
18 | 22 | | |||
19 | class UITenBrushes(object): | 23 | class UITenBrushes(object): | ||
20 | 24 | | |||
21 | def __init__(self): | 25 | def __init__(self): | ||
22 | self.kritaInstance = krita.Krita.instance() | 26 | self.kritaInstance = krita.Krita.instance() | ||
23 | self.mainDialog = tenbrushesdialog.TenBrushesDialog(self, self.kritaInstance.activeWindow().qwindow()) | 27 | self.mainDialog = tenbrushesdialog.TenBrushesDialog( | ||
28 | self, self.kritaInstance.activeWindow().qwindow()) | ||||
24 | 29 | | |||
25 | self.buttonBox = QDialogButtonBox(self.mainDialog) | 30 | self.buttonBox = QDialogButtonBox(self.mainDialog) | ||
26 | self.vbox = QVBoxLayout(self.mainDialog) | 31 | self.vbox = QVBoxLayout(self.mainDialog) | ||
27 | self.hbox = QHBoxLayout(self.mainDialog) | 32 | self.hbox = QHBoxLayout(self.mainDialog) | ||
28 | self.checkBox = QCheckBox(i18n("&Activate previous brush when pressing the shortcut for the second time"), self.mainDialog) | 33 | self.checkBox = QCheckBox( | ||
34 | i18n("&Activate previous brush when pressing the shortcut for the " | ||||
35 | "second time"), | ||||
36 | self.mainDialog) | ||||
29 | 37 | | |||
30 | self.buttonBox.accepted.connect(self.mainDialog.accept) | 38 | self.buttonBox.accepted.connect(self.mainDialog.accept) | ||
31 | self.buttonBox.rejected.connect(self.mainDialog.reject) | 39 | self.buttonBox.rejected.connect(self.mainDialog.reject) | ||
32 | 40 | | |||
33 | self.buttonBox.setOrientation(Qt.Horizontal) | 41 | self.buttonBox.setOrientation(Qt.Horizontal) | ||
34 | self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) | 42 | self.buttonBox.setStandardButtons( | ||
43 | QDialogButtonBox.Ok | QDialogButtonBox.Cancel) | ||||
35 | 44 | | |||
36 | self.presetChooser = krita.PresetChooser(self.mainDialog) | 45 | self.presetChooser = krita.PresetChooser(self.mainDialog) | ||
37 | 46 | | |||
38 | def initialize(self, tenbrushes): | 47 | def initialize(self, tenbrushes): | ||
39 | self.tenbrushes = tenbrushes | 48 | self.tenbrushes = tenbrushes | ||
40 | 49 | | |||
41 | self.loadButtons() | 50 | self.loadButtons() | ||
42 | 51 | | |||
43 | self.vbox.addLayout(self.hbox) | 52 | self.vbox.addLayout(self.hbox) | ||
44 | self.vbox.addWidget(QLabel(i18n("Select the brush preset, then click on the button you want to use to select the preset"))) | 53 | self.vbox.addWidget( | ||
54 | QLabel(i18n("Select the brush preset, then click on the button " | ||||
55 | "you want to use to select the preset"))) | ||||
45 | self.vbox.addWidget(self.presetChooser) | 56 | self.vbox.addWidget(self.presetChooser) | ||
46 | 57 | | |||
47 | self.checkBox.setChecked(self.tenbrushes.activatePrev) | 58 | self.checkBox.setChecked(self.tenbrushes.activatePrev) | ||
48 | self.checkBox.toggled.connect(self.setActivatePrev) | 59 | self.checkBox.toggled.connect(self.setActivatePrev) | ||
49 | self.vbox.addWidget(self.checkBox) | 60 | self.vbox.addWidget(self.checkBox) | ||
50 | 61 | | |||
51 | self.vbox.addWidget(self.buttonBox) | 62 | self.vbox.addWidget(self.buttonBox) | ||
52 | 63 | | |||
53 | self.mainDialog.show() | 64 | self.mainDialog.show() | ||
54 | self.mainDialog.activateWindow() | 65 | self.mainDialog.activateWindow() | ||
55 | self.mainDialog.exec_() | 66 | self.mainDialog.exec_() | ||
56 | 67 | | |||
57 | def setActivatePrev(self, checked): | 68 | def setActivatePrev(self, checked): | ||
58 | self.tenbrushes.activatePrev = checked | 69 | self.tenbrushes.activatePrev = checked | ||
59 | 70 | | |||
60 | def loadButtons(self): | 71 | def loadButtons(self): | ||
61 | self.tenbrushes.buttons = [] | 72 | self.tenbrushes.buttons = [] | ||
62 | 73 | | |||
63 | allPresets = Application.resources("preset") | 74 | allPresets = Application.resources("preset") | ||
64 | 75 | | |||
65 | for index, item in enumerate(['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']): | 76 | for index, item in enumerate(['1', '2', '3', '4', '5', | ||
77 | '6', '7', '8', '9', '0']): | ||||
66 | buttonLayout = QVBoxLayout() | 78 | buttonLayout = QVBoxLayout() | ||
67 | button = dropbutton.DropButton(self.mainDialog) | 79 | button = dropbutton.DropButton(self.mainDialog) | ||
68 | button.setObjectName(item) | 80 | button.setObjectName(item) | ||
69 | button.clicked.connect(button.selectPreset) | 81 | button.clicked.connect(button.selectPreset) | ||
70 | button.presetChooser = self.presetChooser | 82 | button.presetChooser = self.presetChooser | ||
71 | 83 | | |||
72 | if self.tenbrushes.actions[index] and self.tenbrushes.actions[index].preset and self.tenbrushes.actions[index].preset in allPresets: | 84 | action = self.tenbrushes.actions[index] | ||
73 | p = allPresets[self.tenbrushes.actions[index].preset] | 85 | | ||
86 | if action and action.preset and action.preset in allPresets: | ||||
87 | p = allPresets[action.preset] | ||||
74 | button.preset = p.name() | 88 | button.preset = p.name() | ||
75 | button.setIcon(QIcon(QPixmap.fromImage(p.image()))) | 89 | button.setIcon(QIcon(QPixmap.fromImage(p.image()))) | ||
76 | 90 | | |||
77 | buttonLayout.addWidget(button) | 91 | buttonLayout.addWidget(button) | ||
78 | 92 | | |||
79 | label = QLabel(self.tenbrushes.actions[index].shortcut().toString()) | 93 | label = QLabel( | ||
94 | action.shortcut().toString()) | ||||
80 | label.setAlignment(Qt.AlignHCenter) | 95 | label.setAlignment(Qt.AlignHCenter) | ||
81 | buttonLayout.addWidget(label) | 96 | buttonLayout.addWidget(label) | ||
82 | 97 | | |||
83 | self.hbox.addLayout(buttonLayout) | 98 | self.hbox.addLayout(buttonLayout) | ||
84 | self.tenbrushes.buttons.append(button) | 99 | self.tenbrushes.buttons.append(button) |