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) ...@@ -87,7 +87,7 @@ install_pykrita_plugin(exportlayers)
#install_pykrita_plugin(highpass) #install_pykrita_plugin(highpass)
install_pykrita_plugin(tenbrushes) install_pykrita_plugin(tenbrushes)
install_pykrita_plugin(tenscripts) 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(quick_settings_docker)
install_pykrita_plugin(lastdocumentsdocker) install_pykrita_plugin(lastdocumentsdocker)
# install_pykrita_plugin(scriptdocker) # install_pykrita_plugin(scriptdocker)
......
# let's make a module from krita import DockWidgetFactory, DockWidgetFactoryBase
from .palette_docker import * from .palette_docker import PaletteDocker
Application.addDockWidgetFactory(
DockWidgetFactory("palette_docker", DockWidgetFactoryBase.DockRight,
PaletteDocker))
''' # A script that converts the palette with the given name to a gimp
A script that converts the palette with the given name to a gimp palette at the location asked for. # 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: # Importing the relevant dependencies:
import sys
from PyQt5.QtWidgets import QFileDialog, QMessageBox from PyQt5.QtWidgets import QFileDialog, QMessageBox
import math from krita import Palette
from krita import *
class gimpPaletteExporter: class gimpPaletteExporter:
...@@ -35,7 +36,9 @@ class gimpPaletteExporter: ...@@ -35,7 +36,9 @@ class gimpPaletteExporter:
self.export() self.export()
done = QMessageBox() done = QMessageBox()
done.setWindowTitle(i18n("Export Successful")) 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_() done.exec_()
pass pass
...@@ -43,9 +46,9 @@ class gimpPaletteExporter: ...@@ -43,9 +46,9 @@ class gimpPaletteExporter:
# open the appropriate file... # open the appropriate file...
gplFile = open(self.fileName + "/" + self.paletteName + ".gpl", "w") gplFile = open(self.fileName + "/" + self.paletteName + ".gpl", "w")
gplFile.write("GIMP Palette\n") gplFile.write("GIMP Palette\n")
gplFile.write("Name: " + self.paletteName + "\n") gplFile.write("Name: %s\n" % self.paletteName)
gplFile.write("Columns: " + str(self.currentPalette.columnCount()) + "\n") gplFile.write("Columns: %s/n", self.currentPalette.columnCount())
gplFile.write("#" + self.currentPalette.comment() + "\n") gplFile.write("#%s\n" % self.currentPalette.comment())
colorCount = self.currentPalette.colorsCountGroup("") colorCount = self.currentPalette.colorsCountGroup("")
for i in range(colorCount): for i in range(colorCount):
...@@ -57,17 +60,27 @@ class gimpPaletteExporter: ...@@ -57,17 +60,27 @@ class gimpPaletteExporter:
red = max(min(int(color.componentsOrdered()[0] * 255), 255), 0) red = max(min(int(color.componentsOrdered()[0] * 255), 255), 0)
green = max(min(int(color.componentsOrdered()[1] * 255), 255), 0) green = max(min(int(color.componentsOrdered()[1] * 255), 255), 0)
blue = max(min(int(color.componentsOrdered()[2] * 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() groupNames = self.currentPalette.groupNames()
for groupName in groupNames: for groupName in groupNames:
colorCount = self.currentPalette.colorsCountGroup(groupName) colorCount = self.currentPalette.colorsCountGroup(groupName)
for i in range(colorCount): for i in range(colorCount):
entry = self.currentPalette.colorSetEntryFromGroup(i, groupName) entry = self.currentPalette.colorSetEntryFromGroup(
i, groupName)
color = self.currentPalette.colorForEntry(entry) color = self.currentPalette.colorForEntry(entry)
# convert to sRGB # convert to sRGB
color.setColorSpace("RGBA", "U8", "sRGB built-in") color.setColorSpace("RGBA", "U8", "sRGB built-in")
red = max(min(int(color.componentsOrdered()[0] * 255), 255), 0) red = max(
green = max(min(int(color.componentsOrdered()[1] * 255), 255), 0) min(int(color.componentsOrdered()[0] * 255), 255), 0)
blue = max(min(int(color.componentsOrdered()[2] * 255), 255), 0) green = max(
gplFile.write(str(red) + " " + str(green) + " " + str(blue) + " " + entry.id() + "-" + entry.name() + "\n") 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() 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
'''
from krita import Palette
# Importing the relevant dependencies:
from krita import *
class sortColors(object): class sortColors(object):
...@@ -37,39 +37,41 @@ class sortColors(object): ...@@ -37,39 +37,41 @@ class sortColors(object):
self.sort_color_by_name(groupName) self.sort_color_by_name(groupName)
def sort_color_by_name(self, groupName): def sort_color_by_name(self, groupName):
l = {} d = {}
colorCount = self.currentPalette.colorsCountGroup(groupName) colorCount = self.currentPalette.colorsCountGroup(groupName)
for i in range(colorCount - 1, -1, -1): for i in range(colorCount - 1, -1, -1):
entry = self.currentPalette.colorSetEntryFromGroup((i), groupName) entry = self.currentPalette.colorSetEntryFromGroup((i), groupName)
l[entry.name + str(i)] = entry d[entry.name + str(i)] = entry
self.currentPalette.removeEntry((i), groupName) self.currentPalette.removeEntry((i), groupName)
for s in sorted(l): for s in sorted(d):
self.currentPalette.addEntry(l[s], groupName) self.currentPalette.addEntry(d[s], groupName)
def sort_color_by_id(self, groupName): def sort_color_by_id(self, groupName):
l = {} d = {}
colorCount = self.currentPalette.colorsCountGroup(groupName) colorCount = self.currentPalette.colorsCountGroup(groupName)
for i in range(colorCount - 1, -1, -1): for i in range(colorCount - 1, -1, -1):
entry = self.currentPalette.colorSetEntryFromGroup((i), groupName) entry = self.currentPalette.colorSetEntryFromGroup((i), groupName)
l[entry.id() + " " + str(i)] = entry d[entry.id() + " " + str(i)] = entry
self.currentPalette.removeEntry((i), groupName) self.currentPalette.removeEntry((i), groupName)
for s in sorted(l): for s in sorted(d):
self.currentPalette.addEntry(l[s], groupName) self.currentPalette.addEntry(d[s], groupName)
def sort_by_value(self, groupName): def sort_by_value(self, groupName):
l = {} d = {}
colorCount = self.currentPalette.colorsCountGroup(groupName) colorCount = self.currentPalette.colorsCountGroup(groupName)
for i in range(colorCount - 1, -1, -1): for i in range(colorCount - 1, -1, -1):
entry = self.currentPalette.colorSetEntryFromGroup((i), groupName) entry = self.currentPalette.colorSetEntryFromGroup((i), groupName)
color = self.currentPalette.colorForEntry(entry) color = self.currentPalette.colorForEntry(entry)
color.setColorSpace("RGBA", "U8", "sRGB built-in") 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) self.currentPalette.removeEntry((i), groupName)
for s in sorted(l): for s in sorted(d):
self.currentPalette.addEntry(l[s], groupName) self.currentPalette.addEntry(d[s], groupName)
def sort_by_hue(self, stepsize, groupName): def sort_by_hue(self, stepsize, groupName):
pass 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