OMC::Palette Class Reference

Detailed Description

Represents and provides the methods for a Palette in a project.

Behaves as a container list for Palette colour object types.

Palettes are referenced by ID and are accessible through the OMC::PaletteList object.
f

A Simple Example - Creating a new Palette in the project's PaletteList and adding a colour and a texture.

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette (it already comes with a default colour, with the name 'Default'):
new_palette_type = 'Colour'
new_palette_name = 'Colour_Palette_Name'
new_colour_palette = palette_list.create(new_palette_type,new_palette_name)
# Create a new solid red palette colour:
new_colour_name = 'Red_Colour'
newSolidRedPaletteColour = new_colour_palette.create_solid_colour(new_colour_name,[255,0,0,255])
# Create a new texture palette:
new_texture_file_path = r'.../pathToTexture/texture.png'
new_texture_name = 'Texture_Colour'
new_texture_palette_colour = new_colour_palette.create_texture(new_texture_file_path,new_texture_name)
# List palette contents:
for palette_colour in new_colour_palette:
print(palette_colour.name)
#Default
#Red_Colour
#Texture_Colour

Public Member Functions

OMC::PaletteListpalette_list ()
 Gets the parent PaletteList, or throws error if currently parentless. More...
 
OMC::Elementelement ()
 Retrieves the element object that owns the Palette, if the Palette is stored in an element. More...
 
void lock ()
 Try to obtain the database lock. The lock will be held until it is released in script or the ui. Safe to call multiple time to get the lock state. Throws error if unsuccessful. More...
 
void release ()
 Try to release the database lock. Release access to the Palette. Other users will be able to obtain the access rights to the Palette. Throws error if unsuccessful. More...
 
OMC::PaletteColourcreate_solid_colour (QString name, QVariant colourData=QVariant(), int index=-1)
 Create a new solid colour of a given type. More...
 
OMC::PaletteColourcreate_linear_gradient_colour (QString name=QString(), QVariant startColourData=QVariant(), float startPercentage=0.0f, QVariant endColourData=QVariant(), float endPercentage=100.0f, int index=-1)
 Create a new colour with linear gradient of a given type. More...
 
OMC::PaletteColourcreate_radial_gradient_colour (QString name=QString(), QVariant startColourData=QVariant(), float startPercentage=0.0f, QVariant endColourData=QVariant(), float endPercentage=100.0f, int index=-1)
 Create a new colour with radial gradient of a given type. More...
 
OMC::PaletteTexturecreate_texture (QString filePath, QString name=QString(), int index=-1, bool tiled=false)
 Create a new texture colour object. More...
 
OMC::PaletteBaseColourinsert (OMC::PaletteBaseColour *colour, int index, bool duplicate=false)
 Inserts an existing colour object to this Palette. If the pallete ID already exists on the list, it will requeire the moveType argument to be specified as "Clone" or "Duplicate". More...
 
OMC::PaletteBaseColourappend (OMC::PaletteBaseColour *colour, bool duplicate=false)
 Appends an existing colour object to the back of this Palette. If the pallete ID already exists on the list, it will require the duplicate paremeter to be true". More...
 
OMC::PaletteBaseColourpop (int index)
 Pops given index colour from the Palette. More...
 
void remove (OMC::PaletteBaseColour *colour)
 Removes colour from the Palette. Throws error if unsuccessful. More...
 
void reorder (OMC::PaletteBaseColour *colour, int index)
 Reorders the internal list by moving a the specified Palette id to the given index. Throws error if unsuccessful. More...
 
void clear ()
 Removes and deletes all colour objects from the Palette. Throws an error if failed to remove the colour. More...
 
void acquire (OMC::PaletteBaseColour *colorObj)
 Move a color to this Palette. Will remove the colour from its original Palette and move it to this one. Throws error if unsuccessful, e.g. if the colour is invalid or if this is the same Palette as the current PaletteBaseColour. If this Palette has a colour with the same colour ID as the source colour, it will return false also. More...
 
Array [QString] colour_names ()
 Lists the Palette colours and/or textures names. More...
 
bool contains (PaletteBaseColour *item)
 Identifies if the list contains the colour. More...
 
Array [OMC::PaletteBaseColour *] list ()
 Converts the dynamic list into a concrete list of PaletteBaseColour objects. More...
 

Public Attributes

QString path
 The path to the palette file, containing this palette, in system. More...
 
QString name
 The name of this Palette. The extension (".plt") is not included. More...
 
bool valid
 True if the Palette object is valid. More...
 
bool loaded
 True if the Palette was successfully loaded from the disk. More...
 
bool found
 True if the Palette was found at the location specified by the path and name. More...
 
QString type
 The type of the Palette, can be used to change the Palette type if it can be converted. More...
 
bool locked
 Whether the Palette is currently locally locked by the session, and can be modified. More...
 
QString id
 The ID of this Palette. More...
 
QString location
 The storage location of this Palette (e.g. Environment, Job, Scene, Element, External). More...
 
int element_id
 The element id in which the Palette is stored if location is ELEMENT. Returns None if the Palette is not stored in an element. More...
 
OMC::PaletteBaseColouroperator[int index]
 Provides the PaletteBaseColour object at the given index. More...
 

Member Function Documentation

◆ acquire()

void OMC::Palette::acquire ( OMC::PaletteBaseColour colorObj)

Move a color to this Palette. Will remove the colour from its original Palette and move it to this one. Throws error if unsuccessful, e.g. if the colour is invalid or if this is the same Palette as the current PaletteBaseColour. If this Palette has a colour with the same colour ID as the source colour, it will return false also.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create new colour palettes:
new_colour_palette_a = palette_list.create('Colour','A')
new_colour_palette_b = palette_list.create('Colour','B')
# Append new colours inside the palettes:
new_colour_at_a = new_colour_palette_a.create_solid_colour('Colour_A',[255,0,0])
new_colour_at_b = new_colour_palette_b.create_solid_colour('Colour_B',[0,255,0])
# Verifications before:
print(new_colour_palette_a.contains(new_colour_at_b)) # False
print(new_colour_palette_b.contains(new_colour_at_b)) # True
print(new_colour_palette_b.id == new_colour_at_b.palette().id) # True
# Acquire color from another palette:
new_colour_palette_a.acquire(new_colour_at_b)
# Verifications after:
print(new_colour_palette_a.contains(new_colour_at_b)) # True
print(new_colour_palette_b.contains(new_colour_at_b)) # False
print(new_colour_palette_a.id == new_colour_at_b.palette().id) # True

◆ append()

OMC::PaletteBaseColour* OMC::Palette::append ( OMC::PaletteBaseColour colour,
bool  duplicate = false 
)

Appends an existing colour object to the back of this Palette. If the pallete ID already exists on the list, it will require the duplicate paremeter to be true".

Returns
The appended PaletteBaseColour object, which the ID may differ form the input argument.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create new colour palettes:
new_colour_palette_a = palette_list.create('Colour','A')
new_colour_palette_b = palette_list.create('Colour','B')
# Append new colours inside the palettes:
new_colour_at_a = new_colour_palette_a.create_solid_colour('Colour_A',[255,0,0])
new_colour_at_b = new_colour_palette_b.create_solid_colour('Colour_B',[0,255,0])
new_colour_palette_a.append(new_colour_at_b,0) # append colour from another palette
new_duplicate_of_a = new_colour_palette_a.append(new_colour_at_a,True) # duplicate colour from the same palette
new_duplicate_of_a.name = 'Colour_A_duplicate'
# List palette colours:
for palette_colour in new_colour_palette_a:
print(palette_colour.name)
#Default
#Colour_A
#Colour_B
#Colour_A_duplicate

◆ clear()

void OMC::Palette::clear ( )

Removes and deletes all colour objects from the Palette. Throws an error if failed to remove the colour.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colours inside palette:
new_colour_a = new_colour_palette.create_solid_colour('Colour_A',[255,0,0])
new_colour_b = new_colour_palette.create_solid_colour('Colour_B',[255,255,0])
new_colour_c = new_colour_palette.create_solid_colour('Colour_C',[255,0,255])
print(new_colour_palette.size() == 4) # True
# Clear A:
new_colour_palette.clear()
print(new_colour_palette.size() == 0) # True
# List palette colours:
print(new_colour_palette.list()) #[]

◆ colour_names()

Array [QString] OMC::Palette::colour_names ( )

Lists the Palette colours and/or textures names.

Returns
Returns a list of the containing PaletteBaseColour names.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colours inside palette:
new_colour_palette.create_solid_colour('Colour_A',[255,0,0])
new_colour_palette.create_solid_colour('Colour_B',[255,255,0])
new_colour_palette.create_solid_colour('Colour_C',[255,0,255])
# List palette colours:
print(new_colour_palette.colour_names())
#['Default', 'Colour_A', 'Colour_B', 'Colour_C']

◆ contains()

bool OMC::Palette::contains ( PaletteBaseColour item)

Identifies if the list contains the colour.

Returns
Return true if contains, and false otherwise.

Examplified in acquire().

◆ create_linear_gradient_colour()

OMC::PaletteColour* OMC::Palette::create_linear_gradient_colour ( QString  name = QString(),
QVariant  startColourData = QVariant(),
float  startPercentage = 0.0f,
QVariant  endColourData = QVariant(),
float  endPercentage = 100.0f,
int  index = -1 
)

Create a new colour with linear gradient of a given type.

Returns
Returns a reference to the newly created Palette colour object.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette (it already comes with a default colour, with the name 'Default'):
new_palette_type = 'Colour'
new_palette_name = 'Colour_Palette_Name'
new_colour_palette = palette_list.create(new_palette_type,new_palette_name)
#Add colours to the Colour Palette
new_gradient = new_colour_palette.create_linear_gradient_colour("Red_To_Blue",[255,0,0,255],0,[0,0,255,255],100)
# List gradient colours:
for colour in new_gradient:
print("At: ",colour.position,"%, Colour is:",[colour.r,colour.g,colour.b])
#[255.0, 0.0, 0.0] # Red
#[0.0, 0.0, 255.0] # Blue

◆ create_radial_gradient_colour()

OMC::PaletteColour* OMC::Palette::create_radial_gradient_colour ( QString  name = QString(),
QVariant  startColourData = QVariant(),
float  startPercentage = 0.0f,
QVariant  endColourData = QVariant(),
float  endPercentage = 100.0f,
int  index = -1 
)

Create a new colour with radial gradient of a given type.

Returns
Returns a reference to the newly created Palette colour object.

Examplified in create_linear_gradient_colour() method. Where 'create_linear_gradient_colour()' becomes 'create_radial_gradient_colour()'.

◆ create_solid_colour()

OMC::PaletteColour* OMC::Palette::create_solid_colour ( QString  name,
QVariant  colourData = QVariant(),
int  index = -1 
)

Create a new solid colour of a given type.

Returns
Returns a reference to the newly created Palette colour object.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette (it already comes with a default colour, with the name 'Default'):
new_palette_type = 'Colour'
new_palette_name = 'Colour_Palette_Name'
new_colour_palette = palette_list.create(new_palette_type,new_palette_name)
#Add colours to the Colour Palette
new_colour_palette.create_solid_colour("Yellow",[255,255,0,255])
new_colour_palette.create_solid_colour("Magenta",harmony.Colour([255,0,255,255]),0)
# List palette colours:
for palette_colour in new_colour_palette:
print(palette_colour.name)
#Magenta
#Default
#Yellow

◆ create_texture()

OMC::PaletteTexture* OMC::Palette::create_texture ( QString  filePath,
QString  name = QString(),
int  index = -1,
bool  tiled = false 
)

Create a new texture colour object.

Returns
Returns a reference to the newly created Palette texture object.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette (it already comes with a default colour, with the name 'Default'):
new_palette_type = 'Colour'
new_palette_name = 'Colour_Palette_Name'
new_colour_palette = palette_list.create(new_palette_type,new_palette_name)
#Add a texture to the Colour Palette
new_texture_file_path = r'.../pathToTexture/texture.png'
new_texture_name = 'Texture_Colour'
new_texture_palette_colour = new_colour_palette.create_texture(new_texture_file_path,new_texture_name)
print(new_texture_palette_colour.name == new_texture_name) # True
print(new_texture_palette_colour.base_type == "Texture") # True

◆ element()

OMC::Element* OMC::Palette::element ( )

Retrieves the element object that owns the Palette, if the Palette is stored in an element.

Returns
Returns the element object on which this Palette is stored

Example:

from ToonBoom import harmony
palette_lists = harmony.session().project.palette_lists;
for palette_list in palette_lists:
for palette in palette_list:
if palette.element_id != -1:
print(palette.element().name) # Writes the element names associated with the respective palettes

◆ insert()

OMC::PaletteBaseColour* OMC::Palette::insert ( OMC::PaletteBaseColour colour,
int  index,
bool  duplicate = false 
)

Inserts an existing colour object to this Palette. If the pallete ID already exists on the list, it will requeire the moveType argument to be specified as "Clone" or "Duplicate".

Returns
Returns the inserted PaletteBaseColour object.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create new colour palettes:
new_colour_palette_a = palette_list.create('Colour','A')
new_colour_palette_b = palette_list.create('Colour','B')
# Insert new colours inside a palette:
new_colour_at_a = new_colour_palette_a.create_solid_colour('Colour_A',[255,0,0])
new_colour_at_b = new_colour_palette_b.create_solid_colour('Colour_B',[0,255,0])
new_colour_palette_a.insert(new_colour_at_b,0) # insert colour from another palette
new_duplicate_of_a = new_colour_palette_a.insert(new_colour_at_a,0,True) # duplicate colour from the same palette
new_duplicate_of_a.name = 'Colour_A_duplicate'
# List palette colours:
for palette_colour in new_colour_palette_a:
print(palette_colour.name)
#Colour_A_duplicate
#Colour_B
#Default
#Colour_A

◆ list()

Array [OMC::PaletteBaseColour*] OMC::Palette::list ( )

Converts the dynamic list into a concrete list of PaletteBaseColour objects.

Returns
Returns an array of PaletteBaseColour objects.

◆ lock()

void OMC::Palette::lock ( )

Try to obtain the database lock. The lock will be held until it is released in script or the ui. Safe to call multiple time to get the lock state. Throws error if unsuccessful.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette (it already comes with a default colour, with the name 'Default'):
new_palette_type = 'Colour'
new_palette_name = 'Colour_Palette_Name'
new_colour_palette = palette_list.create(new_palette_type,new_palette_name)
#Lock Palette
new_colour_palette.lock()
#Check that it's locked
print(new_colour_palette.locked == True) # True
#Release lock
new_colour_palette.release()
print(new_colour_palette.locked == False) # True

◆ palette_list()

OMC::PaletteList* OMC::Palette::palette_list ( )

Gets the parent PaletteList, or throws error if currently parentless.

Returns
The Palette list object.

◆ pop()

OMC::PaletteBaseColour* OMC::Palette::pop ( int  index)

Pops given index colour from the Palette.

Returns
Returns the popped PaletteBaseColour object.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colours inside palette:
new_colour_a = new_colour_palette.create_solid_colour('Colour_A',[255,0,0])
new_colour_b = new_colour_palette.create_solid_colour('Colour_B',[255,255,0])
new_colour_c = new_colour_palette.create_solid_colour('Colour_C',[255,0,255])
# Pop B:
popped_colour_b = new_colour_palette.pop(2)
print(popped_colour_b.id == new_colour_b.id) # True
# List palette colours:
for palette_colour in new_colour_palette:
print(palette_colour.name)
#Default
#Colour_A
#Colour_C

◆ release()

void OMC::Palette::release ( )

Try to release the database lock. Release access to the Palette. Other users will be able to obtain the access rights to the Palette. Throws error if unsuccessful.

Examplified in lock() method.

◆ remove()

void OMC::Palette::remove ( OMC::PaletteBaseColour colour)

Removes colour from the Palette. Throws error if unsuccessful.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colours inside palette:
new_colour_a = new_colour_palette.create_solid_colour('Colour_A',[255,0,0])
new_colour_b = new_colour_palette.create_solid_colour('Colour_B',[255,255,0])
new_colour_c = new_colour_palette.create_solid_colour('Colour_C',[255,0,255])
# Remove B:
new_colour_palette.remove(new_colour_b)
# List palette colours:
for palette_colour in new_colour_palette:
print(palette_colour.name)
#Default
#Colour_A
#Colour_C

◆ reorder()

void OMC::Palette::reorder ( OMC::PaletteBaseColour colour,
int  index 
)

Reorders the internal list by moving a the specified Palette id to the given index. Throws error if unsuccessful.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colours inside palette:
new_colour_a = new_colour_palette.create_solid_colour('Colour_A',[255,0,0])
new_colour_b = new_colour_palette.create_solid_colour('Colour_B',[255,255,0])
new_colour_c = new_colour_palette.create_solid_colour('Colour_C',[255,0,255])
# Reorder A:
new_colour_palette.reorder(new_colour_a,3)
# List palette colours:
for palette_colour in new_colour_palette:
print(palette_colour.name)
#Default
#Colour_B
#Colour_C
#Colour_A

Member Data Documentation

◆ element_id

int OMC::Palette::element_id
read

The element id in which the Palette is stored if location is ELEMENT. Returns None if the Palette is not stored in an element.

◆ found

bool OMC::Palette::found
read

True if the Palette was found at the location specified by the path and name.

◆ id

QString OMC::Palette::id
read

The ID of this Palette.

◆ loaded

bool OMC::Palette::loaded
read

True if the Palette was successfully loaded from the disk.

◆ location

QString OMC::Palette::location
read

The storage location of this Palette (e.g. Environment, Job, Scene, Element, External).

◆ locked

bool OMC::Palette::locked
read

Whether the Palette is currently locally locked by the session, and can be modified.

◆ name

QString OMC::Palette::name
readwrite

The name of this Palette. The extension (".plt") is not included.

◆ operator[int index]

OMC::PaletteBaseColour* OMC::Palette::operator[int index]

Provides the PaletteBaseColour object at the given index.

Returns
The Palette list object.

Example:

from ToonBoom import harmony
palette_list = harmony.session().project.palettes;
# Clear the palette list of palettes (Optional)
palette_list.clear()
# Create a new colour palette:
new_colour_palette = palette_list.create('Colour','Palette_Name')
# Create new colour inside palette:
new_colour = new_colour_palette.create_solid_colour('Colour_A',[255,0,0])
# Access palette colours:
print(new_colour_palette[0].name == 'Default' ) # True
print(new_colour_palette[1].id == new_colour.id ) # True

◆ path

QString OMC::Palette::path
read

The path to the palette file, containing this palette, in system.

◆ type

QString OMC::Palette::type
readwrite

The type of the Palette, can be used to change the Palette type if it can be converted.

◆ valid

bool OMC::Palette::valid
read

True if the Palette object is valid.

Inheritance diagram for OMC::Palette:
Collaboration diagram for OMC::Palette: