本文整理汇总了Python中forms.Form.add_prompt方法的典型用法代码示例。如果您正苦于以下问题:Python Form.add_prompt方法的具体用法?Python Form.add_prompt怎么用?Python Form.add_prompt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.Form
的用法示例。
在下文中一共展示了Form.add_prompt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import add_prompt [as 别名]
def __init__(self, mt, title, choices,
prompt=None, line_skip=0, margin_top=0, prompt_line=None, addit=None,
cancelable=True
):
"""
Parameters:
mt (:py:class:`Minitel`): the Minitel instance
title (str or list of str): the menu title, displayed centered on the screen
choices (list of str): the options
prompt (str): the prompt displayed with the input field. Default: "Your choice"
line_skip (int): vertical space between options. Default (0) places options on consecutive lines
margin_top (int): vertical space before the menu title. Default: 0
prompt_line (int): line number on which the input prompt is displayed
addit (list of tuple): additional prompts as a list of (x, y, text) tuples
cancelable (bool): if True, the cancel key (SOMMAIRE) can be used, and `get_choice` will exit
and return None. If False, the cancel key will be treated as an invalid choice.
"""
if not mt:
raise ValueError('mt parameter is mandatory')
if not choices:
raise ValueError('choices parameter must be an iterable of option labels')
if len(choices) < 2:
raise ValueError('choices must contain at least 2 items')
if isinstance(title, basestring):
title = [title]
if not prompt:
prompt = "Your choice"
addit = addit or []
choice_max = len(choices)
prompt = "%s [1..%d] : " % (prompt, choice_max)
prompt_text = prompt + ('..' if choice_max > 9 else '.') + " + ENVOI"
x_prompt = max(0, (40 - len(prompt_text)) / 2)
form = Form(mt)
y = margin_top
for line in title:
form.add_prompt(0, y, line.center(40))
y += 1
choice_lines = ["%2d - %s" % (i + 1, s) for i, s in enumerate(choices)]
max_len = max(len(s) for s in choice_lines)
x = max(0, (40 - max_len) / 2)
y += 1
y_inc = line_skip + 1
for line in choice_lines:
form.add_prompt(x, y, line)
y += y_inc
y = prompt_line or y + 1
form.add_prompt(x_prompt, y, prompt_text)
form.add_field('choice', x_prompt + len(prompt), y, 1 if choice_max < 10 else 2)
for addit_prompt in addit:
form.add_prompt(*addit_prompt)
self._mt = mt
self._form = form
self._choice_max = choice_max
self._cancelable = cancelable