Class Palette
Build from Palette.h
+Krita 4.0.0↻Krita 6.0.0

The Palette class Palette is a resource object that stores organised color data. It's purpose is to allow artists to save colors and store them.

An example for printing all the palettes and the entries:

import sysfrom krita import *resources = Application.resources("palette")for (k, v) in resources.items(): print(k) palette = Palette(v) for x in range(palette.numberOfEntries()): entry = palette.colorSetEntryByIndex(x) print(x, entry.name(), entry.id(), entry.spotColor())

Methods

Palette(resource: Resource) addEntry(entry: Swatch, groupName: str = "") addGroup(name: str) changeGroupName(oldGroupName: str, newGroupName: str) colorSetEntryByIndex(index: int) ➞ Swatch colorSetEntryFromGroup(index: int, groupName: str) ➞ Swatch colorsCountGroup(name: str) ➞ int colorsCountTotal() ➞ int columnCount() ➞ int comment() ➞ str entryByIndex(index: int) ➞ Swatch entryByIndexFromGroup(index: int, groupName: str) ➞ Swatch groupNames() ➞ list[str] moveGroup(groupName: str, groupNameInsertBefore: str = "") numberOfEntries() ➞ int removeEntry(index: int) removeEntryFromGroup(index: int, groupName: str) removeGroup(name: str, keepColors: bool = True) renameGroup(oldGroupName: str, newGroupName: str) rowCount() ➞ int rowCountGroup(name: str) ➞ int save() ➞ bool setColumnCount(columns: int) setComment(comment: str) setRowCountGroup(rows: int, name: str) slotCount() ➞ int slotCountGroup(name: str) ➞ int

Member documentation

Palette(resource: Resource)
+Krita 4.0.0

Parameters

resource(no description provided)

Return

(no description provided)

addEntry(entry: Swatch, groupName: str = "")
+Krita 4.2.0↻Krita 6.0.0

add a color entry to a group. Color is appended to the end.

Parameters

entry

the entry

groupName

the name of the group to add to.

addGroup(name: str)
+Krita 4.0.0↻Krita 6.0.0

Palette content can be organized in groups. This method allows to add a new group in palette.

Parameters

name

The name of the new group to add.

changeGroupName(oldGroupName: str, newGroupName: str)
+Krita 4.0.0↻Krita 5.2.0⚠Krita 6.0.0

change the group name.

DEPRECATED: use `renameGroup()` instead

Parameters

oldGroupName

the old groupname to change.

newGroupName

the new name to change it into.

Return

whether successful. Reasons for failure include not knowing have oldGroupName

colorSetEntryByIndex(index: int) ➞ Swatch
+Krita 4.2.0⚠Krita 6.0.0

get the colorsetEntry from the global index.

DEPRECATED: use `entryByIndex()` instead

Parameters

index

the global index

Return

the colorset entry

colorSetEntryFromGroup(index: int, groupName: str) ➞ Swatch
+Krita 4.2.0⚠Krita 6.0.0

DEPRECATED: use `entryByIndexFromGroup()` instead

Parameters

index

index in the group.

groupName

the name of the group to get the color from.

Return

the colorsetentry.

colorsCountGroup(name: str) ➞ int
+Krita 4.0.0↻Krita 6.0.0

Parameters

name

of the group to check. Empty is the default group.

Return

the amount of filled colors within that group.

colorsCountTotal() ➞ int
+Krita 4.0.0↻Krita 6.0.0

number of filled colors (swatches) in palette NOTE: same as `numberOfEntries()`

Return

total number of colors

columnCount() ➞ int
+Krita 4.0.0↻Krita 6.0.0

Palettes are defined in grids. The number of column define grid width. The number of rows will depend of columns and total number of entries.

Return

the number of columns this palette is set to use.

comment() ➞ str
+Krita 4.0.0↻Krita 6.0.0

the comment or description associated with the palette.

Return

A string for which value contains the comment/description of palette.

entryByIndex(index: int) ➞ Swatch
+Krita 6.0.0

get color (swatch) from the global index.

Parameters

index

the global index

Return

The Swatch color for given index.

entryByIndexFromGroup(index: int, groupName: str) ➞ Swatch
+Krita 6.0.0

get color (swatch) from the given group index.

Parameters

index

index in the group.

groupName

the name of the group to get the color from.

Return

The Swatch color for given index within given group name.

groupNames() ➞ list[str]
+Krita 4.0.0↻Krita 6.0.0

Palette content can be organized in groups.

Return

The list of group names (list of string). This list follow the order the groups are defined in palette.

moveGroup(groupName: str, groupNameInsertBefore: str = "")
+Krita 4.0.0↻Krita 6.0.0

Move the group `groupName` to position before group `groupNameInsertBefore`.

Parameters

groupName

group to move.

groupNameInsertBefore

reference group for which `groupName` have to be moved before.

numberOfEntries() ➞ int
+Krita 4.0.0↻Krita 6.0.0

number of filled colors (swatches) in palette NOTE: same as `colorsCountTotal()`

Return

total number of colors

removeEntry(index: int)
+Krita 4.0.0↻Krita 6.0.0

Remove the color entry at the given index in this palette.

Parameters

index

index in this palette.

removeEntryFromGroup(index: int, groupName: str)
+Krita 6.0.0

Remove the color entry at the given index in the given group.

Parameters

index

index in the group.

groupName

the name of the group to remove the entry from.

removeGroup(name: str, keepColors: bool = True)
+Krita 4.0.0↻Krita 6.0.0

Palette content can be organized in groups. This method allows to remove an existing group from palette.

Parameters

name

The name of the group to remove.

keepColors

whether or not to delete all the colors inside, or to move them to the default group.

renameGroup(oldGroupName: str, newGroupName: str)
+Krita 6.0.0

rename a group

Parameters

oldGroupName

the old groupname to change.

newGroupName

the new name to change it into.

rowCount() ➞ int
+Krita 6.0.0

The number of rows in the palette grid. If the palette has groups, the row count is defined by the groups' row count. Otherwise, it's determined by the number of columns and entries.

Return

the number of rows this palette has.

rowCountGroup(name: str) ➞ int
+Krita 6.0.0

The number of rows defined in the given group.

Parameters

name

of the group to check.

Return

the number of rows this group is set to use.

save() ➞ bool
+Krita 4.0.0↻Krita 6.0.0

the palette

WARNING: this method does nothing and need to be implemented!

Return

always False

setColumnCount(columns: int)
+Krita 4.0.0↻Krita 6.0.0

Palettes are defined in grids. The number of column define grid width, this value can be defined. The number of rows will depend of columns and total number of entries.

Parameters

columns

Set the amount of columns this palette should use.

setComment(comment: str)
+Krita 4.0.0↻Krita 6.0.0

the comment or description associated with the palette.

Parameters

comment

set the comment or description associated with the palette.

setRowCountGroup(rows: int, name: str)
+Krita 6.0.0

Set the number of rows defined in the given group.

Parameters

rows

the amount of rows this group should use.

name

of the group to modify.

slotCount() ➞ int
+Krita 6.0.0

number of slots for swatches in palette This includes any empty slots not filled by a color.

Return

total number of slots

slotCountGroup(name: str) ➞ int
+Krita 6.0.0

number of slots for swatches in group This includes any empty slots not filled by a color.

Parameters

name

of the group to check. Empty is the default group.

Return

number of slots in group