def display(self, record, field): super(Char, self).display(record, field) if record and self.autocomplete: … elif self.autocomplete: … # Set size if self.autocomplete: … else: … if record: … else: … if not field: value = '' else: value = field.get_client(record) if not self.autocomplete: self.entry.set_text(value) else: …
Set differents states of the widget
def display(self, record, field): if not field: self._readonly_set(self.attrs.get('readonly', True)) self.invisible_set(self.attrs.get('invisible', False)) return self._readonly_set(self.attrs.get('readonly', field.get_state_attrs(record).get('readonly', False))) if self.attrs.get('readonly', field.get_state_attrs(record).get('readonly', False)): self.color_set('readonly') elif not field.get_state_attrs(record).get('valid', True): self.color_set('invalid') elif field.get_state_attrs(record).get('required', False): self.color_set('required') else: self.color_set('normal') self.invisible_set(self.attrs.get('invisible', field.get_state_attrs(record).get('invisible', False)))
In the GTk widget:
def set_value(self, record, field): entry = self.entry.get_child() if self.autocomplete else self.entry value = entry.get_text() or self._default_value return field.set_client(record, value)
In the field:
def set_client(self, record, value, force_change=False): previous_value = self.get(record) self.set(record, value) if previous_value != self.get(record): record.modified_fields.setdefault(self.name) record.signal('record-modified') self.sig_changed(record) record.validate(softvalidation=True) record.signal('record-changed') elif force_change: self.sig_changed(record) record.validate(softvalidation=True) record.signal('record-changed')
Add your field in gui/window/view_form/model/field.py
self.set(record, filename) return self.get(record) + +class DictField(CharField): + + _default = {} + + TYPES = { 'char': CharField, 'sha': CharField, @@ -941,4 +947,5 @@ 'time': TimeField, 'one2one': O2OField, 'binary': BinaryField, + 'dict': DictField, }
Add your widget in gui/window/view_form/view/form_gtk/parser.py
@@ -547,6 +548,7 @@ from progressbar import ProgressBar from one2one import One2One from richtextbox import RichTextBox +from dictionary import DictWidget WIDGETS_TYPE = { @@ -576,4 +578,5 @@ 'progressbar': (ProgressBar, 1, False, False), 'one2one': (One2One, 1, False, False), 'richtext': (RichTextBox, 1, True, True), + 'dict': (DictWidget, 1, False, False), }
The number is useless. The first boolean represent the yexpand property. The second boolean represent the yfill property.
In gui/window/view_form/view/list_gtk/parser.py you can add a class to represent in the list view your widget.
class Geometry(Char): def __init__(self, field_name, model_name, treeview, attrs=None): super(Geometry, self).__init__(field_name, model_name, treeview, attrs=attrs) def get_textual_value(self, record): val = record[self.field_name].get_client(record) return val.wkt if val else ''
get_textual_value will return the value that must be displayed in the cell. value_from_text will set the value in the record from the text of the cell.
You can also define your own CellRenderer, they are examples in common/.
Table of Contents | t |
---|---|
Exposé | ESC |
Full screen slides | e |
Presenter View | p |
Source Files | s |
Slide Numbers | n |
Toggle screen blanking | b |
Show/hide slide context | c |
Notes | 2 |
Help | h |