Delegates — Camelot documentation

### Navigation

- index
- modules |
- next |
- previous |
- Camelot documentation »
- Camelot Documentation contents »
- Camelot Documentation »

# Delegates

Release: | trunk
Date: | November 03, 2011

Delegates are a cornerstone of the Qt model/delegate/view framework. A delegate is used to display and edit data from a model.

In the Camelot framework, every field of an Entity has an associated delegate that specifies how the field will be displayed and edited. When a new form or table is constructed, the delegates of all fields on the form or table will construct editors for their fields and fill them with data from the model. When the data has been edited in the form, the delegates will take care of updating the model with the new data.

All Camelot delegates are subclasses of `QAbstractItemDelegate`.

The PyQT website provides detailed information the differenct classes involved in the model/delegate/view framework.

## Specifying delegates

The use of a specific delegate can be forced by using the `delegate` field attribute. Suppose `rating` is a field of type `integer`, then it can be forced to be visualized as stars:

    from camelot.view.controls import delegates

    class Movie(Entity):
      title = Field(Unicode(50))
      rating = Field(Integer)

      class Admin(EntityAdmin):
        list_display = ['title', 'rating']
        field_attributes = {'rating':{'delegate':delegates.StarDelegate}}

The above code will result in:

If no delegate field attribute is given, a default one will be taken depending on the sqlalchemy field type.

All available delegates can be found in `camelot.view.controls.delegates`

## Available delegates

Camelot includes a number of Qt delegates, most of them are used as default delegates for the various sqlalchemy and camelot field types.

Some delegates take specific arguments into account for their construction. All `field_attributes` specified for a certain field will be propagated towards the constructor of the delegate. Some of them will be used by the delegate itself, others will be used by the editor, created by the delegate.

### BoolDelegate

Custom delegate for boolean values

By default, creates a BoolEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - minimum
> - maximum
> - nullable
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### ChartDelegate

Custom delegate for Matplotlib charts

### CodeDelegate

Field attributes supported by the delegate :

> - parts
> - separator

By default, creates a CodeEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - parts
> - editable
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### ColorDelegate

By default, creates a ColorEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - editable
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### ColoredFloatDelegate

Custom delegate for float values.

> The class attribute icons is used to customize the icons displayed.

Field attributes supported by the delegate :

> - minimum
> - maximum
> - precision
> - reverse
> - neutral
> - unicode_format

By default, creates a ColoredFloatEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - precision
> - reverse
> - neutral
> - option
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip
> - prefix
> - suffix
> - minimum
> - maximum
> - single_step

### ComboBoxDelegate

By default, creates a ChoicesEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - nullable
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - choices

### CurrencyDelegate

Custom delegate for currency values

### DateDelegate

Custom delegate for date values

Field attributes supported by the delegate :

By default, creates a DateEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - editable
> - nullable
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### DateTimeDelegate

Field attributes supported by the delegate :

> - editable

By default, creates a DateTimeEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - editable
> - nullable
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### EnumerationDelegate

Contrary to the comboboxdelegate, the enumeration delegate does not support dynamic
  choices

Field attributes supported by the delegate :

> - choices
> - editable

By default, creates a ChoicesEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - nullable
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - choices

### FileDelegate

Delegate for camelot.types.file fields. Expects values of type camelot.core.files.storage.StoredFile.

By default, creates a FileEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - storage
> - field_name
> - remove_original

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip
> - remove_original

### FloatDelegate

Custom delegate for float values

Field attributes supported by the delegate :

> - minimum
> - maximum
> - unicode_format

By default, creates a FloatEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - minimum
> - maximum
> - calculator
> - decimal
> - option
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip
> - prefix
> - suffix
> - precision
> - single_step

### ImageDelegate

### IntegerDelegate

Custom delegate for integer values

Field attributes supported by the delegate :

> - minimum
> - maximum
> - unicode_format

By default, creates a IntegerEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - minimum
> - maximum
> - calculator
> - option
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip
> - prefix
> - suffix
> - nullable
> - single_step

### IntervalsDelegate

Custom delegate for visualizing camelot.container.IntervalsContainer
  data:

### LabelDelegate

Delegate to display an attribute as a label

By default, creates a LabelEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - text
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### LanguageDelegate

### LocalFileDelegate

Delegate for displaying a path on the local file system. This path can
  either point to a file or a directory

Field attributes supported by the delegate :

By default, creates a LocalFileEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - field_name
> - directory
> - save_as
> - file_filter

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### Many2OneDelegate

Custom delegate for many 2 one relations

> Once an item has been selected, it is represented by its unicode representation in the editor or the table. So the related classes need an implementation of their __unicode__ method.

Field attributes supported by the delegate :

> - admin
> - embedded
> - editable

By default, creates a Many2OneEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - admin
> - editable
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### ManyToManyDelegate

### ManyToOneChoicesDelegate

Display a ManyToOne field as a ComboBox, filling the list of choices with

  the objects of the target class.

  The items in the ComboBox are the unicode representation of the related objects. So these classes need an implementation of their __unicode__ method to show up in a human readable way in the ComboBox.

### MonthsDelegate

MonthsDelegate

> custom delegate for showing and editing months and years

Field attributes supported by the delegate :

> - forever

By default, creates a MonthsEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - editable
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### NoteDelegate

By default, creates a NoteEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### One2ManyDelegate

Custom delegate for many 2 one relations

Field attributes supported by the delegate :

### PlainTextDelegate

Custom delegate for simple string values

Field attributes supported by the delegate :

> - length
> - editable
> - translate_content

By default, creates a TextLineEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - length
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### RichTextDelegate

Custom delegate for rich text (HTML) string values

Field attributes supported by the delegate :

> - editable

By default, creates a RichTextEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color

### SmileyDelegate

Delegate for Smiley’s

Field attributes supported by the delegate :

> - editable
> - icons

By default, creates a SmileyEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - editable
> - icons
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### StarDelegate

Delegate for integer values from (1 to 5)(Rating Delegate)

Field attributes supported by the delegate :

> - editable
> - maximum

By default, creates a StarEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - maximum
> - editable
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### TextBoolDelegate

### TextEditDelegate

Custom delegate for simple string values

Field attributes supported by the delegate :

By default, creates a TextEditEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - length
> - editable
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### TimeDelegate

Field attributes supported by the delegate :

> - editable

By default, creates a TimeEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - editable
> - field_name
> - format

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### VirtualAddressDelegate

Field attributes supported by the delegate :

> - editable
> - address_type

By default, creates a VirtualAddressEditor as its editor.

Field Attributes | Editor
editable=False tooltip=’tooltip’ |
editable=True |
editable=True tooltip=’tooltip’ |
editable=False |
editable=False background_color=ColorScheme.green |
editable=True background_color=ColorScheme.green |

Static attributes supported by this editor :

> - editable
> - address_type
> - address_validator
> - field_name

Dynamic field attributes supported by the editor :

> - editable
> - background_color
> - tooltip

### Navigation

- index
- modules |
- next |
- previous |
- Camelot documentation »
- Camelot Documentation contents »
- Camelot Documentation »

Comments
blog comments powered by Disqus