Files
controller-wisetopdataserver/python/biopro/util/channel.py
T
2021-12-20 14:52:55 +08:00

68 lines
1.8 KiB
Python

"""Channel mask. It is python wrap the c extension.
"""
from typing import List, Union, Iterable
# noinspection PyUnresolvedReferences
import biopro.ext.channel as util_channel
__all__ = ['ChannelMask']
_RUNTIME_COMPILE = False
if _RUNTIME_COMPILE:
ChannelMask = util_channel.ChannelMask
else:
class ChannelMask:
__slots__ = '__impl',
def __init__(self, *channel: int):
self.__impl: 'ChannelMask' = util_channel.ChannelMask(channel)
@property
def size(self) -> int:
"""channel number"""
return self.__impl.size
def clear(self):
"""clear channel mask"""
self.__impl.clear()
def contain_channel(self, channel: int) -> bool:
"""contain channel"""
return self.__impl.contain_channel(channel)
def add_channel(self, channel: Union[int, List[int], Iterable[int]]) -> bool:
"""update channel mask
:param channel:
:return: mask changed
"""
return self.__impl.add_channel(channel)
def set_channel(self, channel: Union[int, List[int], Iterable[int]]) -> bool:
"""replace channel mask.
:param channel:
:return: mask changed
"""
return self.__impl.set_channel(channel)
def del_channel(self, channel: int) -> bool:
"""remove channel from mask.
:param channel:
:return: mask changed
"""
return self.__impl.del_channel(channel)
def channels(self) -> List[int]:
"""list channels"""
return self.__impl.channels()
def __iter__(self):
"""iter channel"""
return iter(self.__impl.channels())