Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix and re-enable Python Palette Docker
Freya Lupene45f39431591
diff --git a/plugins/python/CMakeLists.txt b/plugins/python/CMakeLists.txtindex 7dcac0234c..4260fa1fdd 100644--- a/plugins/python/CMakeLists.txt+++ b/plugins/python/CMakeLists.txt@@ -68,7 +68,7 @@ install_pykrita_plugin(batch_exporter)#install_pykrita_plugin(highpass)install_pykrita_plugin(tenbrushes)install_pykrita_plugin(tenscripts)-#install_pykrita_plugin(palette_docker) # Needs fixing -> bug 405194+install_pykrita_plugin(palette_docker)install_pykrita_plugin(quick_settings_docker)install_pykrita_plugin(lastdocumentsdocker)# install_pykrita_plugin(scriptdocker)diff --git a/plugins/python/palette_docker/palette_docker.py b/plugins/python/palette_docker/palette_docker.pyindex 6a618ffd91..916ab0e702 100644--- a/plugins/python/palette_docker/palette_docker.py+++ b/plugins/python/palette_docker/palette_docker.py@@ -10,6 +10,7 @@# Importing the relevant dependencies:try:+ from PyQt6.QtGui import QPixmap, QIcon, QPainter, QBrush, QPalettefrom PyQt6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QComboBox, QTabWidget,QLineEdit, QSpinBox, QDialogButtonBox, QToolButton, QDialog,@@ -17,6 +18,7 @@ try:from PyQt6.QtCore import Qt, pyqtSlotfrom PyQt6.QtGui import QActionexcept:+ from PyQt5.QtGui import QPixmap, QIcon, QPainter, QBrush, QPalettefrom PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QComboBox, QAction, QTabWidget,QLineEdit, QSpinBox, QDialogButtonBox, QToolButton, QDialog,@@ -115,7 +117,7 @@ class PaletteDocker(DockWidget):self.actionMenu.addAction(self.editPaletteData)self.actionMenu.addAction(self.exportToGimp)self.actionMenu.addAction(self.exportToInkscape)- # self.actionMenu.addAction(self.sortColors)+ self.actionMenu.addAction(self.sortColors)self.extra.setMenu(self.actionMenu)@@ -131,18 +133,18 @@ class PaletteDocker(DockWidget):self.paletteView.setPalette(self.currentPalette)self.slot_fill_combobox()- @pyqtSlot('KisSwatch')+ @pyqtSlot('Swatch')def slot_swatchSelected(self, entry):if (self.canvas()) is not None:if (self.canvas().view()) is not None:name = entry.name()- if len(entry.id) > 0:+ if len(entry.id()) > 0:name = entry.id() + " - " + entry.name()if len(name) > 0:if name in self.colorList:self.colorComboBox.setCurrentIndex(self.colorList.index(name))- color = self.currentPalette.colorForEntry(entry)+ color = entry.color()self.canvas().view().setForeGroundColor(color)def slot_fill_combobox(self):@@ -154,43 +156,43 @@ class PaletteDocker(DockWidget):'''if self.currentPalette is None:- pass+ returnself.colorComboBox.clear()self.colorList = list()-# palette = self.currentPalette-# for info in palette.infoList():-# entry = info.swatch-# color = palette.colorForEntry(entry).colorForCanvas(self.canvas())-# colorSquare = QPixmap(12, 12)-# if entry.spotColor() is True:-# img = colorSquare.toImage()-# circlePainter = QPainter()-# img.fill(self.colorComboBox.palette().color(QPalette.ColorRole.Base))-# circlePainter.begin(img)-# brush = QBrush(Qt.BrushStyle.SolidPattern)-# brush.setColor(color)-# circlePainter.setBrush(brush)-# circlePainter.pen().setWidth(0)-# circlePainter.drawEllipse(0, 0, 11, 11)-# circlePainter.end()-# colorSquare = QPixmap.fromImage(img)-# else:-# colorSquare.fill(color)-# name = entry.name()-# if len(entry.id()) > 0:-# name = entry.id() + " - " + entry.name()-# self.colorList.append(name)-# self.colorComboBox.addItem(QIcon(colorSquare), name)+ palette = self.currentPalette+ for i in range(palette.colorsCountTotal()):+ entry = palette.entryByIndex(i)+ color = entry.color().colorForCanvas(self.canvas())+ colorSquare = QPixmap(12, 12)+ if entry.spotColor() is True:+ img = colorSquare.toImage()+ circlePainter = QPainter()+ img.fill(self.colorComboBox.palette().color(QPalette.ColorRole.Base))+ circlePainter.begin(img)+ brush = QBrush(Qt.BrushStyle.SolidPattern)+ brush.setColor(color)+ circlePainter.setBrush(brush)+ circlePainter.pen().setWidth(0)+ circlePainter.drawEllipse(0, 0, 11, 11)+ circlePainter.end()+ colorSquare = QPixmap.fromImage(img)+ else:+ colorSquare.fill(color)+ name = entry.name()+ if len(entry.id()) > 0:+ name = entry.id() + " - " + entry.name()+ self.colorList.append(name)+ self.colorComboBox.addItem(QIcon(colorSquare), name)self.colorComboBox.setEditable(True)self.colorComboBox.setInsertPolicy(QComboBox.InsertPolicy.NoInsert)self.colorComboBox.completer().setCompletionMode(QCompleter.CompletionMode.PopupCompletion)- self.colorComboBox.completer().setCaseSensitivity(False)+ self.colorComboBox.completer().setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)self.colorComboBox.completer().setFilterMode(Qt.MatchFlag.MatchContains)def slot_get_color_from_combobox(self):if self.currentPalette is not None:- entry = self.currentPalette.colorSetEntryByIndex(+ entry = self.currentPalette.entryByIndex(self.colorComboBox.currentIndex())self.slot_swatchSelected(entry)diff --git a/plugins/python/palette_docker/palette_exporter_gimppalette.py b/plugins/python/palette_docker/palette_exporter_gimppalette.pyindex 7c1abd6a33..b393b813e6 100644--- a/plugins/python/palette_docker/palette_exporter_gimppalette.py+++ b/plugins/python/palette_docker/palette_exporter_gimppalette.py@@ -38,40 +38,22 @@ class gimpPaletteExporter:gplFile = open(self.fileName + "/" + self.paletteName + ".gpl", "w")gplFile.write("GIMP Palette\n")gplFile.write("Name: %s\n" % self.paletteName)- gplFile.write("Columns: %s/n", self.currentPalette.columnCount())+ gplFile.write("Columns: %s\n" % self.currentPalette.columnCount())gplFile.write("#%s\n" % self.currentPalette.comment())- colorCount = self.currentPalette.colorsCountGroup("")- for i in range(colorCount):- entry = self.currentPalette.colorSetEntryFromGroup(i, "")- color = self.currentPalette.colorForEntry(entry)- # convert to sRGB- color.setColorSpace("RGBA", "U8", "sRGB built-in")-- red = max(min(int(color.componentsOrdered()[0] * 255), 255), 0)- green = max(min(int(color.componentsOrdered()[1] * 255), 255), 0)- blue = max(min(int(color.componentsOrdered()[2] * 255), 255), 0)- gplFile.write(- "{red} {green} {blue} {id}-{name}\n".format(- red=red, green=green, blue=blue, id=entry.id(),- name=entry.name))- groupNames = self.currentPalette.groupNames()- for groupName in groupNames:- colorCount = self.currentPalette.colorsCountGroup(groupName)- for i in range(colorCount):- entry = self.currentPalette.colorSetEntryFromGroup(- i, groupName)- color = self.currentPalette.colorForEntry(entry)- # convert to sRGB- color.setColorSpace("RGBA", "U8", "sRGB built-in")- red = max(- min(int(color.componentsOrdered()[0] * 255), 255), 0)- green = max(- min(int(color.componentsOrdered()[1] * 255), 255), 0)- blue = max(- min(int(color.componentsOrdered()[2] * 255), 255), 0)- gplFile.write(- "{red} {green} {blue} {id}-{name}\n".format(- red=red, green=green, blue=blue, id=entry.id(),- name=entry.name))+ groupNames = self.currentPalette.groupNames()+ for groupName in groupNames:+ colorCount = self.currentPalette.colorsCountGroup(groupName)+ for i in range(colorCount):+ entry = self.currentPalette.entryByIndexFromGroup(i, groupName)+ color = entry.color()+ # convert to sRGB+ color.setColorSpace("RGBA", "U8", "sRGB built-in")+ red = max(min(int(color.componentsOrdered()[0] * 255), 255), 0)+ green = max(min(int(color.componentsOrdered()[1] * 255), 255), 0)+ blue = max(min(int(color.componentsOrdered()[2] * 255), 255), 0)+ name = f"{entry.id()}-{entry.name()}" if entry.id() else entry.name()+ gplFile.write(+ "{red:>3} {green:>3} {blue:>3} {name}\n".format(+ red=red, green=green, blue=blue, name=name))gplFile.close()diff --git a/plugins/python/palette_docker/palette_exporter_inkscapeSVG.py b/plugins/python/palette_docker/palette_exporter_inkscapeSVG.pyindex b2b7122585..6dd4f3f34e 100644--- a/plugins/python/palette_docker/palette_exporter_inkscapeSVG.py+++ b/plugins/python/palette_docker/palette_exporter_inkscapeSVG.py@@ -75,72 +75,20 @@ class inkscapeSVGExporter:Column = 0iccProfileList = []- colorCount = self.currentPalette.colorsCountGroup("")-- for i in range(colorCount):- entry = self.currentPalette.colorSetEntryFromGroup(i, "")- color = self.currentPalette.colorForEntry(entry)-- iccColor = "icc-color(" + color.colorProfile()- for c in range(len(color.componentsOrdered()) - 1):- iccColor = "{col},{c}".format(- col=iccColor, c=color.componentsOrdered()[c])- iccColor = iccColor + ")"- if color.colorProfile() not in iccProfileList:- iccProfileList.append(color.colorProfile())-- # convert to sRGB- color.setColorSpace("RGBA", "U8", "sRGB built-in")- red = max(min(int(color.componentsOrdered()[0] * 255), 255), 0)- green = max(min(int(color.componentsOrdered()[1] * 255), 255), 0)- blue = max(min(int(color.componentsOrdered()[2] * 255), 255), 0)- hexcode = "#{red:02x}{green:02x}{blue:02x}".format(- red=red, green=green, blue=blue)- swatchName = "{i}-{name}".format(i=i, name=entry.name())- swatchName = swatchName.replace(" ", "-")- swatchName = swatchName.replace("(", "-")- swatchName = swatchName.replace(")", "-")- swatchMain = svgDoc.createElement("linearGradient")- swatchMain.setAttribute("osb:paint", "solid")- swatchMain.setAttribute("id", swatchName)- swatchSub = svgDoc.createElement("stop")- swatchSub.setAttribute(- "style",- "stop-color: {hex} {color};stop-opacity:1;".format(- hex=hexcode, color=iccColor))- swatchMain.appendChild(swatchSub)- svgDefs.appendChild(swatchMain)- svgSingleSwatch = svgDoc.createElement("rect")- svgSingleSwatch.setAttribute("x", str(int(Column * 20)))- svgSingleSwatch.setAttribute("y", str(int(Row * 20)))- svgSingleSwatch.setAttribute("width", str(int(20)))- svgSingleSwatch.setAttribute("height", str(int(20)))- svgSingleSwatch.setAttribute("fill", "url(#%s)" % swatchName)- svgSingleSwatch.setAttribute("id", "swatch %s" % swatchName)- if entry.spotColor() is True:- svgSingleSwatch.setAttribute("rx", str(10))- svgSingleSwatch.setAttribute("ry", str(10))- svgSwatches.appendChild(svgSingleSwatch)- Column += 1- if (Column >= self.currentPalette.columnCount()):- Column = 0- Row += 1-groupNames = self.currentPalette.groupNames()for groupName in groupNames:Column = 0- Row += 1groupTitle = svgDoc.createElement("text")- groupTitle.setAttribute("x", str(int(Column * 20)))- groupTitle.setAttribute("y", str(int(Row * 20) + 15))+ groupTitle.setAttribute("x", str(Column * 20))+ groupTitle.setAttribute("y", str(Row * 20 + 15))groupTitle.appendChild(svgDoc.createTextNode(groupName))svgSwatches.appendChild(groupTitle)Row += 1colorCount = self.currentPalette.colorsCountGroup(groupName)for i in range(colorCount):- entry = self.currentPalette.colorSetEntryFromGroup(+ entry = self.currentPalette.entryByIndexFromGroup(i, groupName)- color = self.currentPalette.colorForEntry(entry)+ color = entry.color()iccColor = "icc-color(" + color.colorProfile()for c in range(len(color.componentsOrdered()) - 1):iccColor = "{col},{c}".format(@@ -150,15 +98,12 @@ class inkscapeSVGExporter:iccProfileList.append(color.colorProfile())# convert to sRGBcolor.setColorSpace("RGBA", "U8", "sRGB built-in")- red = max(- min(int(color.componentsOrdered()[0] * 255), 255), 0)- green = max(- min(int(color.componentsOrdered()[1] * 255), 255), 0)- blue = max(- min(int(color.componentsOrdered()[2] * 255), 255), 0)+ red = max(min(int(color.componentsOrdered()[0] * 255), 255), 0)+ green = max(min(int(color.componentsOrdered()[1] * 255), 255), 0)+ blue = max(min(int(color.componentsOrdered()[2] * 255), 255), 0)hexcode = "#{red:02x}{green:02x}{blue:02x}".format(red=red, green=green, blue=blue)- swatchName = groupName + str(i) + "-" + entry.name()+ swatchName = "{i}-{name}".format(i=i, name=entry.name())swatchName = swatchName.replace(" ", "-")swatchName = swatchName.replace("(", "-")swatchName = swatchName.replace(")", "-")@@ -174,10 +119,10 @@ class inkscapeSVGExporter:swatchMain.appendChild(swatchSub)svgDefs.appendChild(swatchMain)svgSingleSwatch = svgDoc.createElement("rect")- svgSingleSwatch.setAttribute("x", str(int(Column * 20)))- svgSingleSwatch.setAttribute("y", str(int(Row * 20)))- svgSingleSwatch.setAttribute("width", str(int(20)))- svgSingleSwatch.setAttribute("height", str(int(20)))+ svgSingleSwatch.setAttribute("x", str(Column * 20))+ svgSingleSwatch.setAttribute("y", str(Row * 20))+ svgSingleSwatch.setAttribute("width", str(20))+ svgSingleSwatch.setAttribute("height", str(20))svgSingleSwatch.setAttribute("fill", "url(#%s)" % swatchName)svgSingleSwatch.setAttribute("id", "swatch %s" % swatchName)if entry.spotColor() is True:@@ -188,6 +133,7 @@ class inkscapeSVGExporter:if (Column >= self.currentPalette.columnCount()):Column = 0Row += 1+ Row += 1for profile in iccProfileList:svgProfileDesc = svgDoc.createElement("color-profile")@@ -204,7 +150,7 @@ class inkscapeSVGExporter:"viewBox","0 0 {cols} {row}".format(cols=self.currentPalette.columnCount() * 20,- row=int((Row + 1) * 20)))+ row=Row * 20))svgDoc.appendChild(svgBaseElement)svgFile.write(svgDoc.toString())svgFile.close()diff --git a/plugins/python/palette_docker/palette_sortColors.py b/plugins/python/palette_docker/palette_sortColors.pyindex 79306c0c0a..b62327f31d 100644--- a/plugins/python/palette_docker/palette_sortColors.py+++ b/plugins/python/palette_docker/palette_sortColors.py@@ -28,8 +28,8 @@ class sortColors(object):d = {}colorCount = self.currentPalette.colorsCountGroup(groupName)for i in range(colorCount - 1, -1, -1):- entry = self.currentPalette.colorSetEntryFromGroup((i), groupName)- d[entry.name + str(i)] = entry+ entry = self.currentPalette.entryByIndexFromGroup((i), groupName)+ d[entry.name() + str(i)] = entryself.currentPalette.removeEntry((i), groupName)for s in sorted(d):@@ -39,7 +39,7 @@ class sortColors(object):d = {}colorCount = self.currentPalette.colorsCountGroup(groupName)for i in range(colorCount - 1, -1, -1):- entry = self.currentPalette.colorSetEntryFromGroup((i), groupName)+ entry = self.currentPalette.entryByIndexFromGroup((i), groupName)d[entry.id() + " " + str(i)] = entryself.currentPalette.removeEntry((i), groupName)@@ -50,8 +50,8 @@ class sortColors(object):d = {}colorCount = self.currentPalette.colorsCountGroup(groupName)for i in range(colorCount - 1, -1, -1):- entry = self.currentPalette.colorSetEntryFromGroup((i), groupName)- color = self.currentPalette.colorForEntry(entry)+ entry = self.currentPalette.entryByIndexFromGroup((i), groupName)+ color = entry.color()color.setColorSpace("RGBA", "U8", "sRGB built-in")d[color.components()[0] +color.components()[1] +