13 from PyQt6.QtGui import QPixmap, QIcon, QPainter, QBrush, QPalette
15 QWidget, QVBoxLayout, QHBoxLayout, QComboBox, QTabWidget,
16 QLineEdit, QSpinBox, QDialogButtonBox, QToolButton, QDialog,
17 QPlainTextEdit, QCompleter, QMenu)
21 from PyQt5.QtGui import QPixmap, QIcon, QPainter, QBrush, QPalette
23 QWidget, QVBoxLayout, QHBoxLayout, QComboBox, QAction, QTabWidget,
24 QLineEdit, QSpinBox, QDialogButtonBox, QToolButton, QDialog,
25 QPlainTextEdit, QCompleter, QMenu)
26 from PyQt5.Qt
import Qt, pyqtSlot
27from krita
import DockWidget, Palette, PaletteView
28from builtins
import i18n, i18nc, Application
32 palette_exporter_gimppalette,
33 palette_exporter_inkscapeSVG,
42 super(PaletteDocker, self).
__init__()
45 layout = QVBoxLayout()
46 buttonLayout = QHBoxLayout()
47 widget.setLayout(layout)
48 self.setWindowTitle(i18n(
"Python Palette Docker"))
52 allPalettes = Application.resources(
"palette")
53 for palette_name
in allPalettes:
57 if len(allPalettes.keys()) > 0:
83 self.
addGroup.setText(i18nc(
"Group as Color Group in a Palette",
"Add Group"))
84 self.
addGroup.setIconText(str(
"\U0001F4C2"))
89 addEntryButton = QToolButton()
90 addEntryButton.setDefaultAction(self.
addEntry)
91 buttonLayout.addWidget(addEntryButton)
92 addGroupButton = QToolButton()
93 addGroupButton.setDefaultAction(self.
addGroup)
94 buttonLayout.addWidget(addGroupButton)
95 removeEntryButton = QToolButton()
96 removeEntryButton.setDefaultAction(self.
removeEntry)
97 buttonLayout.addWidget(removeEntryButton)
105 buttonLayout.addWidget(self.
extra)
108 self.
exportToGimp.setText(i18n(
"Export as GIMP Palette File"))
112 i18n(
"Export as Inkscape SVG with Swatches"))
125 layout.addLayout(buttonLayout)
127 self.setWidget(widget)
130 allPalettes = Application.resources(
"palette")
131 if len(allPalettes) > 0
and name
in allPalettes:
133 Application.resources(
"palette")[name])
139 if (self.canvas())
is not None:
140 if (self.canvas().view())
is not None:
142 if len(entry.id()) > 0:
143 name = entry.id() +
" - " + entry.name()
148 color = entry.color()
149 self.canvas().view().setForeGroundColor(color)
152 '''A function for making a combobox with the available colors. We use
153 QCompleter on the colorComboBox so that people can type in the
154 name of a color to select it. This is useful for people with
155 carefully made palettes where the colors are named properly,
156 which makes it easier for them to find colors.
164 for i
in range(palette.colorsCountTotal()):
165 entry = palette.entryByIndex(i)
166 color = entry.color().colorForCanvas(self.canvas())
167 colorSquare = QPixmap(12, 12)
168 if entry.spotColor()
is True:
169 img = colorSquare.toImage()
170 circlePainter = QPainter()
172 circlePainter.begin(img)
173 brush = QBrush(Qt.BrushStyle.SolidPattern)
174 brush.setColor(color)
175 circlePainter.setBrush(brush)
176 circlePainter.pen().setWidth(0)
177 circlePainter.drawEllipse(0, 0, 11, 11)
179 colorSquare = QPixmap.fromImage(img)
181 colorSquare.fill(color)
183 if len(entry.id()) > 0:
184 name = entry.id() +
" - " + entry.name()
188 self.
colorComboBox.setInsertPolicy(QComboBox.InsertPolicy.NoInsert)
190 QCompleter.CompletionMode.PopupCompletion)
191 self.
colorComboBox.completer().setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
192 self.
colorComboBox.completer().setFilterMode(Qt.MatchFlag.MatchContains)
201 if (self.canvas())
is not None:
202 if (self.canvas().view())
is not None:
203 color = self.canvas().view().foregroundColor()
204 success = self.
paletteView.addEntryWithDialog(color)
214 success = self.
paletteView.removeSelectedEntryWithDialog()
219 '''A function for giving a gui to edit palette metadata... I also
220 want this to be the way to edit the settings of the palette
224 dialog = QDialog(self)
225 tabWidget = QTabWidget()
226 dialog.setWindowTitle(i18n(
"Edit Palette Data"))
227 dialog.setLayout(QVBoxLayout())
228 dialog.layout().addWidget(tabWidget)
229 paletteWidget = QWidget()
230 paletteWidget.setLayout(QVBoxLayout())
231 tabWidget.addTab(paletteWidget, i18n(
"Palette Data"))
232 paletteName = QLineEdit()
234 paletteWidget.layout().addWidget(paletteName)
235 paletteColumns = QSpinBox()
237 paletteWidget.layout().addWidget(paletteColumns)
238 paletteComment = QPlainTextEdit()
240 paletteWidget.layout().addWidget(paletteComment)
241 buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok)
242 dialog.layout().addWidget(buttons)
243 buttons.accepted.connect(dialog.accept)
246 if dialog.exec() == QDialog.DialogCode.Accepted:
247 Resource = Application.resources(
"palette")[
272 allPalettes = Application.resources(
"palette")
273 for palette_name
in allPalettes:
void setName(QString value)
canvasChanged(self, canvas)
slot_export_to_inkscape_svg
slot_paletteChanged(self, name)
slot_export_to_gimp_palette
slot_edit_palette_data(self)
slot_export_to_inkscape_svg(self)
slot_swatchSelected(self, entry)
slot_get_color_from_combobox
slot_export_to_gimp_palette(self)
slot_get_color_from_combobox(self)
rgba palette[MAX_PALETTE]