当前位置: 首页>>代码示例>>Python>>正文


Python nodes.image方法代码示例

本文整理汇总了Python中docutils.nodes.image方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.image方法的具体用法?Python nodes.image怎么用?Python nodes.image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docutils.nodes的用法示例。


在下文中一共展示了nodes.image方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: visit_reference

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def visit_reference(self, node):
        atts = {'class': 'reference'}
        if 'refuri' in node:
            atts['href'] = node['refuri']
            if ( self.settings.cloak_email_addresses
                 and atts['href'].startswith('mailto:')):
                atts['href'] = self.cloak_mailto(atts['href'])
                self.in_mailto = True
            atts['class'] += ' external'
        else:
            assert 'refid' in node, \
                   'References must have "refuri" or "refid" attribute.'
            atts['href'] = '#' + node['refid']
            atts['class'] += ' internal'
        if not isinstance(node.parent, nodes.TextElement):
            assert len(node) == 1 and isinstance(node[0], nodes.image)
            atts['class'] += ' image-reference'
        self.body.append(self.starttag(node, 'a', '', **atts)) 
开发者ID:skarlekar,项目名称:faces,代码行数:20,代码来源:_html_base.py

示例2: get_image_node

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def get_image_node(self, source):
        file_name = self.name_source_snippet(source)
        file_path = os.path.join(VISUAL_EXAMPLES_DIR, file_name)

        env = self.state.document.settings.env

        if all([
            render_snippet,
            env.config['render_examples'],
            not os.environ.get('SPHINX_DISABLE_RENDER', False),
        ]):
            try:
                render_snippet(
                    source, file_path,
                    output_dir=SOURCE_DIR, **self.options
                )
            except:
                print("problematic code:\n%s" % source)
                raise

        img = nodes.image()
        img['uri'] = "/" + file_path
        return img 
开发者ID:swistakm,项目名称:pyimgui,代码行数:25,代码来源:custom_directives.py

示例3: link

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def link(self, url, text=None, image_url=None, image_height=None, image_width=None):
        """
        Shows a link.
        Link can be a text, an image or both

        :param url:
        :param text:
        :param image_url:
        :param image_height:
        :param image_width:
        :return:
        """

        if text is None:  # May be needed if only image shall be shown
            text = ''

        link_node = nodes.reference(text, text, refuri=url)

        if image_url is not None:
            image_node = self.image(image_url, image_height, image_width)
            link_node.append(image_node)

        return link_node 
开发者ID:useblocks,项目名称:sphinxcontrib-needs,代码行数:25,代码来源:layout.py

示例4: make_thumbnail

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def make_thumbnail(self, imgfilename_inrst):
        """
        Make thumbnail and return (html) path to image

        Parameters
        ----------
        imgfilename_rst : rst
            Image filename (relative path), as it appears in the
            ReST file (coverted).
        """
        builddir = self.env.app.outdir

        imgfilename_src = os.path.join(DOC_PATH, imgfilename_inrst)

        thumbfilename = self.thumbfilename(imgfilename_inrst)
        thumbfilename_inhtml = os.path.join('_images', thumbfilename)
        thumbfilename_dest = os.path.join(builddir, '_images', thumbfilename)

        im = Image.open(imgfilename_src)
        im.thumbnail(thumbnail_size)
        im.save(thumbfilename_dest)
        return thumbfilename_inhtml 
开发者ID:has2k1,项目名称:plotnine,代码行数:24,代码来源:examples_and_gallery.py

示例5: test_caption_option

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def test_caption_option(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. rackdiag::\n"
                "   :caption: hello world\n"
                "\n"
                "   1: server\n"
                "   2: database\n")
        doctree = publish_doctree(text)
        self.assertEqual(1, len(doctree))
        self.assertEqual(nodes.figure, type(doctree[0]))
        self.assertEqual(2, len(doctree[0]))
        self.assertEqual(nodes.image, type(doctree[0][0]))
        self.assertEqual(nodes.caption, type(doctree[0][1]))
        self.assertEqual(1, len(doctree[0][1]))
        self.assertEqual(nodes.Text, type(doctree[0][1][0]))
        self.assertEqual('hello world', doctree[0][1][0]) 
开发者ID:blockdiag,项目名称:nwdiag,代码行数:18,代码来源:test_rst_directives.py

示例6: test_caption_option_and_align_option

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def test_caption_option_and_align_option(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. rackdiag::\n"
                "   :align: left\n"
                "   :caption: hello world\n"
                "\n"
                "   1: server\n"
                "   2: database\n")
        doctree = publish_doctree(text)
        self.assertEqual(1, len(doctree))
        self.assertEqual(nodes.figure, type(doctree[0]))
        self.assertEqual('left', doctree[0]['align'])
        self.assertEqual(2, len(doctree[0]))
        self.assertEqual(nodes.image, type(doctree[0][0]))
        self.assertNotIn('align', doctree[0][0])
        self.assertEqual(nodes.caption, type(doctree[0][1]))
        self.assertEqual(1, len(doctree[0][1]))
        self.assertEqual(nodes.Text, type(doctree[0][1][0]))
        self.assertEqual('hello world', doctree[0][1][0]) 
开发者ID:blockdiag,项目名称:nwdiag,代码行数:21,代码来源:test_rst_directives.py

示例7: get_tokens

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def get_tokens(self, txtnodes):
        # A generator that yields ``(texttype, nodetext)`` tuples for a list
        # of "Text" nodes (interface to ``smartquotes.educate_tokens()``).

        texttype = {True: 'literal', # "literal" text is not changed:
                    False: 'plain'}
        for txtnode in txtnodes:
            nodetype = texttype[isinstance(txtnode.parent,
                                           (nodes.literal,
                                            nodes.math,
                                            nodes.image,
                                            nodes.raw,
                                            nodes.problematic))]
            yield (nodetype, txtnode.astext()) 
开发者ID:skarlekar,项目名称:faces,代码行数:16,代码来源:universal.py

示例8: figwidth_value

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def figwidth_value(argument):
        if argument.lower() == 'image':
            return 'image'
        else:
            return directives.length_or_percentage_or_unitless(argument, 'px') 
开发者ID:skarlekar,项目名称:faces,代码行数:7,代码来源:images.py

示例9: apply

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def apply(self, **kwargs):
        # only handle those not otherwise defined in the document
        to_handle = self.emojis - set(self.document.substitution_defs)
        for ref in self.document.traverse(nodes.substitution_reference):
            refname = ref['refname']
            if refname in to_handle:
                node = nodes.image(
                    uri='http://www.tortue.me/emoji/{0}.png'.format(refname),
                    alt=refname,
                    classes=['emoji'],
                    height="24px",
                    width="24px")
                ref.replace_self(node) 
开发者ID:mgaitan,项目名称:waliki,代码行数:15,代码来源:transforms.py

示例10: process_image

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def process_image(self, decorator):
        """
        # build out an image directive like
        # .. image:: somefile.png
        #    :width 4in
        #
        # from an input like
        # savefig somefile.png width=4in
        """
        savefig_dir = self.savefig_dir
        source_dir = self.source_dir
        saveargs = decorator.split(' ')
        filename = saveargs[1]
        # insert relative path to image file in source
        outfile = os.path.relpath(os.path.join(savefig_dir,filename),
                    source_dir)

        imagerows = ['.. image:: %s'%outfile]

        for kwarg in saveargs[2:]:
            arg, val = kwarg.split('=')
            arg = arg.strip()
            val = val.strip()
            imagerows.append('   :%s: %s'%(arg, val))

        image_file = os.path.basename(outfile) # only return file name
        image_directive = '\n'.join(imagerows)
        return image_file, image_directive


    # Callbacks for each type of token 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:33,代码来源:ipython_directive.py

示例11: save_image

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def save_image(self, image_file):
        """
        Saves the image file to disk.
        """
        self.ensure_pyplot()
        command = 'plt.gcf().savefig("%s")'%image_file
        #print 'SAVEFIG', command  # dbg
        self.process_input_line('bookmark ipy_thisdir', store_history=False)
        self.process_input_line('cd -b ipy_savedir', store_history=False)
        self.process_input_line(command, store_history=False)
        self.process_input_line('cd -b ipy_thisdir', store_history=False)
        self.process_input_line('bookmark -d ipy_thisdir', store_history=False)
        self.clear_cout() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,代码来源:ipython_directive.py

示例12: process_block

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def process_block(self, block):
        """
        process block from the block_parser and return a list of processed lines
        """
        ret = []
        output = None
        input_lines = None
        lineno = self.IP.execution_count

        input_prompt = self.promptin%lineno
        output_prompt = self.promptout%lineno
        image_file = None
        image_directive = None

        for token, data in block:
            if token==COMMENT:
                out_data = self.process_comment(data)
            elif token==INPUT:
                (out_data, input_lines, output, is_doctest, image_file,
                    image_directive) = \
                          self.process_input(data, input_prompt, lineno)
            elif token==OUTPUT:
                out_data = \
                    self.process_output(data, output_prompt,
                                        input_lines, output, is_doctest,
                                        image_file)
            if out_data:
                ret.extend(out_data)

        # save the image files
        if image_file is not None:
            self.save_image(image_file)

        return ret, image_directive 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:36,代码来源:ipython_directive.py

示例13: apply

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import image [as 别名]
def apply(self):
        thebe_config = self.config.jupyter_sphinx_thebelab_config

        for cell_node in self.document.traverse(JupyterCellNode):
            (output_bundle_node,) = cell_node.traverse(CellOutputBundleNode)

            # Create doctree nodes for cell outputs.
            output_nodes = cell_output_to_nodes(
                output_bundle_node.outputs,
                self.config.jupyter_execute_data_priority,
                bool(cell_node.attributes["stderr"]),
                sphinx_abs_dir(self.env),
                thebe_config,
            )
            # Remove the outputbundlenode and we'll attach the outputs next
            attach_outputs(output_nodes, cell_node, thebe_config, cell_node.cm_language)

        # Image collect extra nodes from cell outputs that we need to process
        for node in self.document.traverse(image):
            # If the image node has `candidates` then it's already been processed
            # as in-line content, so skip it
            if "candidates" in node:
                continue
            # re-initialize an ImageCollector because the `app` imagecollector instance
            # is only available via event listeners.
            col = ImageCollector()
            col.process_doc(self.app, node) 
开发者ID:jupyter,项目名称:jupyter-sphinx,代码行数:29,代码来源:ast.py


注:本文中的docutils.nodes.image方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。