OMH::Harmony Class Reference

Detailed Description

The Harmony Application object.

The top level object, representing the currently running instance of Harmony and provides access to the loaded project and its contents.

Public Member Functions

void process_one_event ()
 Processes the next event in the application's event queue. More...
 
void log (const QString &log) const
 Write to the application's Message Log; defaults to a trace_level log. More...
 
void log (const QString &log, const QString &level) const
 Write to the application's Message Log with different levels as an option. More...
 
void trace (const QString &log) const
 Write to the application's Message Log as trace output.
 
void debug (const QString &log) const
 Write to the application's Message Log as debug output.
 
void error (const QString &log) const
 Write to the application's Message Log as error output.
 
void thread_lock ()
 Locks the application to allow for a thread to process commands. More...
 
void thread_unlock ()
 Unlocks the application after a thread has processed commands. More...
 
void run_function (PyFunction function)
 Runs the provided function while locking and unlocking the application as needed. More...
 
void run_on_main (PyFunction function, bool blocking)
 Runs the provided method on the main thread. More...
 

Public Attributes

OMH::HarmonyProjectproject
 Get the active project from the instance of Harmony. More...
 
OMC::Aboutabout
 Get the active about details from the instance of Harmony. More...
 
OMC::Preferencespreferences
 Get the active preferences from the instance of Harmony. More...
 
OMC::Actionsactions
 Get the application's action interface. More...
 
OMC::ViewList * views
 Get the application's available views - not yet available. More...
 
OMC::ToolList * tools
 Get the application's available tools - not yet available. More...
 
OMC::InterfaceManager * interfaces
 Get the DOM interface manager - not yet available. More...
 
bool notify_enabled
 Get/set whether application notifications are enabled. More...
 
OMC::Javascriptjavascript
 Get the Javascript interface, used for interacting with Javascript scripts.
 

Member Function Documentation

◆ log() [1/2]

void OMC::Application::log ( const QString &  log) const
inherited

Write to the application's Message Log; defaults to a trace_level log.

from ToonBoom import harmony #Import the Harmony Module
session = harmony.session()
session.log( "Hello World!" ) #Expectation: Hello World appears in the MessageLog's view.

◆ log() [2/2]

void OMC::Application::log ( const QString &  log,
const QString &  level 
) const
inherited

Write to the application's Message Log with different levels as an option.

The Message Log supports three levels of output, which can be specified in this function.

Available log levels include:

  • trace : The standard trace output in the MessageLog view.
  • debug : The debug output in the MessageLog view, only available when the Application's debug mode is enabled.
  • error : The error output in the MessageLog view, as well as a critical error popup window.
from ToonBoom import harmony #Import the Harmony Module
session = harmony.session()
session.log( "Hello Debug World!", "debug" ) #Expectation: Hello World appears in the MessageLog's view.

◆ process_one_event()

void OMC::Application::process_one_event ( )
inherited

Processes the next event in the application's event queue.

In the event that the script requires updates in the GUI, process_one_event() will ublock the application from the current script and run the next event in the application queue.

from ToonBoom import harmony #Import the Harmony Module
session = harmony.session()
actions = session.actions
actions.perform( "actionThatRequiresGUI" )
session.process_one_event()

◆ run_function()

void OMC::Application::run_function ( PyFunction  function)
inherited

Runs the provided function while locking and unlocking the application as needed.

Similar to lock() and unlock(), this will run the provided function and lock and unlock the application as necessary.

#In an external Python thread ---
from ToonBoom import harmony #Import the Harmony Module
from time import sleep
from threading import Thread
session = harmony.session()
def mainthread_action():
print("RUNNING TEST")
proj = session.project
scene = proj.scene
nodes = scene.nodes
for n in nodes:
print(n.name)
def thread_task():
session.run_function( mainthread_action )
thread = Thread(target=thread_task)
thread.start()
print( "Concurrent Work Being Done" )

◆ run_on_main()

void OMC::Application::run_on_main ( PyFunction  function,
bool  blocking 
)
inherited

Runs the provided method on the main thread.

Only available in the internal Python Console

Using run_on_main will send the function-call to the main thread and it is run there safely. The external thread locks until the main thread has finished.

Note– this requires that the main thread be available to run the function at some point; the call will time out if is does not become available in a timely manner.

#In an external Python thread ---
from ToonBoom import harmony #Import the Harmony Module
from time import sleep
from threading import Thread
session = harmony.session()
def mainthread_action():
print("RUNNING TEST")
proj = session.project
scene = proj.scene
nodes = scene.nodes
for n in nodes:
print(n.name)
def thread_task():
session.run_function( mainthread_action )
thread = Thread(target=thread_task)
thread.start()
#The thread will queue the function onto the main thread, the function is called when the main thread can appropriately run it.

◆ thread_lock()

void OMC::Application::thread_lock ( )
inherited

Locks the application to allow for a thread to process commands.

When running in threads – accessing Harmony objects without a thread lock will result in an error. Instead, get the application's lock in the external thread, and release it when complete to regain activity in the main application thread afterwards.

from ToonBoom import harmony #Import the Harmony Module
from time import sleep
from threading import Thread
session = harmony.session()
def thread_task():
session.thread_lock()
print("RUNNING TEST")
proj = session.project
scene = proj.scene
nodes = scene.nodes
for n in nodes:
print(n.name)
session.thread_unlock()
thread = Thread(target=thread_task)
thread.start()
# The thread will be queued to run on the main thread when it becomes available.
# concurrent work cannot be done, as the main thread needs to be available at some point.
# processOneEvent() may be needed to force the queued event to occur.

◆ thread_unlock()

void OMC::Application::thread_unlock ( )
inherited

Unlocks the application after a thread has processed commands.

See thread_lock() for more information.

Member Data Documentation

◆ about

OMH::Harmony::about

Get the active about details from the instance of Harmony.

The About class provides general information about the current Harmony session. This includes environment information, and general application information,

from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
about = sess.about #Get about object.
print( about.path_application ) #Expectation: Prints the path to the Harmony application's path.

◆ actions

OMH::Harmony::actions

Get the application's action interface.

The application's action interface is used to perform underlying actions within the GUI in the application. Generally, actions are only available internally within the GUI. This interface can also be used to list available actions that can be performed.
In the event that a scripted solution is not available through the DOM, an action may be available. It is worth noting that actions can require user input and subsequent application event callbacks, some of which are not supported in a scripted environment.

from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
actions = sess.actions #Get actions handler.
for responder in actions.responders:
print( responder )
action_list = actions.actions(responder)
for action in action_list:
print( " %s"%(action) ) #Expectation - All responders will be listed with their available actions.

◆ interfaces

OMH::Harmony::interfaces

Get the DOM interface manager - not yet available.

Not yet available.

◆ notify_enabled

bool OMH::Harmony::notify_enabled
readwrite

Get/set whether application notifications are enabled.

Most actions in Harmony result in events that update the GUI and refresh the contents in the scene. Setting the notify_enabled to false will prevent these intermediate updates, and will often allow scripts to run faster. Once a script has completed, it is important that this be reenabled in order for the GUI to appropriately update with all expected changes.

import math
from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
sess.notify_enabled = False #Disable application events, so everything happens under-the-hood, quickly.
proj = sess.project
scn = proj.scene
top = scn.top
for n in range( 100 ): #Create 100 pegs -- for fun!
rad = ( n / 100.0 ) * 2.0 * math.pi #Time to be fancy!
dist = 100.0
new_node = top.nodes.create( "PEG", "PEG_%04d"%(n) )
new_node.position.x = math.cos( rad ) * dist
new_node.position.y = math.sin( rad ) * dist
sess.notify_enabled = True #Reenable applicaiton events to see all 100 fancy new pegs (in record time!)

◆ preferences

OMH::Harmony::preferences

Get the active preferences from the instance of Harmony.

The preference handler for the application provides read and write access to the current application preferences. This is useful for storing and modifying tool preferences.

from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
prefs = sess.preferences #Get preferences handler.
prefs["PEG_DEFAULT_SEPARATE_POSITION"] = True #Expectation: The Peg default separate position preference will now be set to true.

◆ project

OMH::Harmony::project

Get the active project from the instance of Harmony.

The project provides access to properties of the project, and objects contained within the project (such as scenes, palettes, nodes, ect).

from ToonBoom import harmony #Import the Harmony Module
sess = harmony.session() #Get access to the Harmony session, this class.
project = sess.project #Get the currently loaded project.

◆ tools

OMH::Harmony::tools

Get the application's available tools - not yet available.

Not yet available.

◆ views

OMH::Harmony::views

Get the application's available views - not yet available.

Not yet available.

Inheritance diagram for OMH::Harmony:
Collaboration diagram for OMH::Harmony: