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.

render_tab(index)[source]

Render the tab at index

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. The base form uses the QFormLayout to render a form:

class Admin(EntityAdmin):
  form_display = Form(['title', 'short_description', 'director', 'release_date'])

..image:: /_static/form/form.png

get_fields()[source]
Returns:the fields, visible in this form
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(*args, **kwargs)[source]
Parameters:
  • widgets – a camelot.view.controls.formview.FormEditors object that is able to create the widgets for this form
  • parent – the QtGui.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 QWidget into which the form is rendered

render_ooxml(obj, delegates)[source]

Generator for lines of text in Office Open XML representing this form, using tables :param obj: the object or entity that will be rendered :param delegates: a dictionary mapping field names to their delegate

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']])
../../_images/grid_form.png
append_column(column)[source]
Parameters:column – the list of fields that should come in the additional column

use this method to modify inherited grid forms

append_row(row)[source]
Parameters:row – the list of fields that should come in the additional row

use this method to modify inherited grid forms

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'])
../../_images/group_box_form.png
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']])
../../_images/hbox_form.png
class camelot.view.forms.Label(label, alignment='left', style=None)[source]

Render a label with a QLabel

render_ooxml()[source]

Generator for label text in Office Open XML representing this form

class camelot.view.forms.TabForm(tabs, position='North')[source]

Render forms within a QTabWidget:

from = TabForm([('First tab', ['title', 'short_description']),
                ('Second tab', ['director', 'release_date'])])
../../_images/tab_form.png
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.
add_tab_at_index(tab_label, tab_form, index)[source]

Add a tab to the form at the specified index

Parameters:
  • tab_label – the name to the tab
  • tab_form – the form to display in the tab or a list of field names.
  • index – the position of tab in the tabs list.
get_tab(tab_label)[source]

Get the tab form of associated with a tab_label, use this function to modify the underlying tab_form in case of inheritance

:param tab_label : a label of a tab as passed in the construction method :return: the tab_form corresponding to tab_label

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']])
../../_images/vbox_form.png
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

Previous topic

filters

Next topic

main

This Page


Comments
blog comments powered by Disqus