Great guys.
Duffanator, here’s to answer your question about classes in the project.pa.forms Python module:
The FormInput class is defined and used as a way to treat all form input components the same way.
A new instance of a FormInput class is created by passing in a form input component argument to the constructor, like this: formInputInstance = FormInput(formInputComponent). A FormInput instance provides a common set of methods to access data and functionality for any form input component.
New instances of the FormInput class are created in one place, in the getInputs function, which is here:
def getInputs(formContainer):
"""
Get all form input components in a Form Container.
"""
inputs = []
for comp in formContainer.getComponents():
if isinstance(comp,BasicContainer):
if not hasattr(comp,"Column"):
inputs.extend(getInputs(comp))
continue
inputs.append(FormInput(comp))
return inputs
Notice this line: “inputs.append(FormInput(comp))”. This is creating a new FormInput instance from a form input component and appending it to the list of other FormInput instances.
The form input components are the form components that have a “Column” custom property. Some of these are the “Form Text Field”, “Form Numeric Text Field”, “Form Dropdown List” and “Form Radio Buttons”.
The getInputs function finds each input form component, creates a FormInput instance with it and adds it to a list. When all the input form components are found the list of FormInput instances are returned.
Here’s a couple examples to show you how this is used. Normally to get the value from a Form Text Field component you have to use this code:
value = formTextField.getComponent("Text Field").text
And if you want to get a value from the Form Dropdown List component you have to use this code:
dropdownList = formDropdownList.getComponent("Dropdown List")
value = getattr(dropdownList,dropdownList.ValueProperty)
But if you create FormInput instances of these two form input components then accessing the value is done in the same way:
formTextField = FormInput(formTextField)
formDropdownList = FormInput(formDropdownList)
value = formTextField.getValue()
value = formDropdownList.getValue()
Besides getValue() the FormInput class provides other uniform functions for form input components such as setValue(), clearValue(), and more can be added as needed in the future.
So the getInputs() function returns a list of all form input componets as FormInput instances. This makes it easy to loop through all form inputs and perform an operation on all of them. For example:
inputs = getInputs(formContainer)
for input in inputs:
print input.getValue()
How is this? Any other questions?
Best,