A control to facilitate capturing a date.

It combines a text control having user-definable input and display format, and a popup calendar that can be used as a date picker.

What Objects are Involved

The primary control is a wx.combo.ComboCtrl.

The underlying text control has bindings for EVT_SET_FOCUS and EVT_CHAR, which handle formatting and entering of dates.

It uses a customised popup, which invokes a wx.Dialog, which contains a wx.calendar.Calendar, together with Ok and Cancel buttons.

Process Overview

Add DateCtrl to your Panel in the normal way.

Parameters -

[1] strftime format - a format string containing directives governing how the date is to be formatted.

There are many directives - refer to the python manual for details.

Here are some common directives -

Here are some typical formats, used to display 31st December 2010 -

For input purposes, DateCtrl parses the format string, so that the user enters the date using only the numeric keypad. Delimiters and other literals are displayed, but automatically skipped over while entering.

Special Concerns

1. The calendar popup is displayed using CentreOnScreen(). Some may prefer to anchor it to the underlying text control, but this has not been implemented.

2. 'input_format' is invoked when the control gains focus. When the control loses focus, the date is re-displayed using 'display_format'. This is an effective way of allowing the user to confirm that the result matches his intentions. However, from a user-interface POV, it can be unsettling that it changes back to 'input_format' when it gains focus again. Feel free to add comments below to see if we can reach consensus on how this should be handled.

3. In order to evaluate the date entered, it is necessary to call the method convert_to_wx_date(). Strategies as to *when* this should be called may differ. In the attached program, it is called when the control after the date control gets focus.

4. There are a couple of minor issues regarding the appearance of the dropdown button. I spent some time investigating this but ended up making matters worse, so I left it.

Here is a link to a post from Robin discussing the underlying cause -

If anyone feels like following it up, patches will be very welcome.

Code Sample

Code is attached -

Revised version uploaded - added tooltip to dropdown button

Revised version uploaded - various bug fixes

Revised version uploaded - fixed bug in input format


Comments welcome. Frank Millman

DateEditorAndPicker (last edited 2010-11-07 09:15:39 by 41-132-50-75)

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