Framework core
The framework-core
library is constructed around a few key components: the Host
, the Client
, the Event Manager
, and the Registry
.
In essence, the framework-core
library's functionality is established by initializing the Host
and the Client
, which then interact through events managed by the Event Manager
. Meanwhile, the Registry
is leveraged to manage and provide extensions, with a set of default ones available in the framework-common-extensions
project.
Host
The Host
plays a pivotal role in the framework. Its main responsibilities include:
- Managing interactions with the underlying application that the host runs within, typically a DCC (Digital Content Creation) application, through plugins.
- Instantiated with an
Event Manager
, facilitating communication between theHost
and theClient
. - Execute tool-configs on demand by the client on the
Engine
.
Host(event_manager, registry=registry_instance)
Client
The Client
component is tasked with:
- Reading the tool configuration and context from the
Host
. - Running framework dialogs (interactive/GUI mode)
- Instructing the
Host
to execute the augmented tool configuration, its plugins, and options gathered from the user.
client = Client(event_manager, registry=registry_instance)
Event Manager
The Event Manager
is integral for:
- Facilitating communication between the
Host
and theClient
. - Managing and dispatching events within the system.
- Being instantiated with a session to handle these events effectively.
- The Event Manager can be instantiated in either allowing remote events or not (True by default).
- Remote events goes to the server and then back to the Host/client, while local events are handled directly by the Host/client.
event_manager = EventManager(
session=session, allow_remote_events=True
)
Remote/Local events example:
from ftrack_framework_core import event
import ftrack_api
def my_publish_callback(_event):
'''Event callback printing all new or updated entities.'''
print(f"callback: {_event}")
def my_subscribe_callback(_event):
print(f"sub_callback: {_event}")
return "my-reply"
session = ftrack_api.Session(auto_connect_event_hub=True)
event_manager = event.EventManager(session, allow_remote_events=True)
event_manager.subscribe.host_run_tool_config("my-host_id", my_subscribe_callback)
# Run local event will return the reply from the callback:
reply = event_manager.publish.host_run_tool_config("my-host_id","my-tool-config-reference",{"data":"example"}, my_publish_callback)
print (reply)
# Run remote event will run asynchronous and will print the reply in the callback:
event_manager.publish.host_run_tool_config("my-host_id","my-tool-config-reference",{"data":"example"}, my_publish_callback, remote=True
)
Registry
The Registry
serves to:
- Store and manage extensions within the framework.
- Be instantiated and scanned to identify available extensions.
- Provide default extensions, which are included in the
framework-common-extensions
.
registry_instance = Registry()
registry_instance.scan_extensions(paths=framework_extensions_path)