Krita Source Code Documentation
Loading...
Searching...
No Matches
palette_sortColors.py
Go to the documentation of this file.
1# A script that sorts the colors in the group.
2
3# By Wolthera(originally)
4
5# SPDX-License-Identifier: CC0-1.0
6
7# @package palette_docker
8
9from krita import Palette
10from builtins import Application
11
12
13class sortColors(object):
14
15 def __init__(self, name):
16 # We want people to select a palette...
17 allPalettes = Application.resources("palette")
18 self.paletteName = name
19 self.currentPalette = Palette(allPalettes[self.paletteName])
20 self.sort_all_groups()
21
22 def sort_all_groups(self):
23 groupNames = self.currentPalette.groupNames()
24 for groupName in groupNames:
25 self.sort_color_by_name(groupName)
26
27 def sort_color_by_name(self, groupName):
28 d = {}
29 slotCount = self.currentPalette.slotCountGroup(groupName)
30 for i in range(slotCount - 1, -1, -1):
31 entry = self.currentPalette.entryByIndexFromGroup((i), groupName)
32 if not entry.isValid():
33 continue
34 d[entry.name() + str(i)] = entry
35 self.currentPalette.removeEntryFromGroup((i), groupName)
36
37 for s in sorted(d):
38 self.currentPalette.addEntry(d[s], groupName)
39
40 def sort_color_by_id(self, groupName):
41 d = {}
42 slotCount = self.currentPalette.slotCountGroup(groupName)
43 for i in range(slotCount - 1, -1, -1):
44 entry = self.currentPalette.entryByIndexFromGroup((i), groupName)
45 if not entry.isValid():
46 continue
47 d[entry.id() + " " + str(i)] = entry
48 self.currentPalette.removeEntryFromGroup((i), groupName)
49
50 for s in sorted(d):
51 self.currentPalette.addEntry(d[s], groupName)
52
53 def sort_by_value(self, groupName):
54 d = {}
55 slotCount = self.currentPalette.slotCountGroup(groupName)
56 for i in range(slotCount - 1, -1, -1):
57 entry = self.currentPalette.entryByIndexFromGroup((i), groupName)
58 if not entry.isValid():
59 continue
60 color = entry.color()
61 color.setColorSpace("RGBA", "U8", "sRGB built-in")
62 d[color.components()[0] +
63 color.components()[1] +
64 color.components()[2]] = entry
65 self.currentPalette.removeEntryFromGroup((i), groupName)
66
67 for s in sorted(d):
68 self.currentPalette.addEntry(d[s], groupName)
69
70 def sort_by_hue(self, stepsize, groupName):
71 pass
72
73 def palette(self):
74 return self.currentPalette
rgba palette[MAX_PALETTE]
Definition palette.c:35