File: layout.py

package info (click to toggle)
blender 4.3.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 309,564 kB
  • sloc: cpp: 2,385,210; python: 330,236; ansic: 280,972; xml: 2,446; sh: 972; javascript: 317; makefile: 170
file content (21 lines) | stat: -rw-r--r-- 549 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# SPDX-FileCopyrightText: 2023 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later

import contextlib


@contextlib.contextmanager
def operator_context(layout, op_context):
    """Context manager that temporarily overrides the operator context.

    >>> with operator_context(layout, 'INVOKE_REGION_CHANNELS'):
    ...     layout.operator("anim.channels_delete")
    """

    orig_context = layout.operator_context
    layout.operator_context = op_context
    try:
        yield
    finally:
        layout.operator_context = orig_context