Gnumed.wxpython.gmEditArea.cGenericEditAreaMixin

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

# Class cGenericEditAreaMixin

source code

    object --+
             |
            cGenericEditAreaMixin

Known Subclasses:
  - gmContactWidgets.cCommChannelEditAreaPnl
  - , gmKeywordExpansionWidgets.cTextExpansionEditAreaPnl
  - , gmOrganizationWidgets.cOrgUnitEAPnl
  - , gmOrganizationWidgets.cOrganizationEAPnl
  - , gmI18nWidgets.cDatabaseTranslationEAPnl
  - , gmAddressWidgets.cAddressEAPnl
  - , gmAddressWidgets.cProvinceEAPnl

    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.status_message = _('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.status_message = _('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
            #----------------------------------------------------------------

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

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

Properties
| data
| mode
| status_message
Inherited from `object`: `__class__`

Method Details

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

### 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().

### 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

Property Details

### data Get Method: _get_data(self) Set Method: _set_data(self, data=None)

### mode Get Method: _get_mode(self) Set Method: _set_mode(self, mode=None)

### status_message Get Method: unreachable(x) Set Method: show_msg(self, msg)