Пример #1
0
def get_form_input(fields, title):
	"""
	``get_from_input`` Prompts the user for a set of inputs specified in ``fields`` with given title.
	The fields parameter is a list which can contain the following types:
		- str  - an alias for LabelField
		- None - an alias for SeparatorField
		- LabelField         - Text output
		- SeparatorField     - Vertical spacing
		- TextLineField      - Prompt for a string value
		- MultilineTextField - Prompt for multi-line string value
		- IntegerField       - Prompt for an integer
		- AddressField       - Prompt for an address
		- ChoiceField        - Prompt for a choice from provided options
		- OpenFileNameField  - Prompt for file to open
		- SaveFileNameField  - Prompt for file to save to
		- DirectoryNameField - Prompt for directory name
	This API is flexible and works both in the UI via a popup dialog and on the command line.
	:params list fields: A list containing of the above specified classes, strings or None
	:params str title: The title of the popup dialog.
	:Example:

		>>> int_f = IntegerField("Specify Integer")
		>>> tex_f = TextLineField("Specify name")
		>>> choice_f = ChoiceField("Options", ["Yes", "No", "Maybe"])
		>>> get_form_input(["Get Data", None, int_f, tex_f, choice_f], "The options")
		Get Data

		Specify Integer 1337
		Specify name Peter
		The options
		1) Yes
		2) No
		3) Maybe
		Options 1
		>>> True
		>>> print tex_f.result, int_f.result, choice_f.result
		Peter 1337 0
	"""
	value = (core.BNFormInputField * len(fields))()
	for i in xrange(0, len(fields)):
		if isinstance(fields[i], str):
			LabelField(fields[i])._fill_core_struct(value[i])
		elif fields[i] is None:
			SeparatorField()._fill_core_struct(value[i])
		else:
			fields[i]._fill_core_struct(value[i])
	if not core.BNGetFormInput(value, len(fields), title):
		return False
	for i in xrange(0, len(fields)):
		if not (isinstance(fields[i], str) or (fields[i] is None)):
			fields[i]._get_result(value[i])
	core.BNFreeFormInputResults(value, len(fields))
	return True
Пример #2
0
def get_form_input(fields, title):
    value = (core.BNFormInputField * len(fields))()
    for i in xrange(0, len(fields)):
        if isinstance(fields[i], str):
            LabelField(fields[i])._fill_core_struct(value[i])
        elif fields[i] is None:
            SeparatorField()._fill_core_struct(value[i])
        else:
            fields[i]._fill_core_struct(value[i])
    if not core.BNGetFormInput(value, len(fields), title):
        return False
    for i in xrange(0, len(fields)):
        if not (isinstance(fields[i], str) or (fields[i] is None)):
            fields[i]._get_result(value[i])
    core.BNFreeFormInputResults(value, len(fields))
    return True