Package Gnumed :: Package wxpython :: Module gmEditArea :: Class cGenericEditAreaMixin |
[frames] | no frames]

# Class cGenericEditAreaMixin

source code

    object --+
             |
            cGenericEditAreaMixin

    Mixin for edit area panels providing generic functionality.

            **************** start of template ****************

    #====================================================================
    # Class definition:

    from Gnumed.wxGladeWidgets import wxgXxxEAPnl

    class cXxxEAPnl(wxgXxxEAPnl.wxgXxxEAPnl, gmEditArea.cGenericEditAreaMixin):

            def __init__(self, *args, **kwargs):

                    try:
                            data = kwargs['xxx']
                            del kwargs['xxx']
                    except KeyError:
                            data = None

                    wxgXxxEAPnl.wxgXxxEAPnl.__init__(self, *args, **kwargs)
                    gmEditArea.cGenericEditAreaMixin.__init__(self)

                    # Code using this mixin should set mode and data
                    # after instantiating the class:
                    self.mode = 'new'
                    self.data = data
                    if data is not None:
                            self.mode = 'edit'

                    #self.__init_ui()

            #----------------------------------------------------------------
    #       def __init_ui(self):
    #               # adjust phrasewheels etc

            #----------------------------------------------------------------
            # generic Edit Area mixin API
            #----------------------------------------------------------------
            def _valid_for_save(self):

                    # its best to validate bottom -> top such that the
                    # cursor ends up in the topmost failing field

                    # remove when implemented:
                    return False

                    validity = True

                    if self._TCTRL_xxx.GetValue().strip() == u'':
                            validity = False
                            self.display_tctrl_as_valid(tctrl = self._TCTRL_xxx, valid = False)
                            self.StatusText = _('No entry in field xxx.')
                            self._TCTRL_xxx.SetFocus()
                    else:
                            self.display_tctrl_as_valid(tctrl = self._TCTRL_xxx, valid = True)

                    if self._PRW_xxx.GetData() is None:
                            validity = False
                            self._PRW_xxx.display_as_valid(False)
                            self.StatusText = _('No entry in field xxx.')
                            self._PRW_xxx.SetFocus()
                    else:
                            self._PRW_xxx.display_as_valid(True)

                    return validity

            #----------------------------------------------------------------
            def _save_as_new(self):

                    # remove when implemented:
                    return False

                    # save the data as a new instance
                    data = gmXXXX.create_xxxx()

                    data[''] = self._
                    data[''] = self._

                    data.save()

                    # must be done very late or else the property access
                    # will refresh the display such that later field
                    # access will return empty values
                    self.data = data
                    return False
                    return True

            #----------------------------------------------------------------
            def _save_as_update(self):

                    # remove when implemented:
                    return False

                    # update self.data and save the changes
                    self.data[''] = self._TCTRL_xxx.GetValue().strip()
                    self.data[''] = self._PRW_xxx.GetData()
                    self.data[''] = self._CHBOX_xxx.GetValue()
                    self.data.save()
                    return True

            #----------------------------------------------------------------
            def _refresh_as_new(self):
                    pass

            #----------------------------------------------------------------
            def _refresh_as_new_from_existing(self):
                    self._refresh_as_new()

            #----------------------------------------------------------------
            def _refresh_from_existing(self):
                    pass

            #----------------------------------------------------------------
            def set_fields(self, fields):
                    # <fields> must be a dict compatible with the
                    # structure of the business object this edit
                    # area is for,
                    # thusly, the edit area knows how to set its
                    # controls from it,
                    # <fields> doesn't have to contain all keys, rather:
                    # - missing ones are skipped
                    # - unknown ones are ignored
                    # each key must hold a dict with at least a key 'value'
                    # and _can_ contain another key 'data',
                    # 'value' and 'data' must be compatible with the
                    # control they go into,
                    # controls which don't require 'data' (say, RadioButton)
                    # will ignore an existing 'data' key
                    pass

            #----------------------------------------------------------------

            **************** end of template ****************

Instance Methods
__init__(self) x.__init__(...) initializes x; see help(type(x)) for signature | source code
save(self) Invoked from the generic edit area dialog. | source code
refresh(self) Invoked from the generic edit area dialog. | source code
display_tctrl_as_valid(self, tctrl=None, valid=None) | source code
display_ctrl_as_valid(self, ctrl=None, valid=None) | source code
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Class Variables
| mode = `property(_get_mode, _set_mode)`
| data = `property(_get_data, _set_data)`
| StatusText = `property(lambda x: x, _set_status_text)`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self) (Constructor) | source code
x.__init__(...) initializes x; see help(type(x)) for signature Overrides: object.__init__ (inherited documentation)

### save(self) | source code
    Invoked from the generic edit area dialog.

    Invokes
            _valid_for_save,
            _save_as_new,
            _save_as_update
    on the implementing edit area as needed.

    _save_as_* must set self.__data and return True/False

### refresh(self) | source code
    Invoked from the generic edit area dialog.

    Invokes
            _refresh_as_new()
            _refresh_from_existing()
            _refresh_as_new_from_existing()
    on the implementing edit area as needed.

    Then calls _valid_for_save().