File: utils.py

package info (click to toggle)
python-moderngl-window 3.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 69,096 kB
  • sloc: python: 12,076; makefile: 21
file content (23 lines) | stat: -rw-r--r-- 576 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
22
23
import random
import string
from contextlib import contextmanager

from moderngl_window import conf


@contextmanager
def settings_context(values: dict):
    """Override conf.settings

    Args:
        values (dict): Dictionary containing settings values
    """
    old_settings = conf.settings.to_dict()
    conf.settings.apply_from_dict(values)
    yield None
    conf.settings.apply_from_dict(old_settings)


def rnd_string(length=16):
    chars = string.ascii_letters + string.digits
    return "".join(c for c in random.choices(chars, k=length))