本文整理汇总了Python中echomesh.expression.Expression类的典型用法代码示例。如果您正苦于以下问题:Python Expression类的具体用法?Python Expression怎么用?Python Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent, desc):
times = []
for e in desc.get('elements', []):
times.append([Expression.convert(e.pop(a, None))
for a in Sequence.ATTRIBUTES])
self.elements = []
self.output = desc.get('output', None)
self.patterns = {}
for k, v in desc.get('pattern', {}).items():
self.patterns[k] = make_pattern(self, v, k)
super(Sequence, self).__init__(
parent, desc, name='Sequence', full_slave=False)
self.loops = Expression.convert(desc.get('loops', 1))
self.duration = Expression.convert(desc.get('duration', 'infinity'))
self.sequence = []
self.paused_children = set()
for element, t in zip(self.elements, times):
begin, end, duration = t
if duration is not None:
if end is not None:
begin = end - duration
elif begin is not None:
end = begin + duration
self.sequence.append([begin or 0, element.start])
if end is not None:
self.sequence.append([end, element.pause])
self.sequence.append([self.duration, self.pause])
self.sequence.sort(key=operator.itemgetter(0))
示例2: __init__
def __init__(self, parent, desc):
times = []
for e in desc.get('elements', []):
times.append([Expression.convert(e.pop(a, None)) for a in Sequence.ATTRIBUTES])
self.elements = []
self.pattern_makers = PatternDesc.make_patterns_for_element(
self, desc.get('patterns', {}))
super(Sequence, self).__init__(
parent, desc, name='Sequence', full_slave=False)
self.loops = Expression.convert(desc.get('loops', 1))
self.duration = Expression.convert(desc.get('duration', Units.INFINITY))
self.sequence = []
self.paused_children = set()
for element, t in zip(self.elements, times):
begin, end, duration = t
if duration is not None:
if end is not None:
begin = end - duration
elif begin is not None:
end = begin + duration
self.sequence.append([begin or 0, element.start])
if end is not None:
self.sequence.append([end, element.pause])
self.sequence.append([self.duration, self.pause])
self.sequence.sort(key=operator.itemgetter(0))
示例3: __init__
def __init__(self, parent, description, name='Repeat', **kwds):
super(Repeat, self).__init__(parent, description, name, **kwds)
self.random_delay = Expression.convert(description.get('random_delay', 0))
self.period = Expression.convert(description.get('period', 0))
self.repeat = Expression.convert(description.get('repeat', 'infinite'))
assert self.random_delay > 0 or self.period > 0, (
'You must set either a period or a random_delay')
示例4: settings_update
def settings_update(self, get):
if not self.count_set:
self._set_count(light_count(get))
self.brightness = Expression.convert(get('light', 'brightness'))
if not self.period_set:
self.period = Expression.convert(
get('light', 'visualizer', 'period'))
示例5: split
def split(items):
kwds = {}
numeric = []
for k, v in six.iteritems(items):
if isinstance(k, six.string_types) and k[0].isalpha():
kwds[k] = v
else:
from echomesh.expression import Expression
numeric.append([Expression.convert(k), Expression.convert(v)])
return kwds, sorted(numeric)
示例6: __init__
def __init__(self, element, period, begin=None, end=None, count=None,
skip=1, repeat=INFINITY, **kwds):
parts = [
Expression.convert(x, element) for x in (count, begin, end, skip)]
self.count, self.begin, self.end, self.skip = Interval.interval(*parts)
self.element = element
self.period = Expression.convert(period, element)
self.repeat = repeat
if kwds:
LOGGER.error('Unknown keywords "%s" for counter', kwds)
示例7: set_player
def set_player(self, element,
level=1, pan=0, loops=1, begin=0, end=INF, length=INF, **kwds):
self._element = element
self._file = kwds.pop('file')
self._filename = Util.DEFAULT_AUDIO_DIRECTORY.expand(self._file)
if kwds:
LOGGER.error('Unused keywords %s', kwds)
self._passthrough = (level == 1 and pan == 0)
self._length = length
self._level = Expression.expression(level, element)
self._pan = Expression.expression(pan, element)
self._loops = loops
self._begin = begin
self._end = end
示例8: __init__
def __init__(
self,
element,
loops=1,
position=(0, 0),
rotation=(0, 0, 0),
size=1,
duration=None,
z=DEFAULT_Z,
shader=None,
**kwds
):
super(ImageSprite, self).__init__()
import pi3d
self.element = element
self.imagename = IMAGE_DIRECTORY.expand(kwds.pop("file", None))
del kwds["type"]
if kwds:
s = "" if len(kwds) == 1 else "s"
LOGGER.error("Unknown keyword%s: %s", s, ", ".join(kwds))
self._loops = loops
self._loop_number = 0
self._position = Expression.expression(position, element)
self._rotation = Expression.expression(rotation, element)
self._size = Expression.expression(size, element)
self._z = Expression.expression(z, element)
self.element.time = 0 # elapsed time.
self._time = 0 # start time.
if duration is None:
for env in [self._position, self._rotation, self._size, self._z]:
if env.is_constant():
duration = max(duration, env.length)
if duration is None:
duration = INFINITY
else:
self._duration = Expression.convert(duration)
if not self._duration:
LOGGER.warning("An image sprite had a zero duration.")
if not ImageSprite.CACHE:
ImageSprite.CACHE = pi3d.TextureCache()
texture = ImageSprite.CACHE.create(self.imagename)
x, y, z = self.coords()
self.sprite = pi3d.ImageSprite(texture, w=texture.ix, h=texture.iy, shader=Shader.shader(shader), x=x, y=y, z=z)
self.sprite.repaint = self.repaint
示例9: set_player
def set_player(player, element,
level=1, pan=0, loops=1, begin=0, end=-1, length=-1, **kwds):
kwds.pop('type', None)
player._element = element
player._file = kwds.pop('file')
player._filename = Util.DEFAULT_AUDIO_DIRECTORY.expand(player._file)
if kwds:
LOGGER.error('Unused keywords %s', kwds)
player._passthrough = (level == 1 and pan == 0)
player._length = length
player._level = Expression.expression(level, element)
player._pan = Expression.expression(pan, element)
player._loops = loops
player._begin = begin
player._end = end
示例10: get
def get(self, *path):
with self.lock:
value = self.clients.get(path)
if not value:
value = Expression.convert(Settings.get(*path))
self.clients[path] = value
return value
示例11: make_table_and_patterns
def make_table_and_patterns(pattern_desc, attributes):
table = {}
patterns = []
desc = pattern_desc.description
pd = pattern_desc
try:
for k, v in six.iteritems(desc):
if not k.startswith('pattern'):
if k in attributes:
v = Expression.expression(v, pattern_desc.element)
table[k] = v
pats = desc.get('patterns') or desc.get('pattern') or []
if type(pats) is not list:
pats = [pats]
for p in pats:
pd = _PatternDesc(pattern_desc.element, p, pattern_desc.name)
pattern = _make_pattern(pd, False)
if pattern:
patterns.append(pattern)
except Exception as e:
if RAISE_ORIGINAL_EXCEPTION:
raise
else:
raise Exception('%s in %s' % (e, pd))
return table, patterns
示例12: config_update
def config_update(self, get):
config = get('network', 'client')
if self.constructed:
# TODO: restart the server on the fly if its parameters change.
pass
else:
self.constructed = True
super(ClientServer, self).__init__(
config['host_name'],
config['port'],
allow_reuse_address=config['allow_reuse_address'],
debug=config['debug'],
read_callback=self.read_callback,
timeout=Expression.convert(get('network', 'timeout')),
)
self.start()
if (not self.process) and config['start']:
args = {}
if config['pipe_stdin']:
args['stdin'] = subprocess.PIPE
if config['pipe_stdout']:
args['stdout'] = subprocess.PIPE
command = Client.make_command()
LOGGER.vdebug("About to start client process: '%s'", command)
try:
self.process = subprocess.Popen(command, **args)
except:
LOGGER.error("Couldn't start the subprocess with command '%s'", command)
else:
LOGGER.vdebug('Client process started!')
elif self.process:
LOGGER.vdebug('Not starting client: the configuration said not to.')
示例13: _fix_config
def _fix_config(self, get):
light = copy.deepcopy(get('light'))
light['brightness'] = Expression.convert(light['brightness'])
light['hardware']['period'] = Expression.convert(light['hardware']['period'])
light['visualizer']['period'] = Expression.convert(light['visualizer']['period'])
visualizer = light['visualizer']
visualizer['background'] = ColorTable.to_color(visualizer['background'])
dl = visualizer['instrument']
dl['border']['color'] = ColorTable.to_color(dl['border']['color'])
dl['background'] = ColorTable.to_color(dl['background'])
data = {'light': light, 'midi': get('midi')}
config = {'type': 'config', 'data': data}
self.closes_echomesh = visualizer['closes_echomesh'] ## !
return config
示例14: __init__
def __init__(self, desc, element, name):
self.name = name
self.element = element
desc = ReadObservingDictionary(desc)
pat = desc.pop('pattern', [])
if isinstance(pat, dict):
pat = [pat]
elif isinstance(pat, six.string_types):
pat = split_on_commas(pat)
self._patterns = [make_pattern(element, p) for p in pat]
if self.PATTERN_COUNT is not None:
assert self.PATTERN_COUNT == len(self._patterns), (
"Pattern type %s expects %s subpatterns but got %d" %
(self.__class__.__name__,
self.PATTERN_COUNT,
len(self._patterns)))
self.dictionary = {}
self.is_constant = all(p.is_constant for p in self._patterns)
missing = []
self.constants = set()
for k, v in self.SETTINGS.items():
const = v.get('constant', self.CONSTANT)
literal = v.get('literal')
if const:
self.constants.add(k)
value = desc.get(k, v.get('default'))
if value is None and 'default' not in v:
missing.append(k)
else:
if literal:
expression = LiteralExpression(value)
elif const:
expression = ConstantExpression.constant_expression(value)
else:
expression = Expression.expression(value, element)
self.dictionary[k] = expression
self.is_constant = self.is_constant and expression.is_constant()
if missing:
raise Exception('%s is missing required arguments %s' %
(self, ', '.join(missing)))
unread = desc.unread()
if unread:
LOGGER.error(
"For pattern type %s, we didn't use the following parameters: %s",
self.__class__.__name__, ', '.join(unread))
self._in_precompute = True
self._precompute()
self._in_precompute = False
if self.is_constant:
self._value = self._evaluate();
示例15: settings_update
def settings_update(self, get):
port = get('osc', 'server', 'port')
if port == self.port:
return
if self.server:
self.server.close()
self.server = None
self.port = port
self.server = OSC.OSCServer(('', port), None, port)
self.server.socket.settimeout(
Expression.convert(get('network', 'timeout')))