Introduction

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 the CalendarCtrl control, which lacks the abiltity to support wxPython's usual validation 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 CalendarCtrl object that is able to accept and store Null date values to a database.

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 Calendar object in the workorderFieldsInfo, which is used in the parent recipe to this one. Notice also that validator is set to None for fields that use this control.

Concerns

The derived control supports persistence only to databases that accept ISO-format dates, eg, MySQL.

Code Sample

   1 from wxPython.wx import *
   2 from wx . calendar import  *
   3     
   4 Calendar = DerivedDBControl ( CalendarCtrlForDB, kwargs = { 'style': CAL_SUNDAY_FIRST | CAL_SEQUENTIAL_MONTH_SELECTION | CAL_SHOW_SURROUNDING_WEEKS } )
   5 OrderTypeComboxBox = DerivedDBControl ( wxComboBox, kwargs = { 'value': '', 'choices': [ 'L', 'M', ], } ) 
   6 workorderFieldsInfo . rawInfo = {
   7     'IDENTIFIER' : { 'DisplayName': 'Identifier', 'NoDisplay': True, 'readOnly': True, },
   8     'ORD_DATE' : { 'DisplayName' : 'Order Date', 'control': Calendar, 'validator' : None, },
   9     'CUST_NO' : { 'DisplayName' : 'Customer Number', 'readOnly': True, },
  10     'INV_AMT' : { 'DisplayName' : 'Invoice Amount', },
  11     'WO_NO' : { 'DisplayName' : 'WO Number', },
  12     'INV_NO' : { 'DisplayName' : 'Invoice Number', },
  13     'PO_NO' : { 'DisplayName' : 'PO Number', },
  14     'PAID_DATE' : { 'DisplayName' : 'Paid Date', 'control': Calendar, 'validator' : None, },
  15     'PAID_FLAG' : { 'DisplayName' : 'Paid Flag', },
  16     'ORD_TYPE' : { 'DisplayName' : 'Units', 'control': OrderTypeComboxBox, },
  17     'UTILITY' : { 'DisplayName' : 'Utility', },
  18     }

Comments

I welcome comment. Bill Bell

Data-aware Controls with Validators, Note 2 (last edited 2008-03-11 10:50:38 by localhost)

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