コード例 #1
0
ファイル: CodeBlock.py プロジェクト: jdavancens/abjad
 def show(self, expr, return_timing=False, **kwargs):
     r'''Proxies Abjad's toplevel `show()` function.
     '''
     from abjad.tools import abjadbooktools
     illustration = expr.__illustrate__(**kwargs)
     default_stylesheet = None
     if (
         self._console is not None and
         self._console.document_handler is not None
         ):
         handler = self._console.document_handler
         default_stylesheet = handler.get_default_stylesheet()
     image_render_specifier = self.image_render_specifier
     if image_render_specifier is None:
         image_render_specifier = abjadbooktools.ImageRenderSpecifier()
     if image_render_specifier.stylesheet is None:
         image_render_specifier = new(
             image_render_specifier,
             stylesheet=default_stylesheet,
             )
     output_proxy = abjadbooktools.LilyPondOutputProxy(
         illustration,
         image_layout_specifier=self.image_layout_specifier,
         image_render_specifier=image_render_specifier,
         )
     self.push_asset_output_proxy(output_proxy)
コード例 #2
0
 def __init__(
     self,
     payload,
     image_layout_specifier=None,
     image_render_specifier=None,
 ):
     from abjad.tools import abjadbooktools
     from abjad.tools import lilypondfiletools
     from abjad.tools import markuptools
     ImageOutputProxy.__init__(
         self,
         image_layout_specifier=image_layout_specifier,
         image_render_specifier=image_render_specifier,
     )
     payload = copy.deepcopy(payload)
     if image_render_specifier is None:
         image_render_specifier = abjadbooktools.ImageRenderSpecifier()
     if (not image_render_specifier.stylesheet
             and not image_render_specifier.no_stylesheet):
         payload = documentationtools.make_reference_manual_lilypond_file(
             payload)
     lilypond_file = payload
     assert isinstance(lilypond_file, lilypondfiletools.LilyPondFile)
     lilypond_file.header_block.tagline = markuptools.Markup('""')
     lilypond_file._date_time_token = None
     token = lilypondfiletools.LilyPondVersionToken("2.19.0", )
     lilypond_file._lilypond_version_token = token
     if (image_render_specifier.stylesheet
             and not image_render_specifier.no_stylesheet):
         if not lilypond_file.includes:
             lilypond_file._use_relative_includes = True
             includes = [image_render_specifier.stylesheet]
             lilypond_file._includes = tuple(includes)
     self._payload = lilypond_file
コード例 #3
0
 def __init__(
     self,
     payload,
     image_layout_specifier=None,
     image_render_specifier=None,
 ):
     from abjad.tools import abjadbooktools
     ImageOutputProxy.__init__(
         self,
         image_layout_specifier=image_layout_specifier,
         image_render_specifier=image_render_specifier,
     )
     payload = copy.deepcopy(payload)
     if image_render_specifier is None:
         image_render_specifier = abjadbooktools.ImageRenderSpecifier()
     if (not image_render_specifier.stylesheet
             and not image_render_specifier.no_stylesheet):
         payload = documentationtools.make_reference_manual_lilypond_file(
             payload)
     manager = systemtools.IOManager
     lilypond_file = manager._insert_expr_into_lilypond_file(payload)
     lilypond_file.file_initial_system_comments[:] = []
     token = lilypondfiletools.LilyPondVersionToken("2.19.0", )
     lilypond_file.file_initial_system_includes[0] = token
     if (image_render_specifier.stylesheet
             and not image_render_specifier.no_stylesheet):
         lilypond_file.use_relative_includes = True
         lilypond_file.file_initial_user_includes[:] = [
             image_render_specifier.stylesheet
         ]
     self._payload = lilypond_file
コード例 #4
0
    def render_svg_image(self, node):
        from abjad.tools import abjadbooktools
        # Get all file and path parts.
        image_layout_specifier = node.get('image_layout_specifier', None)
        if image_layout_specifier is None:
            image_layout_specifier = abjadbooktools.ImageLayoutSpecifier()
        image_render_specifier = node.get('image_render_specifier', None)
        if image_render_specifier is None:
            image_render_specifier = abjadbooktools.ImageRenderSpecifier()
        pages = image_layout_specifier.pages

        target_extension = '.svg'
        file_base_name = SphinxDocumentHandler.get_file_base_name(
            node, image_render_specifier)
        source_extension = SphinxDocumentHandler.get_source_extension(node)
        file_name_pattern = '{}*{}'.format(file_base_name, target_extension)
        absolute_directory_path, relative_directory_path = \
            SphinxDocumentHandler.get_image_directory_paths(self)
        relative_source_file_path = posixpath.join(
            relative_directory_path,
            file_base_name + source_extension,
        )

        # Check for pre-existing target(s).
        target_file_paths, found_all_pages = \
            SphinxDocumentHandler.find_target_file_paths(
                absolute_directory_path, relative_directory_path,
                file_name_pattern, pages)
        if found_all_pages:
            return (relative_source_file_path, target_file_paths)

        # Write and render source to target(s).
        source_file_name = file_base_name + source_extension
        absolute_source_file_path = os.path.join(absolute_directory_path,
                                                 source_file_name)
        target_file_name = file_base_name + target_extension
        absolute_target_file_path = os.path.join(absolute_directory_path,
                                                 target_file_name)
        SphinxDocumentHandler.write_image_source(self, node,
                                                 absolute_source_file_path)
        return_code = SphinxDocumentHandler.interpret_image_source(
            self,
            node,
            absolute_source_file_path,
            absolute_target_file_path,
            file_format='svg')
        if return_code:
            return (relative_directory_path, [])

        # Check for target(s).
        target_file_paths, found_all_pages = \
            SphinxDocumentHandler.find_target_file_paths(
                absolute_directory_path, relative_directory_path,
                file_name_pattern, pages)
        if not found_all_pages:
            return (relative_source_file_path, target_file_paths)

        # Target(s) must exist, so simply return.
        return (relative_source_file_path, target_file_paths)
コード例 #5
0
 def visit_abjad_output_block_html(self, node):
     from abjad.tools import abjadbooktools
     image_layout_specifier = node.get('image_layout_specifier', None)
     if image_layout_specifier is None:
         image_layout_specifier = abjadbooktools.ImageLayoutSpecifier()
     image_render_specifier = node.get('image_render_specifier', None)
     if image_render_specifier is None:
         image_render_specifier = abjadbooktools.ImageRenderSpecifier()
     if node['renderer'] not in ('graphviz', 'lilypond'):
         raise nodes.SkipNode
     absolute_image_directory_path = os.path.join(
         self.builder.outdir,
         self.builder.imagedir,
         'abjadbook',
     )
     if not os.path.exists(absolute_image_directory_path):
         os.makedirs(absolute_image_directory_path)
     try:
         if node['renderer'] == 'graphviz':
             relative_source_file_path, relative_target_file_paths = \
                 SphinxDocumentHandler.render_svg_image(self, node)
         else:
             relative_source_file_path, relative_target_file_paths = \
                 SphinxDocumentHandler.render_png_image(self, node)
         if image_layout_specifier.with_thumbnail:
             for relative_target_file_path in relative_target_file_paths:
                 self.builder.thumbnails.add_file(
                     '', relative_target_file_path)
         css_classes = set(node.get('cls', '').split())
         template = SphinxDocumentHandler._basic_template
         if image_layout_specifier.with_thumbnail:
             css_classes.add('thumbnail')
             template = SphinxDocumentHandler._thumbnail_template
         if image_layout_specifier.with_columns:
             css_classes.add('table-cell')
             stop = len(relative_target_file_paths)
             step = image_layout_specifier.with_columns
             for i in range(0, stop, step):
                 self.body.append(
                     SphinxDocumentHandler._table_row_open_template)
                 paths = relative_target_file_paths[i:i + step]
                 for relative_target_file_path in paths:
                     prefix, suffix = os.path.splitext(
                         relative_target_file_path)
                     if suffix == '.svg':
                         thumbnail_path = relative_target_file_path
                     else:
                         thumbnail_path = '{}-thumbnail{}'.format(
                             prefix, suffix)
                     result = template.format(
                         alt='',
                         cls=' '.join(sorted(css_classes)),
                         group='group-{}'.format(
                             os.path.basename(relative_source_file_path)),
                         source_path=relative_source_file_path,
                         target_path=relative_target_file_path,
                         title='',
                         thumbnail_path=thumbnail_path,
                     )
                     result = stringtools.normalize(result)
                     result = ('    ' + _ for _ in result.splitlines())
                     result = '\n'.join(result)
                     self.body.append(result)
                 self.body.append(
                     SphinxDocumentHandler._table_row_close_template)
         else:
             css_classes.add('abjadbook')
             for relative_target_file_path in relative_target_file_paths:
                 prefix, suffix = os.path.splitext(
                     relative_target_file_path)
                 if suffix == '.svg':
                     thumbnail_path = relative_target_file_path
                 else:
                     thumbnail_path = '{}-thumbnail{}'.format(
                         prefix, suffix)
                 result = template.format(
                     alt='',
                     cls=' '.join(sorted(css_classes)),
                     group='group-{}'.format(
                         os.path.basename(relative_source_file_path)),
                     source_path=relative_source_file_path,
                     target_path=relative_target_file_path,
                     title='',
                     thumbnail_path=thumbnail_path,
                 )
                 result = stringtools.normalize(result)
                 self.body.append(result)
     except:
         traceback.print_exc()
     raise nodes.SkipNode