Skip to content

api

Public API for Speedtree

CommunicationWrapper

Source code in client/ayon_speedtree/api/communication_server.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class CommunicationWrapper:
    # TODO add logs and exceptions
    communicator = None

    log = logging.getLogger("CommunicationWrapper")

    @classmethod
    def create_qt_communicator(cls, *args, **kwargs):
        """Create communicator for Artist usage."""
        communicator = QtCommunicator(*args, **kwargs)
        cls.set_communicator(communicator)
        return communicator

    @classmethod
    def set_communicator(cls, communicator):
        if not cls.communicator:
            cls.communicator = communicator
        else:
            cls.log.warning("Communicator was set multiple times.")

    @classmethod
    def client(cls):
        if not cls.communicator:
            return None
        return cls.communicator.client()

    @classmethod
    def replace_process(cls, launch_args):
        """Load spm file."""
        if not cls.communicator:
            return
        return cls.communicator.replace_process(launch_args)

create_qt_communicator(*args, **kwargs) classmethod

Create communicator for Artist usage.

Source code in client/ayon_speedtree/api/communication_server.py
35
36
37
38
39
40
@classmethod
def create_qt_communicator(cls, *args, **kwargs):
    """Create communicator for Artist usage."""
    communicator = QtCommunicator(*args, **kwargs)
    cls.set_communicator(communicator)
    return communicator

replace_process(launch_args) classmethod

Load spm file.

Source code in client/ayon_speedtree/api/communication_server.py
55
56
57
58
59
60
@classmethod
def replace_process(cls, launch_args):
    """Load spm file."""
    if not cls.communicator:
        return
    return cls.communicator.replace_process(launch_args)

SpeedtreeHost

Bases: HostBase, IWorkfileHost, ILoadHost, IPublishHost

Source code in client/ayon_speedtree/api/pipeline.py
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
class SpeedtreeHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost):
    name = "speedtree"

    @staticmethod
    def show_tools_dialog():
        """Show tools dialog with actions leading to show other tools."""
        show_tools_dialog()

    def install(self):

        plugins_dir = os.path.join(SPTREE_ADDON_ROOT, "plugins")
        publish_dir = os.path.join(plugins_dir, "publish")
        load_dir = os.path.join(plugins_dir, "load")
        create_dir = os.path.join(plugins_dir, "create")

        pyblish.api.register_host("speedtree")
        pyblish.api.register_plugin_path(publish_dir)
        register_loader_plugin_path(load_dir)
        register_creator_plugin_path(create_dir)

        register_event_callback(
            "application.launched", self.initial_app_launch
        )
        register_event_callback("application.exit", self.application_exit)

    def get_current_project_name(self):
        """
        Returns:
            Union[str, None]: Current project name.
        """

        return self.get_current_context().get("project_name")

    def get_current_folder_path(self):
        """
        Returns:
            Union[str, None]: Current folder path.
        """

        return self.get_current_context().get("folder_path")

    def get_current_task_name(self):
        """
        Returns:
            Union[str, None]: Current task name.
        """

        return self.get_current_context().get("task_name")

    def get_current_context(self):
        context = get_current_workfile_context()
        if not context:
            return get_global_context()

        return context

    def get_current_workfile(self):
        return os.environ["CURRENT_SPM"]

    def workfile_has_unsaved_changes(self):
        # Pop-up dialog would be located to ask if users
        # save scene if it has unsaved changes
        return True

    def get_workfile_extensions(self):
        return [".spm"]

    def open_workfile(self, filepath):
        os.environ["CURRENT_SPM"] = filepath
        load_spm_file(filepath)
        return filepath

    def save_workfile(self, filepath=None):
        with save_scene("Work Files"):
            context = open_workfile()
            filepath = save_workfile(filepath, context)
        print(f"Saving Spm file: {filepath}")
        copy_ayon_data(filepath)
        load_spm_file(filepath)
        return filepath

    def list_instances(self):
        """Get all AYON instances."""
        # Figure out how to deal with this
        return get_instance_workfile_metadata()

    def write_instances(self, data):
        """Write all AYON instances"""
        return write_workfile_metadata(SPTREE_SECTION_NAME_INSTANCES, data)

    def get_containers(self):
        """Get the data of the containers

        Returns:
            list: the list which stores the data of the containers
        """
        return get_containers()

    def initial_app_launch(self):
        """Triggers on launch of the communication server for Speedtree.

        Usually this aligns roughly with the start of Speedtree.
        """
        context = get_global_context()
        save_current_workfile_context(context)
        # Initialize the SpeedTree system
        SpeedTree.StpInit()

    def application_exit(self):
        """Event action when the application exit
        """
        remove_tmp_data()
        SpeedTree.StpShutDown()

    def update_context_data(self, data, changes):
        return write_workfile_metadata(SPTREE_METADATA_CREATE_CONTEXT, data)

    def get_context_data(self):
        get_load_workfile_metadata(SPTREE_METADATA_CREATE_CONTEXT)

application_exit()

Event action when the application exit

Source code in client/ayon_speedtree/api/pipeline.py
142
143
144
145
146
def application_exit(self):
    """Event action when the application exit
    """
    remove_tmp_data()
    SpeedTree.StpShutDown()

get_containers()

Get the data of the containers

Returns:

Name Type Description
list

the list which stores the data of the containers

Source code in client/ayon_speedtree/api/pipeline.py
124
125
126
127
128
129
130
def get_containers(self):
    """Get the data of the containers

    Returns:
        list: the list which stores the data of the containers
    """
    return get_containers()

get_current_folder_path()

Returns:

Type Description

Union[str, None]: Current folder path.

Source code in client/ayon_speedtree/api/pipeline.py
67
68
69
70
71
72
73
def get_current_folder_path(self):
    """
    Returns:
        Union[str, None]: Current folder path.
    """

    return self.get_current_context().get("folder_path")

get_current_project_name()

Returns:

Type Description

Union[str, None]: Current project name.

Source code in client/ayon_speedtree/api/pipeline.py
59
60
61
62
63
64
65
def get_current_project_name(self):
    """
    Returns:
        Union[str, None]: Current project name.
    """

    return self.get_current_context().get("project_name")

get_current_task_name()

Returns:

Type Description

Union[str, None]: Current task name.

Source code in client/ayon_speedtree/api/pipeline.py
75
76
77
78
79
80
81
def get_current_task_name(self):
    """
    Returns:
        Union[str, None]: Current task name.
    """

    return self.get_current_context().get("task_name")

initial_app_launch()

Triggers on launch of the communication server for Speedtree.

Usually this aligns roughly with the start of Speedtree.

Source code in client/ayon_speedtree/api/pipeline.py
132
133
134
135
136
137
138
139
140
def initial_app_launch(self):
    """Triggers on launch of the communication server for Speedtree.

    Usually this aligns roughly with the start of Speedtree.
    """
    context = get_global_context()
    save_current_workfile_context(context)
    # Initialize the SpeedTree system
    SpeedTree.StpInit()

list_instances()

Get all AYON instances.

Source code in client/ayon_speedtree/api/pipeline.py
115
116
117
118
def list_instances(self):
    """Get all AYON instances."""
    # Figure out how to deal with this
    return get_instance_workfile_metadata()

show_tools_dialog() staticmethod

Show tools dialog with actions leading to show other tools.

Source code in client/ayon_speedtree/api/pipeline.py
37
38
39
40
@staticmethod
def show_tools_dialog():
    """Show tools dialog with actions leading to show other tools."""
    show_tools_dialog()

write_instances(data)

Write all AYON instances

Source code in client/ayon_speedtree/api/pipeline.py
120
121
122
def write_instances(self, data):
    """Write all AYON instances"""
    return write_workfile_metadata(SPTREE_SECTION_NAME_INSTANCES, data)