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


Python roman.toRoman方法代码示例

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


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

示例1: setPageCounter

# 需要导入模块: from docutils.utils import roman [as 别名]
# 或者: from docutils.utils.roman import toRoman [as 别名]
def setPageCounter(counter=None, style=None):

    global _counter, _counterStyle

    if counter is not None:
        _counter = counter
    if style is not None:
        _counterStyle = style

    if _counterStyle == 'lowerroman':
        ptext = toRoman(_counter).lower()
    elif _counterStyle == 'roman':
        ptext = toRoman(_counter).upper()
    elif _counterStyle == 'alpha':
        ptext = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[_counter % 26]
    elif _counterStyle == 'loweralpha':
        ptext = 'abcdefghijklmnopqrstuvwxyz'[_counter % 26]
    else:
        ptext = str(_counter)
    return ptext 
开发者ID:rst2pdf,项目名称:rst2pdf,代码行数:22,代码来源:createpdf.py

示例2: make_enumerator

# 需要导入模块: from docutils.utils import roman [as 别名]
# 或者: from docutils.utils.roman import toRoman [as 别名]
def make_enumerator(self, ordinal, sequence, format):
        """
        Construct and return the next enumerated list item marker, and an
        auto-enumerator ("#" instead of the regular enumerator).

        Return ``None`` for invalid (out of range) ordinals.
        """ #"
        if sequence == '#':
            enumerator = '#'
        elif sequence == 'arabic':
            enumerator = str(ordinal)
        else:
            if sequence.endswith('alpha'):
                if ordinal > 26:
                    return None
                enumerator = chr(ordinal + ord('a') - 1)
            elif sequence.endswith('roman'):
                try:
                    enumerator = roman.toRoman(ordinal)
                except roman.RomanError:
                    return None
            else:                       # shouldn't happen
                raise ParserError('unknown enumerator sequence: "%s"'
                                  % sequence)
            if sequence.startswith('lower'):
                enumerator = enumerator.lower()
            elif sequence.startswith('upper'):
                enumerator = enumerator.upper()
            else:                       # shouldn't happen
                raise ParserError('unknown enumerator sequence: "%s"'
                                  % sequence)
        formatinfo = self.enum.formatinfo[format]
        next_enumerator = (formatinfo.prefix + enumerator + formatinfo.suffix
                           + ' ')
        auto_enumerator = formatinfo.prefix + '#' + formatinfo.suffix + ' '
        return next_enumerator, auto_enumerator 
开发者ID:skarlekar,项目名称:faces,代码行数:38,代码来源:states.py

示例3: section

# 需要导入模块: from docutils.utils import roman [as 别名]
# 或者: from docutils.utils.roman import toRoman [as 别名]
def section(self, level):
        """Return the LaTeX section name for section `level`.

        The name depends on the specific document class.
        Level is 1,2,3..., as level 0 is the title.
        """
        if level <= len(self.sections):
            return self.sections[level-1]
        else:  # unsupported levels
            return 'DUtitle[section%s]' % roman.toRoman(level) 
开发者ID:skarlekar,项目名称:faces,代码行数:12,代码来源:__init__.py

示例4: list_start

# 需要导入模块: from docutils.utils import roman [as 别名]
# 或者: from docutils.utils.roman import toRoman [as 别名]
def list_start(self, node):
        class enum_char(object):
            enum_style = {
                    'bullet'     : '\\(bu',
                    'emdash'     : '\\(em',
                     }

            def __init__(self, style):
                self._style = style
                if 'start' in node:
                    self._cnt = node['start'] - 1
                else:
                    self._cnt = 0
                self._indent = 2
                if style == 'arabic':
                    # indentation depends on number of childrens
                    # and start value.
                    self._indent = len(str(len(node.children)))
                    self._indent += len(str(self._cnt)) + 1
                elif style == 'loweralpha':
                    self._cnt += ord('a') - 1
                    self._indent = 3
                elif style == 'upperalpha':
                    self._cnt += ord('A') - 1
                    self._indent = 3
                elif style.endswith('roman'):
                    self._indent = 5

            def __next__(self):
                if self._style == 'bullet':
                    return self.enum_style[self._style]
                elif self._style == 'emdash':
                    return self.enum_style[self._style]
                self._cnt += 1
                # TODO add prefix postfix
                if self._style == 'arabic':
                    return "%d." % self._cnt
                elif self._style in ('loweralpha', 'upperalpha'):
                    return "%c." % self._cnt
                elif self._style.endswith('roman'):
                    res = roman.toRoman(self._cnt) + '.'
                    if self._style.startswith('upper'):
                        return res.upper()
                    return res.lower()
                else:
                    return "%d." % self._cnt
            def get_width(self):
                return self._indent
            def __repr__(self):
                return 'enum_style-%s' % list(self._style)

        if 'enumtype' in node:
            self._list_char.append(enum_char(node['enumtype']))
        else:
            self._list_char.append(enum_char('bullet'))
        if len(self._list_char) > 1:
            # indent nested lists
            self.indent(self._list_char[-2].get_width())
        else:
            self.indent(self._list_char[-1].get_width()) 
开发者ID:skarlekar,项目名称:faces,代码行数:62,代码来源:manpage.py

示例5: visit_enumerated_list

# 需要导入模块: from docutils.utils import roman [as 别名]
# 或者: from docutils.utils.roman import toRoman [as 别名]
def visit_enumerated_list(self, node):
        # enumeration styles:
        types = {'': '',
                  'arabic':'arabic',
                  'loweralpha':'alph',
                  'upperalpha':'Alph',
                  'lowerroman':'roman',
                  'upperroman':'Roman'}
        # the 4 default LaTeX enumeration labels: präfix, enumtype, suffix,
        labels = [('',  'arabic', '.'), #  1.
                  ('(', 'alph',   ')'), # (a)
                  ('',  'roman',  '.'), #  i.
                  ('',  'Alph',   '.')] #  A.

        prefix = ''
        if self.compound_enumerators:
            if (self.section_prefix_for_enumerators and self.section_level
                and not self._enumeration_counters):
                prefix = '.'.join([str(n) for n in
                                   self._section_number[:self.section_level]]
                                 ) + self.section_enumerator_separator
            if self._enumeration_counters:
                prefix += self._enumeration_counters[-1]
        # TODO: use LaTeX default for unspecified label-type?
              # (needs change of parser)
        prefix += node.get('prefix', '')
        enumtype = types[node.get('enumtype' '')]
        suffix = node.get('suffix', '')

        enumeration_level = len(self._enumeration_counters)+1
        counter_name = 'enum' + roman.toRoman(enumeration_level).lower()
        label = r'%s\%s{%s}%s' % (prefix, enumtype, counter_name, suffix)
        self._enumeration_counters.append(label)

        if enumeration_level <= 4:
            self.out.append('\\begin{enumerate}\n')
            if (prefix, enumtype, suffix
               ) != labels[enumeration_level-1]:
                self.out.append('\\renewcommand{\\label%s}{%s}\n' %
                                (counter_name, label))
        else:
            self.fallbacks[counter_name] = '\\newcounter{%s}' % counter_name
            self.out.append('\\begin{list}')
            self.out.append('{%s}' % label)
            self.out.append('{\\usecounter{%s}}\n' % counter_name)
        if 'start' in node:
            self.out.append('\\setcounter{%s}{%d}\n' %
                            (counter_name,node['start']-1))
        #     ## set rightmargin equal to leftmargin
        #     self.out.append('\\setlength{\\rightmargin}{\\leftmargin}\n') 
开发者ID:skarlekar,项目名称:faces,代码行数:52,代码来源:__init__.py

示例6: visit_enumerated_list

# 需要导入模块: from docutils.utils import roman [as 别名]
# 或者: from docutils.utils.roman import toRoman [as 别名]
def visit_enumerated_list(self, node):
        # enumeration styles:
        types = {'': '',
                  'arabic':'arabic',
                  'loweralpha':'alph',
                  'upperalpha':'Alph',
                  'lowerroman':'roman',
                  'upperroman':'Roman'}
        # the 4 default LaTeX enumeration labels: präfix, enumtype, suffix,
        labels = [('',  'arabic', '.'), #  1.
                  ('(', 'alph',   ')'), # (a)
                  ('',  'roman',  '.'), #  i.
                  ('',  'Alph',   '.')] #  A.

        prefix = ''
        if self.compound_enumerators:
            if (self.section_prefix_for_enumerators and self.section_level
                and not self._enumeration_counters):
                prefix = '.'.join([str(n) for n in
                                   self._section_number[:self.section_level]]
                                 ) + self.section_enumerator_separator
            if self._enumeration_counters:
                prefix += self._enumeration_counters[-1]
        # TODO: use LaTeX default for unspecified label-type?
        #       (needs change of parser)
        prefix += node.get('prefix', '')
        enumtype = types[node.get('enumtype' '')]
        suffix = node.get('suffix', '')

        enumeration_level = len(self._enumeration_counters)+1
        counter_name = 'enum' + roman.toRoman(enumeration_level).lower()
        label = r'%s\%s{%s}%s' % (prefix, enumtype, counter_name, suffix)
        self._enumeration_counters.append(label)

        self.duclass_open(node)
        if enumeration_level <= 4:
            self.out.append('\\begin{enumerate}')
            if (prefix, enumtype, suffix
               ) != labels[enumeration_level-1]:
                self.out.append('\n\\renewcommand{\\label%s}{%s}' %
                                (counter_name, label))
        else:
            self.fallbacks[counter_name] = '\\newcounter{%s}' % counter_name
            self.out.append('\\begin{list}')
            self.out.append('{%s}' % label)
            self.out.append('{\\usecounter{%s}}' % counter_name)
        if 'start' in node:
            self.out.append('\n\\setcounter{%s}{%d}' %
                            (counter_name,node['start']-1)) 
开发者ID:QData,项目名称:deepWordBug,代码行数:51,代码来源:__init__.py

示例7: list_start

# 需要导入模块: from docutils.utils import roman [as 别名]
# 或者: from docutils.utils.roman import toRoman [as 别名]
def list_start(self, node):
        class enum_char(object):
            enum_style = {
                    'bullet'     : '\\(bu',
                    'emdash'     : '\\(em',
                     }

            def __init__(self, style):
                self._style = style
                if node.has_key('start'):
                    self._cnt = node['start'] - 1
                else:
                    self._cnt = 0
                self._indent = 2
                if style == 'arabic':
                    # indentation depends on number of childrens
                    # and start value.
                    self._indent = len(str(len(node.children)))
                    self._indent += len(str(self._cnt)) + 1
                elif style == 'loweralpha':
                    self._cnt += ord('a') - 1
                    self._indent = 3
                elif style == 'upperalpha':
                    self._cnt += ord('A') - 1
                    self._indent = 3
                elif style.endswith('roman'):
                    self._indent = 5

            def next(self):
                if self._style == 'bullet':
                    return self.enum_style[self._style]
                elif self._style == 'emdash':
                    return self.enum_style[self._style]
                self._cnt += 1
                # TODO add prefix postfix
                if self._style == 'arabic':
                    return "%d." % self._cnt
                elif self._style in ('loweralpha', 'upperalpha'):
                    return "%c." % self._cnt
                elif self._style.endswith('roman'):
                    res = roman.toRoman(self._cnt) + '.'
                    if self._style.startswith('upper'):
                        return res.upper()
                    return res.lower()
                else:
                    return "%d." % self._cnt
            def get_width(self):
                return self._indent
            def __repr__(self):
                return 'enum_style-%s' % list(self._style)

        if node.has_key('enumtype'):
            self._list_char.append(enum_char(node['enumtype']))
        else:
            self._list_char.append(enum_char('bullet'))
        if len(self._list_char) > 1:
            # indent nested lists
            self.indent(self._list_char[-2].get_width())
        else:
            self.indent(self._list_char[-1].get_width()) 
开发者ID:jmwright,项目名称:cadquery-freecad-module,代码行数:62,代码来源:manpage.py


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