The parent recipe to this one (Data-aware Controls with Validators, demonstrated in a dialog) shows general, simple means for making controls data-aware. However, in that recipe only the most entirely straightforward controls, textboxes and checkboxes, were considered. This one shows how to provide data-aware extensions of drop-down lists using the same machinery.

What Objects are Involved

The factory called DerivedDBControl can be used to create data-aware controls that "need to know more" about what they are to do than do textboxes.

For example, the line of code that appears first below indicates how to create a data-aware version of the wxComboBox object that provides a drop-down list of three country names.

Process Overview

Typically a reference to such an object would be placed in the 'control' member of a dictionary entry describing a single GUI database field. Notice the reference to CountryComboBox in the customerFieldsInfo, which is used in the parent recipe to this one.


'Canada' does not appear as the default in the combo box built with this machinery.

Code Sample

   1 from wxPython.wx import *
   3 CountryComboxBox = DerivedDBControl(wxComboBox, kwargs={'value': 'Canada', 'choices': ['Canada', 'Mexico', 'U.S.',]})
   5 customerFieldsInfo.rawInfo = {
   6     'IDENTIFIER': {'DisplayName': 'Identifier', 'NoDisplay': True, 'readOnly': True},
   7     'CUST_NO': {'DisplayName': 'Customer Number'}, # 'readOnly': True, },
   8     'COMPANY': {'DisplayName': 'Company'},
   9     'ADDRESS': {'DisplayName': 'Address'},
  10     'CITY': {'DisplayName': 'City'},
  11     'PROV': {'DisplayName': 'Province/State'},
  12     'POSTAL': {'DisplayName': 'Postal Code', 'validator':  PostalCode},
  13     'PHONE1': {'DisplayName': 'Telephone 1'},
  14     'PHONE2': {'DisplayName': 'Telephone 2'},
  15     'FAX': {'DisplayName': 'Fax'},
  16     'CONTACT': {'DisplayName': 'Contact'},
  17     'DISCOUNT': {'DisplayName': 'Discount', 'validator':  AllDigits},
  18     'TERMS': {'DisplayName': 'Terms'},
  19     'FST_NO': {'DisplayName': 'FST Number'},
  20     'PST_NO': {'DisplayName': 'PST Number'},
  21     'PST_EXEMPT': {'DisplayName': 'PST Exempt',},
  22     'COUNTRY': {'DisplayName': 'Country', 'control': CountryComboxBox},
  23     }


I welcome comment. Bill Bell

Data-aware Controls with Validators, Note 1 (last edited 2009-07-13 20:13:05 by host86-139-227-72)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.