def get_context_setting_format_contributions(component):
    r'''Get context setting format contributions for `component`.

    Returns sorted list.
    '''
    result = []
    from abjad.tools.leaftools.Leaf import Leaf
    from abjad.tools.measuretools.Measure import Measure
    from abjad.tools.lilypondfiletools._format_lilypond_context_setting_inline import _format_lilypond_context_setting_inline
    from abjad.tools.lilypondfiletools._format_lilypond_context_setting_in_with_block import _format_lilypond_context_setting_in_with_block
    if isinstance(component, (Leaf, Measure)):
        for name, value in vars(component.set).iteritems():
            # if we've found a leaf LilyPondContextNamespace
            if name.startswith('_'):
                # parse all the public names in the LilyPondContextNamespace
                for x, y in vars(value).iteritems():
                    if not x.startswith('_'):
                        result.append(_format_lilypond_context_setting_inline(x, y, name))
            # otherwise we've found a default leaf context setting
            else:
                # parse default context setting
                result.append(_format_lilypond_context_setting_inline(name, value))
    else:
        for name, value in vars(component.set).iteritems():
            result.append(_format_lilypond_context_setting_in_with_block(name, value))
    result.sort()
    return ['context settings', result]
Example #2
0
 def _format_pieces(self):
     from abjad.tools.lilypondfiletools._format_lilypond_context_setting_in_with_block \
         import _format_lilypond_context_setting_in_with_block
     result = []
     result.append('%s {' % self._escaped_name)
     # CAUTION: source context name must come before type to allow 
     # context redefinition.
     # TODO: rename self.context_name to self.source_context_name
     if self.context_name is not None:
         result.append('\t' + r'\%s' % self.context_name)
     if self.name is not None:
         result.append('\t' + r'\name %s' % self.name)
     if self.type is not None:
         result.append('\t' + r'\type %s' % self.type)
     if self.alias is not None:
         result.append('\t' + r'\alias %s' % self.alias)
     for string in self.engraver_removals:
         result.append('\t' + r'\remove %s' % string)
     # CAUTION: LilyPond consist statements are order-significant!
     for string in self.engraver_consists:
         result.append('\t' + r'\consists %s' % string)
     for string in self.accepts:
         result.append('\t' + r'\accepts %s' % string)
     for override in self.override._list_format_contributions('override'):
         result.append('\t' + override)
     setting_contributions = []
     for key, value in self.set._get_attribute_tuples():
         setting_contribution = \
             _format_lilypond_context_setting_in_with_block(key, value)
         setting_contributions.append(setting_contribution)
     for setting_contribution in sorted(setting_contributions):
         result.append('\t' + setting_contribution)
     result.append('}')
     return result