예제 #1
0
    def _default_context(self):
        """ Initialize the context using the config.

        """
        config = self.template_config
        context = TemplateContext()

        update_members_from_preferences(context, config['context'])
        return context
예제 #2
0
    def _default_context(self):
        """ Initialize the context using the config.

        """
        config = self.template_config
        context = TemplateContext()

        update_members_from_preferences(context, config['context'])
        return context
예제 #3
0
    def build_from_config(cls, config, dependencies):
        """ Create a new instance using the provided infos for initialisation.

        Parameters
        ----------
        config : dict(str)
            Dictionary holding the new values to give to the members in string
            format, or dictionnary like for instance with prefs.

        dependencies : dict
            Dictionary holding the necessary classes needed when rebuilding.

        Returns
        -------
        sequence : AbstractSequence
            Newly created and initiliazed sequence.

        Notes
        -----
        This method is fairly powerful and can handle a lot of cases so
        don't override it without checking that it works.

        """
        sequence = cls()
        update_members_from_preferences(sequence, config)

        i = 0
        pref = 'item_{}'
        validated = []
        while True:
            item_name = pref.format(i)
            if item_name not in config:
                break
            item_config = config[item_name]
            i_id = item_config.pop('item_id')
            i_cls = dependencies['ecpy.pulses.items'][i_id]
            item = i_cls.build_from_config(item_config,
                                           dependencies)
            validated.append(item)
            i += 1

        setattr(sequence, 'items', validated)

        return sequence
예제 #4
0
    def build_from_config(cls, config, dependencies):
        """ Create a new instance using the provided infos for initialisation.

        Parameters
        ----------
        config : dict(str)
            Dictionary holding the new values to give to the members in string
            format, or dictionnary like for instance with prefs.

        dependencies : dict
            Dictionary holding the necessary classes needed when rebuilding.

        Returns
        -------
        pulse : pulse
            Newly created and initiliazed sequence.

        Notes
        -----
        This method is fairly powerful and can handle a lot of cases so
        don't override it without checking that it works.

        """
        pulse = cls()

        #: Initialize the shape object with the right class, so that after
        #: update_members_from_preferences can do all the rest (initialize
        #: the shape's members)
        if 'shape' in config:
            shape_config = config['shape']
            if not shape_config == 'None':
                s_id = shape_config.pop('shape_id')
                s_cls = dependencies['ecpy.pulses.shapes'][s_id]
                shape = s_cls()
                pulse.shape = shape

        update_members_from_preferences(pulse, config)

        return pulse
예제 #5
0
    def build_from_config(cls, config, dependencies):
        """ Create a new instance using the provided infos for initialisation.

        Parameters
        ----------
        config : dict(str)
            Dictionary holding the new values to give to the members in string
            format, or dictionnary like for instance with prefs.

        dependencies : dict
            Dictionary holding the necessary classes needed when rebuilding.

        Returns
        -------
        pulse : pulse
            Newly created and initiliazed sequence.

        Notes
        -----
        This method is fairly powerful and can handle a lot of cases so
        don't override it without checking that it works.

        """
        pulse = cls()

        #: Initialize the shape object with the right class, so that after
        #: update_members_from_preferences can do all the rest (initialize
        #: the shape's members)
        if 'shape' in config:
            shape_config = config['shape']
            if not shape_config == 'None':
                s_id = shape_config.pop('shape_id')
                s_cls = dependencies['ecpy.pulses.shape'][s_id]
                shape = s_cls()
                pulse.shape = shape

        update_members_from_preferences(pulse, config)

        return pulse
예제 #6
0
    def build_from_config(cls, config, dependencies):
        """ Create a new instance using the provided infos for initialisation.

        Parameters
        ----------
        config : dict(str)
            Dictionary holding the new values to give to the members in string
            format, or dictionnary like for instance with prefs.

        dependencies : dict
            Dictionary holding the necessary classes needed when rebuilding.

        Returns
        -------
        sequence : AbstractSequence
            Newly created and initiliazed sequence.

        """
        sequence = cls()
        update_members_from_preferences(sequence, config)

        i = 0
        pref = 'item_{}'
        while True:
            item_name = pref.format(i)
            if item_name not in config:
                break
            item_config = config[item_name]
            i_id = item_config.pop('item_id')
            i_cls = dependencies['ecpy.pulses.item'][i_id]
            item = i_cls.build_from_config(item_config,
                                           dependencies)
            sequence.add_child_item(i, item)
            i += 1

        return sequence
예제 #7
0
    def build_from_config(cls, config, dependencies):
        """ Create a new instance using the provided infos for initialisation.

        Overridden here to allow context creation.

        Parameters
        ----------
        config : dict(str)
            Dictionary holding the new values to give to the members in string
            format, or dictionnary like for instance with prefs.

        dependencies : dict
            Dictionary holding the necessary classes needed when rebuilding.

        Returns
        -------
        sequence : TemplateSequence
            Newly created and initiliazed sequence.

        """
        # TOOD this is not correct as the template config is never retrieved

        # First get the underlying template from the dependencies and merge
        # config into it as it has more recent infos about the context and
        # the vars.
        dep = dependencies

        # Don't want to alter the dependencies dict in case somebody else use
        # the same template.
        t_config = deepcopy(config)

        # Make sure the template_vars stored in the config match the one
        # declared in the template.
        t_vars = literal_eval(config.pop('template_vars'))
        declared_t_vars = literal_eval(t_config['template_vars'])
        for var in declared_t_vars:
            declared_t_vars[var] = t_vars.get(var, '')
        t_config['template_vars'] = repr(declared_t_vars)

        t_config.merge(config)
        config = t_config

        context_config = config['context']
        context_id_name = context_config.pop('context_id')
        context_id = dep['ecpy.pulses.context'][context_id_name]
        context = context_id()
        update_members_from_preferences(context, context_config)

        seq = super(TemplateSequence,
                    cls).build_from_config(t_config, dependencies)
        seq.docs = config['template_doc']
        seq.context = context

        # Do the indexing of the children once and for all.
        i = 1
        for item in seq.items:
            item.index = i
            item.root = seq
            if isinstance(item, BaseSequence):
                item._recompute_indexes()
                i = item._last_index + 1
            else:
                i += 1

        return seq
예제 #8
0
    def build_from_config(cls, config, dependencies):
        """ Create a new instance using the provided infos for initialisation.

        Overridden here to allow context creation.

        Parameters
        ----------
        config : dict(str)
            Dictionary holding the new values to give to the members in string
            format, or dictionnary like for instance with prefs.

        dependencies : dict
            Dictionary holding the necessary classes needed when rebuilding.

        Returns
        -------
        sequence : TemplateSequence
            Newly created and initiliazed sequence.

        """
        # First get the underlying template from the dependencies and merge
        # config into it as it has more recent infos about the context and
        # the vars.
        dep = dependencies

        # Don't want to alter the dependencies dict in case somebody else use
        # the same template.
        t_config = deepcopy(config)

        # Make sure the template_vars stored in the config match the one
        # declared in the template.
        t_vars = literal_eval(config.pop('template_vars'))
        declared_t_vars = literal_eval(t_config['template_vars'])
        for var in declared_t_vars:
            declared_t_vars[var] = t_vars.get(var, '')
        t_config['template_vars'] = repr(declared_t_vars)

        t_config.merge(config)
        config = t_config

        context_config = config['context']
        context_id_name = context_config.pop('context_id')
        context_id = dep['ecpy.pulses.contexts'][context_id_name]
        context = context_id()
        update_members_from_preferences(context, context_config)

        seq = super(TemplateSequence, cls).build_from_config(t_config,
                                                             dependencies)
        seq.docs = config['template_doc']
        seq.context = context

        # Do the indexing of the children once and for all.
        i = 1
        for item in seq.items:
            item.index = i
            item.root = seq
            if isinstance(item, BaseSequence):
                item._recompute_indexes()
                i = item._last_index + 1
            else:
                i += 1

        return seq