forms¶
Classes to layout fields on a form. These are mostly used for specifying the form_display attribute in Admin classes, but they can be used on their own as well. Form classes can be used recursive.
- class camelot.view.forms.DelayedTabWidget(widgets, tabs, parent=None)[source]¶
Helper class for TabForm to delay the creation of tabs to the moment the tab is shown.
- class camelot.view.forms.Form(content, scrollbars=False, columns=1)[source]¶
Base Form class to put fields on a form. The base class of a form is a list. So the form itself is nothing more than a list of field names or sub-forms. A form can thus be manipulated using the list’s method such as append or insert.
A form can be converted to a Qt widget by calling its render method.
Forms are defined using the form_display attribute of an Admin class:
class Admin( EntityAdmin ): form_display = Form( [ 'title', 'short_description', 'release_date' ] )
and takes these parameters :
param content: an iterable with field names or sub-forms to render param columns: the number of columns in which to order the fields. - remove_field(original_field)[source]¶
Remove a field from the form, This function can be used to modify inherited forms.
Parameters: original_field – the name of the field to be removed Returns: True if the field was found and removed
- render(widgets, parent=None, toplevel=False)[source]¶
Parameters: - widgets – a camelot.view.controls.formview.FormEditors object that is able to create the widgets for this form
- parent – the QtWidgets.QWidget in which the form is placed
- toplevel – a boolean indicating if this form is toplevel, or a child form of another form. A toplevel form will be expanding, while a non toplevel form is only expanding if it contains other expanding elements.
Returns: a QtWidgets.QWidget into which the form is rendered
- replace_field(original_field, new_field)[source]¶
Replace a field on this form with another field. This function can be used to modify inherited forms.
:param original_field : the name of the field to be replace :param new_field : the name of the new field :return: True if the original field was found and replaced
- class camelot.view.forms.GridForm(grid, nomargins=False)[source]¶
Put different fields into a grid, without a label. Row or column labels can be added using the Label form:
GridForm([['title', 'short_description'], ['director','release_date']])
- class camelot.view.forms.GroupBoxForm(title, content, scrollbars=None, min_width=None, min_height=None, columns=1)[source]¶
Renders a form within a QGroupBox:
class Admin(EntityAdmin): form_display = GroupBoxForm('Movie', ['title', 'short_description'])
- class camelot.view.forms.HBoxForm(columns, scrollbars=False)[source]¶
Render different forms in a horizontal box:
form = forms.HBoxForm([['title', 'short_description'], ['director', 'release_date']])
- class camelot.view.forms.Label(label, alignment='left', style=None)[source]¶
Render a label using a QtWidgets.QLabel
- class camelot.view.forms.Stretch[source]¶
A stretchable space with zero minimum size, this is able to fill a gap in the form if there are no other items to fill this space.
- class camelot.view.forms.TabForm(tabs, position='North')[source]¶
Render forms within a QtWidgets.QTabWidget:
from = TabForm([('First tab', ['title', 'short_description']), ('Second tab', ['director', 'release_date'])])
- add_tab(tab_label, tab_form)[source]¶
Add a tab to the form
Parameters: - tab_label – the name of the tab
- tab_form – the form to display in the tab or a list of field names.
- class camelot.view.forms.VBoxForm(rows)[source]¶
Render different forms or widgets in a vertical box:
form = forms.VBoxForm([['title', 'short_description'], ['director', 'release_date']])
- class camelot.view.forms.WidgetOnlyForm(field)[source]¶
Renders a single widget without its label, typically a one2many widget
- camelot.view.forms.structure_to_form(structure)[source]¶
Convert a python data structure to a form, using the following rules :
- if structure is an instance of Form, return structure
- if structure is a list, create a Form from this list
This function is mainly used in the Admin class to construct forms out of the form_display attribute