OMC::Application Class Referenceabstract

Detailed Description

The object representing the overall running application at the base level.

The top level object, representing the currently running application, Harmony, Storyboard or Control Center. Generally provided from the main Python module's session.

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

OMC::Projectproject
 Get the active project from the instance of the application.
 
OMC::Aboutabout
 Get the active about details from the instance of the application.
 
OMC::Preferencespreferences
 Get the active preferences from the instance of the application.
 
OMC::Actionsactions
 Get the application's actions.
 
OMC::ViewList * views
 Get the application's available views.
 
OMC::ToolList * tools
 Get the application's available tools.
 
OMC::InterfaceManager * interfaces
 Get the DOM interface manager.
 
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

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

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 ( )

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)

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 
)

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 ( )

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 ( )

Unlocks the application after a thread has processed commands.

See thread_lock() for more information.

Inheritance diagram for OMC::Application:
Collaboration diagram for OMC::Application: