mirror of
https://github.com/iperov/DeepFaceLive
synced 2025-07-06 04:52:14 -07:00
code release
This commit is contained in:
parent
b941ba41a3
commit
a902f11f74
354 changed files with 826570 additions and 1 deletions
24
xlib/python/EventListener.py
Normal file
24
xlib/python/EventListener.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from collections import Iterable
|
||||
|
||||
|
||||
class EventListener:
|
||||
__slots__ = ['_funcs']
|
||||
def __init__(self):
|
||||
self._funcs = []
|
||||
|
||||
def has_listeners(self):
|
||||
return len(self._funcs) != 0
|
||||
|
||||
def add(self, func_or_list):
|
||||
if isinstance(func_or_list, Iterable):
|
||||
func_or_list = tuple(func_or_list)
|
||||
else:
|
||||
func_or_list = (func_or_list,)
|
||||
|
||||
for func in func_or_list:
|
||||
if func not in self._funcs:
|
||||
self._funcs.append(func)
|
||||
|
||||
def call(self, *args, **kwargs):
|
||||
for func in self._funcs:
|
||||
func(*args, **kwargs)
|
42
xlib/python/__init__.py
Normal file
42
xlib/python/__init__.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
class dotdict(dict):
|
||||
"""dot.notation access to dictionary attributes"""
|
||||
__getattr__ = dict.get
|
||||
__setattr__ = dict.__setitem__
|
||||
__delattr__ = dict.__delitem__
|
||||
|
||||
from .EventListener import EventListener
|
||||
|
||||
def all_is_not_None(*args): return all(x is not None for x in args)
|
||||
def all_is_None(*args): return all(x is None for x in args)
|
||||
|
||||
class Disposable:
|
||||
def __del__(self):
|
||||
self.dispose()
|
||||
|
||||
def _on_dispose(self):
|
||||
pass
|
||||
|
||||
|
||||
def dispose(self):
|
||||
_disposed = getattr(self, '_disposed', False)
|
||||
if not _disposed:
|
||||
self._disposed = True
|
||||
self._on_dispose()
|
||||
|
||||
def repeat_call(obj, func_name, args_list):
|
||||
"""
|
||||
|
||||
"""
|
||||
func = getattr(obj, func_name)
|
||||
for args in args_list:
|
||||
if not isinstance(args, list):
|
||||
args = [args]
|
||||
func(*args)
|
||||
|
||||
def repeat_objs_call(obj_list, func_name, *args, **kwargs):
|
||||
"""
|
||||
|
||||
"""
|
||||
for obj in obj_list:
|
||||
func = getattr(obj, func_name)
|
||||
func(*args, **kwargs)
|
Loading…
Add table
Add a link
Reference in a new issue