Commit b1453b9d authored by Rebecca Breu's avatar Rebecca Breu

Python Palette Docker: Exclude from build + Code style fixes

* The Plugin is currently broken (Bug 405194), so I excluded it from the build
* Code style fixes
parent d77c51d6
......@@ -87,7 +87,7 @@ install_pykrita_plugin(exportlayers)
#install_pykrita_plugin(highpass)
install_pykrita_plugin(tenbrushes)
install_pykrita_plugin(tenscripts)
install_pykrita_plugin(palette_docker)
#install_pykrita_plugin(palette_docker) # Needs fixing -> bug 405194
install_pykrita_plugin(quick_settings_docker)
install_pykrita_plugin(lastdocumentsdocker)
# install_pykrita_plugin(scriptdocker)
......
# let's make a module
from .palette_docker import *
from krita import DockWidgetFactory, DockWidgetFactoryBase
from .palette_docker import PaletteDocker
Application.addDockWidgetFactory(
DockWidgetFactory("palette_docker", DockWidgetFactoryBase.DockRight,
PaletteDocker))
'''
Description: A Python based docker that allows you to edit KPL color palettes.
# Description: A Python based docker that allows you to edit KPL color
# palettes.
By Wolthera(originally)
# By Wolthera(originally)
This script is licensed CC 0 1.0, so that you can learn from it.
# This script is licensed CC 0 1.0, so that you can learn from it.
------ CC 0 1.0 ---------------
# ------ CC 0 1.0 ---------------
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.
# 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.
You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
# You can copy, modify, distribute and perform the work, even for
# commercial purposes, all without asking permission.
https://creativecommons.org/publicdomain/zero/1.0/legalcode
# https://creativecommons.org/publicdomain/zero/1.0/legalcode
# @package palette_docker
@package palette_docker
'''
# Importing the relevant dependencies:
import sys
from PyQt5.QtGui import QPixmap, QIcon, QImage, QPainter, QBrush, QPalette
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QComboBox, QAction, QTabWidget, QLineEdit, QSpinBox, QDialogButtonBox, QToolButton, QDialog, QPlainTextEdit, QCompleter, QMenu
from PyQt5.Qt import Qt, pyqtSignal, pyqtSlot
import math
from krita import *
from PyQt5.QtWidgets import (
QWidget, QVBoxLayout, QHBoxLayout, QComboBox, QAction, QTabWidget,
QLineEdit, QSpinBox, QDialogButtonBox, QToolButton, QDialog,
QPlainTextEdit, QCompleter, QMenu)
from PyQt5.Qt import Qt, pyqtSlot
from krita import DockWidget, Palette, PaletteView
# import the exporters
from . import palette_exporter_gimppalette, palette_exporter_inkscapeSVG, palette_sortColors
from . import (
palette_exporter_gimppalette,
palette_exporter_inkscapeSVG,
palette_sortColors,
)
class Palette_Docker(DockWidget):
class PaletteDocker(DockWidget):
# Init the docker
def __init__(self):
super(Palette_Docker, self).__init__()
super(PaletteDocker, self).__init__()
# make base-widget and layout
widget = QWidget()
layout = QVBoxLayout()
......@@ -48,7 +56,7 @@ class Palette_Docker(DockWidget):
self.cmb_palettes.model().sort(0)
if len(allPalettes.keys()) > 0:
self.currentPalette = Palette(allPalettes[list(allPalettes.keys())[0]])
self.currentPalette = Palette(list(allPalettes.values())[0])
else:
self.currentPalette = None
......@@ -57,7 +65,8 @@ class Palette_Docker(DockWidget):
self.paletteView = PaletteView()
self.paletteView.setPalette(self.currentPalette)
layout.addWidget(self.paletteView)
self.paletteView.entrySelectedForeGround.connect(self.slot_swatchSelected)
self.paletteView.entrySelectedForeGround.connect(
self.slot_swatchSelected)
self.colorComboBox = QComboBox()
self.colorList = list()
......@@ -100,8 +109,10 @@ class Palette_Docker(DockWidget):
self.exportToGimp.setText(i18n("Export as GIMP Palette File"))
self.exportToGimp.triggered.connect(self.slot_export_to_gimp_palette)
self.exportToInkscape = QAction(self)
self.exportToInkscape.setText(i18n("Export as Inkscape SVG with Swatches"))
self.exportToInkscape.triggered.connect(self.slot_export_to_inkscape_svg)
self.exportToInkscape.setText(
i18n("Export as Inkscape SVG with Swatches"))
self.exportToInkscape.triggered.connect(
self.slot_export_to_inkscape_svg)
self.sortColors = QAction(self)
self.sortColors.setText(i18n("Sort Colors"))
self.sortColors.triggered.connect(self.slot_sort_colors)
......@@ -119,7 +130,8 @@ class Palette_Docker(DockWidget):
def slot_paletteChanged(self, name):
allPalettes = Application.resources("palette")
if len(allPalettes) > 0 and name in allPalettes:
self.currentPalette = Palette(Application.resources("palette")[name])
self.currentPalette = Palette(
Application.resources("palette")[name])
self.paletteView.setPalette(self.currentPalette)
self.slot_fill_combobox()
......@@ -132,21 +144,24 @@ class Palette_Docker(DockWidget):
name = entry.id() + " - " + entry.name()
if len(name) > 0:
if name in self.colorList:
self.colorComboBox.setCurrentIndex(self.colorList.index(name))
self.colorComboBox.setCurrentIndex(
self.colorList.index(name))
color = self.currentPalette.colorForEntry(entry)
self.canvas().view().setForeGroundColor(color)
'''
A function for making a combobox with the available colors. We use QCompleter on the colorComboBox so that people
can type in the name of a color to select it. This is useful for people with carefully made palettes where the colors
are named properly, which makes it easier for them to find colors.
'''
def slot_fill_combobox(self):
'''A function for making a combobox with the available colors. We use
QCompleter on the colorComboBox so that people can type in the
name of a color to select it. This is useful for people with
carefully made palettes where the colors are named properly,
which makes it easier for them to find colors.
'''
if self.currentPalette is None:
pass
palette = self.currentPalette
self.colorComboBox.clear()
self.colorList = list()
# palette = self.currentPalette
# for info in palette.infoList():
# entry = info.swatch
# color = palette.colorForEntry(entry).colorForCanvas(self.canvas())
......@@ -172,14 +187,15 @@ class Palette_Docker(DockWidget):
# self.colorComboBox.addItem(QIcon(colorSquare), name)
self.colorComboBox.setEditable(True)
self.colorComboBox.setInsertPolicy(QComboBox.NoInsert)
self.colorComboBox.completer().setCompletionMode(QCompleter.PopupCompletion)
self.colorComboBox.completer().setCompletionMode(
QCompleter.PopupCompletion)
self.colorComboBox.completer().setCaseSensitivity(False)
self.colorComboBox.completer().setFilterMode(Qt.MatchContains)
def slot_get_color_from_combobox(self):
if self.currentPalette is not None:
entry = self.currentPalette.colorSetEntryByIndex(self.colorComboBox.currentIndex())
entry = self.currentPalette.colorSetEntryByIndex(
self.colorComboBox.currentIndex())
self.slot_swatchSelected(entry)
def slot_add_entry(self):
......@@ -200,12 +216,12 @@ class Palette_Docker(DockWidget):
if success is True:
self.slot_fill_combobox()
'''
A function for giving a gui to edit palette metadata... I also want this to be the way to edit the settings of the
palette docker.
def slot_edit_palette_data(self):
'''A function for giving a gui to edit palette metadata... I also
want this to be the way to edit the settings of the palette
docker.
'''
def slot_edit_palette_data(self):
dialog = QDialog(self)
tabWidget = QTabWidget()
dialog.setWindowTitle(i18n("Edit Palette Data"))
......@@ -229,7 +245,8 @@ class Palette_Docker(DockWidget):
# buttons.rejected.connect(dialog.reject())
if dialog.exec_() == QDialog.Accepted:
Resource = Application.resources("palette")[self.cmb_palettes.currentText()]
Resource = Application.resources("palette")[
self.cmb_palettes.currentText()]
Resource.setName(paletteName.text())
self.currentPalette = Palette(Resource)
self.currentPalette.setColumnCount(paletteColumns.value())
......@@ -239,13 +256,16 @@ class Palette_Docker(DockWidget):
self.currentPalette.save()
def slot_export_to_gimp_palette(self):
palette_exporter_gimppalette.gimpPaletteExporter(self.cmb_palettes.currentText())
palette_exporter_gimppalette.gimpPaletteExporter(
self.cmb_palettes.currentText())
def slot_export_to_inkscape_svg(self):
palette_exporter_inkscapeSVG.inkscapeSVGExporter(self.cmb_palettes.currentText())
palette_exporter_inkscapeSVG.inkscapeSVGExporter(
self.cmb_palettes.currentText())
def slot_sort_colors(self):
colorSorter = palette_sortColors.sortColors(self.cmb_palettes.currentText())
colorSorter = palette_sortColors.sortColors(
self.cmb_palettes.currentText())
self.paletteView.setPalette(colorSorter.palette())
def canvasChanged(self, canvas):
......@@ -255,8 +275,5 @@ class Palette_Docker(DockWidget):
self.cmb_palettes.addItem(palette_name)
self.cmb_palettes.model().sort(0)
if self.currentPalette == None and len(allPalettes.keys()) > 0:
self.currentPalette = Palette(allPalettes[list(allPalettes.keys())[0]])
# Add docker to the application :)
Application.addDockWidgetFactory(DockWidgetFactory("palette_docker", DockWidgetFactoryBase.DockRight, Palette_Docker))
if self.currentPalette is None and len(allPalettes.keys()) > 0:
self.currentPalette = Palette(list(allPalettes.values())[0])
'''
A script that converts the palette with the given name to a gimp palette at the location asked for.
# A script that converts the palette with the given name to a gimp
# palette at the location asked for.
By Wolthera(originally)
# By Wolthera(originally)
This script is licensed CC 0 1.0, so that you can learn from it.
# This script is licensed CC 0 1.0, so that you can learn from it.
------ CC 0 1.0 ---------------
# ------ CC 0 1.0 ---------------
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.
# 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.
You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
# You can copy, modify, distribute and perform the work, even for
# commercial purposes, all without asking permission.
https://creativecommons.org/publicdomain/zero/1.0/legalcode
# https://creativecommons.org/publicdomain/zero/1.0/legalcode
@package palette_docker
'''
# @package palette_docker
# Importing the relevant dependencies:
import sys
from PyQt5.QtWidgets import QFileDialog, QMessageBox
import math
from krita import *
from krita import Palette
class gimpPaletteExporter:
......@@ -35,7 +36,9 @@ class gimpPaletteExporter:
self.export()
done = QMessageBox()
done.setWindowTitle(i18n("Export Successful"))
done.setText(str(i18n("{input} has been exported to {output}.")).format(input=self.paletteName, output=self.fileName))
done.setText(
str(i18n("{input} has been exported to {output}.")).format(
input=self.paletteName, output=self.fileName))
done.exec_()
pass
......@@ -43,9 +46,9 @@ class gimpPaletteExporter:
# open the appropriate file...
gplFile = open(self.fileName + "/" + self.paletteName + ".gpl", "w")
gplFile.write("GIMP Palette\n")
gplFile.write("Name: " + self.paletteName + "\n")
gplFile.write("Columns: " + str(self.currentPalette.columnCount()) + "\n")
gplFile.write("#" + self.currentPalette.comment() + "\n")
gplFile.write("Name: %s\n" % self.paletteName)
gplFile.write("Columns: %s/n", self.currentPalette.columnCount())
gplFile.write("#%s\n" % self.currentPalette.comment())
colorCount = self.currentPalette.colorsCountGroup("")
for i in range(colorCount):
......@@ -57,17 +60,27 @@ class gimpPaletteExporter:
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(str(red) + " " + str(green) + " " + str(blue) + " " + entry.id() + "-" + entry.name() + "\n")
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)
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(str(red) + " " + str(green) + " " + str(blue) + " " + entry.id() + "-" + entry.name() + "\n")
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))
gplFile.close()
'''
A script that sorts the colors in the group.
# A script that sorts the colors in the group.
By Wolthera(originally)
# By Wolthera(originally)
This script is licensed CC 0 1.0, so that you can learn from it.
# This script is licensed CC 0 1.0, so that you can learn from it.
------ CC 0 1.0 ---------------
# ------ CC 0 1.0 ---------------
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.
# 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.
You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
# You can copy, modify, distribute and perform the work, even for
# commercial purposes, all without asking permission.
https://creativecommons.org/publicdomain/zero/1.0/legalcode
# https://creativecommons.org/publicdomain/zero/1.0/legalcode
@package palette_docker
'''
# @package palette_docker
# Importing the relevant dependencies:
from krita import *
from krita import Palette
class sortColors(object):
......@@ -37,39 +37,41 @@ class sortColors(object):
self.sort_color_by_name(groupName)
def sort_color_by_name(self, groupName):
l = {}
d = {}
colorCount = self.currentPalette.colorsCountGroup(groupName)
for i in range(colorCount - 1, -1, -1):
entry = self.currentPalette.colorSetEntryFromGroup((i), groupName)
l[entry.name + str(i)] = entry
d[entry.name + str(i)] = entry
self.currentPalette.removeEntry((i), groupName)
for s in sorted(l):
self.currentPalette.addEntry(l[s], groupName)
for s in sorted(d):
self.currentPalette.addEntry(d[s], groupName)
def sort_color_by_id(self, groupName):
l = {}
d = {}
colorCount = self.currentPalette.colorsCountGroup(groupName)
for i in range(colorCount - 1, -1, -1):
entry = self.currentPalette.colorSetEntryFromGroup((i), groupName)
l[entry.id() + " " + str(i)] = entry
d[entry.id() + " " + str(i)] = entry
self.currentPalette.removeEntry((i), groupName)
for s in sorted(l):
self.currentPalette.addEntry(l[s], groupName)
for s in sorted(d):
self.currentPalette.addEntry(d[s], groupName)
def sort_by_value(self, groupName):
l = {}
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)
color.setColorSpace("RGBA", "U8", "sRGB built-in")
l[color.components()[0] + color.components()[1] + color.components()[2]] = entry
d[color.components()[0] +
color.components()[1] +
color.components()[2]] = entry
self.currentPalette.removeEntry((i), groupName)
for s in sorted(l):
self.currentPalette.addEntry(l[s], groupName)
for s in sorted(d):
self.currentPalette.addEntry(d[s], groupName)
def sort_by_hue(self, stepsize, groupName):
pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment