コード例 #1
0
    def engravers(self):
        r'''Gets engravers belonging to LilyPond context.

        ::

            >>> for engraver in context.engravers:
            ...     engraver
            ...
            LilyPondEngraver(name='Accidental_engraver')
            LilyPondEngraver(name='Axis_group_engraver')
            LilyPondEngraver(name='Bar_engraver')
            LilyPondEngraver(name='Clef_engraver')
            LilyPondEngraver(name='Collision_engraver')
            LilyPondEngraver(name='Cue_clef_engraver')
            LilyPondEngraver(name='Custos_engraver')
            LilyPondEngraver(name='Dot_column_engraver')
            LilyPondEngraver(name='Figured_bass_engraver')
            LilyPondEngraver(name='Figured_bass_position_engraver')
            LilyPondEngraver(name='Fingering_column_engraver')
            LilyPondEngraver(name='Font_size_engraver')
            LilyPondEngraver(name='Grob_pq_engraver')
            LilyPondEngraver(name='Instrument_name_engraver')
            LilyPondEngraver(name='Key_engraver')
            LilyPondEngraver(name='Ledger_line_engraver')
            LilyPondEngraver(name='Ottava_spanner_engraver')
            LilyPondEngraver(name='Output_property_engraver')
            LilyPondEngraver(name='Piano_pedal_align_engraver')
            LilyPondEngraver(name='Piano_pedal_engraver')
            LilyPondEngraver(name='Pure_from_neighbor_engraver')
            LilyPondEngraver(name='Rest_collision_engraver')
            LilyPondEngraver(name='Script_row_engraver')
            LilyPondEngraver(name='Separating_line_group_engraver')
            LilyPondEngraver(name='Staff_collecting_engraver')
            LilyPondEngraver(name='Staff_symbol_engraver')
            LilyPondEngraver(name='Time_signature_engraver')

        Returns tuple.
        '''
        from abjad.ly import contexts
        from abjad.tools import lilypondnametools
        engravers = set()
        for engraver_name in contexts[self.name]['consists']:
            engraver = lilypondnametools.LilyPondEngraver(name=engraver_name)
            engravers.add(engraver)
        engravers = tuple(sorted(engravers, key=lambda x: x.name))
        return engravers
コード例 #2
0
    def register(
        cls,
        accepted_by=None,
        accepts=None,
        alias=None,
        consists=None,
        default_child=None,
        denies=None,
        name=None,
        removes=None,
    ):
        r'''Registers a new context.

        ::

            >>> custom_context = lilypondnametools.LilyPondContext.register(
            ...     accepted_by=['Score', 'StaffGroup'],
            ...     alias='Staff',
            ...     name='BowingStaff',
            ...     removes=['Note_heads_engraver'],
            ...     )
            >>> print(format(custom_context))
            lilypondnametools.LilyPondContext(
                name='BowingStaff',
                )

        ::

            >>> custom_context.is_custom
            True

        ::

            >>> for engraver in custom_context.engravers:
            ...     engraver
            ...
            LilyPondEngraver(name='Accidental_engraver')
            LilyPondEngraver(name='Axis_group_engraver')
            LilyPondEngraver(name='Bar_engraver')
            LilyPondEngraver(name='Clef_engraver')
            LilyPondEngraver(name='Collision_engraver')
            LilyPondEngraver(name='Cue_clef_engraver')
            LilyPondEngraver(name='Dot_column_engraver')
            LilyPondEngraver(name='Figured_bass_engraver')
            LilyPondEngraver(name='Figured_bass_position_engraver')
            LilyPondEngraver(name='Fingering_column_engraver')
            LilyPondEngraver(name='Font_size_engraver')
            LilyPondEngraver(name='Grob_pq_engraver')
            LilyPondEngraver(name='Instrument_name_engraver')
            LilyPondEngraver(name='Key_engraver')
            LilyPondEngraver(name='Ledger_line_engraver')
            LilyPondEngraver(name='Ottava_spanner_engraver')
            LilyPondEngraver(name='Output_property_engraver')
            LilyPondEngraver(name='Piano_pedal_align_engraver')
            LilyPondEngraver(name='Piano_pedal_engraver')
            LilyPondEngraver(name='Pure_from_neighbor_engraver')
            LilyPondEngraver(name='Rest_collision_engraver')
            LilyPondEngraver(name='Script_row_engraver')
            LilyPondEngraver(name='Separating_line_group_engraver')
            LilyPondEngraver(name='Staff_collecting_engraver')
            LilyPondEngraver(name='Staff_symbol_engraver')
            LilyPondEngraver(name='Time_signature_engraver')

        ::

            >>> score_context = lilypondnametools.LilyPondContext('Score')
            >>> custom_context in score_context.accepts
            True

        ::

            >>> custom_context.unregister()

        '''
        from abjad.ly import contexts
        from abjad.tools import lilypondnametools
        assert name not in contexts
        context_entry = {
            'accepts': set(),
            'consists': set(),
            'is_custom': True,
        }
        if alias is not None:
            if not isinstance(alias, cls):
                alias = cls(name=alias)
            assert isinstance(alias, cls)
            context_entry['accepts'].update(_.name for _ in alias.accepts)
            context_entry['consists'].update(_.name for _ in alias.engravers)
            context_entry['aliases'] = set([alias.name])
        if accepts:
            for x in accepts:
                if not isinstance(x, cls):
                    x = cls(name=x)
                assert isinstance(x, cls)
                context_entry['accepts'].add(x.name)
        if denies:
            for x in denies:
                if not isinstance(x, cls):
                    x = cls(name=x)
                assert isinstance(x, cls)
                if x.name in context_entry['accepts']:
                    context_entry['accepts'].remove(x.name)
        if consists:
            for x in consists:
                if not isinstance(x, lilypondnametools.LilyPondEngraver):
                    x = lilypondnametools.LilyPondEngraver(name=x)
                assert isinstance(x, lilypondnametools.LilyPondEngraver)
                context_entry['consists'].add(x.name)
        if removes:
            for x in removes:
                if not isinstance(x, lilypondnametools.LilyPondEngraver):
                    x = lilypondnametools.LilyPondEngraver(name=x)
                assert isinstance(x, lilypondnametools.LilyPondEngraver)
                if x.name in context_entry['consists']:
                    context_entry['consists'].remove(x.name)
        if default_child is not None:
            if not isinstance(default_child, cls):
                default_child = cls(name=default_child)
            assert isinstance(default_child, cls)
            context_entry['default_child'] = default_child.name
        accepting_contexts = set()
        if accepted_by:
            for x in accepted_by:
                if not isinstance(x, cls):
                    x = cls(name=x)
                assert isinstance(x, cls)
                accepting_contexts.add(x.name)
        contexts[name] = context_entry
        for accepting_context in accepting_contexts:
            contexts[accepting_context]['accepts'].add(name)
        custom_context = cls(name=name)
        return custom_context