Skip to content

lib

maintained_selection()

Maintain selection during context.

Source code in client/ayon_photoshop/api/lib.py
70
71
72
73
74
75
76
77
@contextlib.contextmanager
def maintained_selection():
    """Maintain selection during context."""
    selection = stub().get_selected_layers()
    try:
        yield selection
    finally:
        stub().select_layers(selection)

maintained_visibility(layers=None)

Maintain visibility during context.

Source code in client/ayon_photoshop/api/lib.py
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
@contextlib.contextmanager
def maintained_visibility(layers=None):
    """Maintain visibility during context.

    Args:
        layers (list) of PSItem (used for caching)
    """
    visibility = {}
    if not layers:
        layers = stub().get_layers()
    for layer in layers:
        visibility[layer.id] = layer.visible
    try:
        yield
    finally:
        for layer in layers:
            stub().set_visible(layer.id, visibility[layer.id])
            pass

publish_in_test(log, close_plugin_name=None)

Loops through all plugins, logs to console. Used for tests. Args: log (Logger) close_plugin_name (Optional[str]): Name of plugin with responsibility to close application.

Source code in client/ayon_photoshop/api/lib.py
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
def publish_in_test(log, close_plugin_name=None):
    """Loops through all plugins, logs to console. Used for tests.
    Args:
        log (Logger)
        close_plugin_name (Optional[str]): Name of plugin with responsibility
            to close application.
    """

    # Error exit as soon as any error occurs.
    error_format = "Failed {plugin.__name__}: {error} -- {error.traceback}"
    close_plugin = find_close_plugin(close_plugin_name, log)

    for result in pyblish.util.publish_iter():
        for record in result["records"]:
            # Why do we log again? pyblish logger is logging to stdout...
            log.info("{}: {}".format(result["plugin"].label, record.msg))

        if not result["error"]:
            continue

        # QUESTION We don't break on error?
        error_message = error_format.format(**result)
        log.error(error_message)
        if close_plugin:  # close host app explicitly after error
            context = pyblish.api.Context()
            try:
                close_plugin().process(context)
            except Exception as exp:
                print(exp)