Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    def __init__(self, parent, description):
        super(PatternElement, self).__init__(parent, description)

        assert isinstance(parent, Sequence)
        self.pattern = make_pattern(parent, description['pattern'],
                                    patterns=parent.patterns)
        self.output_data = description.get('output') or parent.output
        self.output = None
Exemplo n.º 3
0
    def __init__(self, parent, description):
        super(PatternElement, self).__init__(parent, description)

        assert isinstance(parent, Sequence)
        self.pattern = make_pattern(parent,
                                    description['pattern'],
                                    patterns=parent.patterns)
        self.output_data = description.get('output') or parent.output
        self.output = None
Exemplo n.º 4
0
    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();
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
    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))