core module¶
-
class
campos.core.
Field
(*args, name='', text='', description='', default=None, on_change=None, labelling='current', validation='current', validators=(), required=False, message=None)[source]¶ Base class for input fields, isn’t generally used directly.
A field is usually composed of a label and an input component. The field’s label position can be changed individually by modifying labelling property or globally by calling
set_current()
onLabelling
enum. It goes the same way with field’s validation, seeValidation
enum for possible validation mechanisms.Subclasses must implement
has_data()
method andchange_signal
property.Parameters: - name (
str
) – text to identify the field inside forms or other contexts, must be a valid variable name, it defaults tofield{consecutive_number}
- text (
str
) – text to show in field’s label, it defaults toname
- description (
str
) – useful short information about the field, usually shown as a tooltip - default – default value when field is shown by first time
- on_change (callable) – handler to call when field’s value changes, this is a
shortcut and it only supports one handler at a time,
if you want to connect multiple handlers you should use
field.change_signal.connect(handler)
for each handler - labelling (
str
orLabelling
) – field’s label position, seeLabelling
for possible values, defaults to ‘current’ - validation (
str
orValidation
) – field’s validation mechanism, seeValidation
for possible values, defaults to ‘current’ - validators (iterable of
Validator
) – validators used to process field’s value when validation is invoked - required (
bool
) – marks this field as required or not, this a shortcut forfield.validators.append(DataRequired())
- message (
str
) – text to show if field is invalid, if set, this message has priority over validators’ messages
-
change_signal
¶ Returns a valid Qt signal which is fired whenever the field’s value changes
Return type: callable
-
description
¶ Useful short information about the field, usually shown as a tooltip.
Type: str
-
has_data
()[source]¶ Check if the field has any data.
Returns: True only if the field contains any data Return type: bool
-
name
¶ Text to identify the field inside forms or other contexts, must be a valid variable name, it defaults to
field{consecutive_number}
Type: str
Raises ValueError: if an invalid field name is given
-
on_change
¶ Handler to call when field’s value changes, this is a shortcut and it only supports one handler at a time, if you want to connect multiple handlers you should use
field.change_signal.connect(handler)
for each handler.To disconnect a connected handler just set
on_change = None
Type: callable or None
-
required
¶ Marks this field as required or not, this a shortcut for
field.validators.append(DataRequired())
Type: bool
-
text
¶ Text to show in the field’s label.
Type: str
-
validate
()[source]¶ Validates field’s current value using current validators. After validation all errors are stored in
errors
list in the form ofValueError
objects, if the field is validerrors
will be empty.Returns: if the field is valid or not Return type: bool
-
validation
¶ Field’s validation mechanism, see
Validation
for possible values.Type: str
orValidation
-
value
¶ Field’s current value
- name (
-
class
campos.core.
BaseField
(*args, **kwargs)[source]¶ More complete base class for fields, implementing a common use case scenario.
This class assumes that a field is composed by a label, a central component (usually where the value is entered) and other label used to show validation errors.
In order to create new fields following this structure is only necessary to implement
value
andmain_component
properties.Field
should be used as base class to create fields without this structure.-
main_component
¶ Returns a valid QWidget or QLayout holding the main part of the field(without text and error labels)
Return type: QWidget or QLayout
-