def tomode(thing):
    if thing == None:
        return Mode()
    if isinstance(thing, Mode):
        return thing
    if isinstance(thing, ControlSurfaceComponent):
        return ComponentMode(thing)
    if isinstance(thing, tuple) and len(thing) == 2:
        if isinstance(thing[0], ControlSurfaceComponent) and isinstance(thing[1], Layer):
            return LayerMode(*thing)
        elif callable(thing[0]) and callable(thing[1]):
            mode = Mode()
            mode.enter_mode, mode.leave_mode = thing
            return mode
    if callable(thing):
        mode = Mode()
        mode.enter_mode = thing
        return mode
    if is_iterable(thing):
        return CompoundMode(*thing)
    if is_contextmanager(thing):
        return ContextManagerMode(thing)
    return thing
Пример #2
0
def tomode(thing):
    if thing == None:
        return Mode()
    if isinstance(thing, Mode):
        return thing
    if isinstance(thing, ControlSurfaceComponent):
        return ComponentMode(thing)
    if isinstance(thing, tuple) and len(thing) == 2:
        if isinstance(thing[0], ControlSurfaceComponent) and isinstance(
                thing[1], Layer):
            return LayerMode(*thing)
        elif callable(thing[0]) and callable(thing[1]):
            mode = Mode()
            mode.enter_mode, mode.leave_mode = thing
            return mode
    if callable(thing):
        mode = Mode()
        mode.enter_mode = thing
        return mode
    if is_iterable(thing):
        return CompoundMode(*thing)
    if is_contextmanager(thing):
        return ContextManagerMode(thing)
    return thing