Skip to content

workio

Host API for working with workfiles.

current_file()

Return the current workfile.

Source code in client/ayon_mocha/api/workio.py
65
66
67
68
69
70
def current_file() -> Optional[Path]:
    """Return the current workfile."""
    project = get_current_project()
    if not project:
        return None
    return Path(project.project_file)

file_extensions()

Return file extensions for workfiles.

Source code in client/ayon_mocha/api/workio.py
12
13
14
def file_extensions() -> list[str]:
    """Return file extensions for workfiles."""
    return [".mocha"]

has_unsave_changes()

Return True if the current workfile has unsaved changes.

Mocha Pro doesn't have API to query this state so we always return False.

Source code in client/ayon_mocha/api/workio.py
17
18
19
20
21
22
def has_unsave_changes() -> bool:
    """Return True if the current workfile has unsaved changes.

    Mocha Pro doesn't have API to query this state so we always return False.
    """
    return True

open_file(filepath)

Open a workfile.

There is probably no way to open a workfile in Mocha Pro directly, so we run Mocha Pro with the footage file as an argument, this will open new Mocha Pro window with the project loaded, and we kill the original application.There wasn't even a way to quit Mocha Pro in standard way, so we terminate it rather forcefully.

Todo (antirotor): quit mocha only if the run_mocha was successful.

Parameters:

Name Type Description Default
filepath Path

Path to the workfile.

required
Source code in client/ayon_mocha/api/workio.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def open_file(filepath: Path) -> None:
    """Open a workfile.

    There is probably no way to open a workfile in Mocha Pro directly,
    so we run Mocha Pro with the footage file as an argument, this will
    open new Mocha Pro window with the project loaded, and we kill the
    original application.There wasn't even a way to quit Mocha Pro
    in standard way, so we terminate it rather forcefully.

    Todo (antirotor): quit mocha only if the run_mocha was successful.

    Args:
        filepath (Path): Path to the workfile.

    """
    run_mocha(footage_path=filepath.as_posix())
    quit_mocha()

save_file(filepath)

Save the current workfile.

Note that project cannot be saved without being created first. To create the project, you need to specify clip first, thus we can't create workfile from the un-initialized project within Mocha Pro.

Source code in client/ayon_mocha/api/workio.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def save_file(filepath: Optional[Path]) -> None:
    """Save the current workfile.

    Note that project cannot be saved without being created first.
    To create the project, you need to specify clip first, thus
    we can't create workfile from the un-initialized project within Mocha Pro.

    """
    project = get_current_project()
    if not project:
        if not filepath:
            return
        project = create_empty_project(filepath)
    if filepath:
        project.save_as(filepath.as_posix())
        # now we need to reopen mocha with the new project
        open_file(filepath)
        return
    project.save()