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()onLabellingenum. It goes the same way with field’s validation, seeValidationenum for possible validation mechanisms.Subclasses must implement
has_data()method andchange_signalproperty.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 (
strorLabelling) – field’s label position, seeLabellingfor possible values, defaults to ‘current’ - validation (
strorValidation) – field’s validation mechanism, seeValidationfor 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: strRaises 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 = NoneType: 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
errorslist in the form ofValueErrorobjects, if the field is validerrorswill be empty.Returns: if the field is valid or not Return type: bool
-
validation¶ Field’s validation mechanism, see
Validationfor possible values.Type: strorValidation
-
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
valueandmain_componentproperties.Fieldshould 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
-