DatePickerCtrl and SetBackgroundColour

I am simply trying to set the background colour on the DatePickerCtrl
to show validation errors. All other input methods on my Frame accept
the SetBackgroundColour method but the date control is not. The method
is available via dir() but I can't figure out what I am doing wrong.
Is there something I am missing?

Thanks,

Abe

A.M. wrote:

I am simply trying to set the background colour on the DatePickerCtrl
to show validation errors. All other input methods on my Frame accept
the SetBackgroundColour method but the date control is not. The method
is available via dir() but I can't figure out what I am doing wrong.
Is there something I am missing?

Which platform and version?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Sorry I didn't include this before but version 2.6.3.3 and running on
Windows XP.

···

On 9/14/06, Robin Dunn <robin@alldunn.com> wrote:

A.M. wrote:
> I am simply trying to set the background colour on the DatePickerCtrl
> to show validation errors. All other input methods on my Frame accept
> the SetBackgroundColour method but the date control is not. The method
> is available via dir() but I can't figure out what I am doing wrong.
> Is there something I am missing?

Which platform and version?

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

A.M. wrote:

···

On 9/14/06, Robin Dunn <robin@alldunn.com> wrote:

A.M. wrote:
> I am simply trying to set the background colour on the DatePickerCtrl
> to show validation errors. All other input methods on my Frame accept
> the SetBackgroundColour method but the date control is not. The method
> is available via dir() but I can't figure out what I am doing wrong.
> Is there something I am missing?

Which platform and version?

Sorry I didn't include this before but version 2.6.3.3 and running on
Windows XP.

On Windows the date picker is a native control, and for SetBackgroundColour a message will be sent to its window handle like for any other widget. So apparently the native control is ignoring the message for some reason.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I want to explain further that I am more interested in setting the
background color of the control (looks like a combo box) that displays
the date string. Not the calendar control itself that's presented when
you click the dropdown arrow. Maybe that is more doable?

···

On 9/15/06, Robin Dunn <robin@alldunn.com> wrote:

A.M. wrote:
> On 9/14/06, Robin Dunn <robin@alldunn.com> wrote:
>> A.M. wrote:
>> > I am simply trying to set the background colour on the DatePickerCtrl
>> > to show validation errors. All other input methods on my Frame accept
>> > the SetBackgroundColour method but the date control is not. The method
>> > is available via dir() but I can't figure out what I am doing wrong.
>> > Is there something I am missing?
>>
>> Which platform and version?
>
> Sorry I didn't include this before but version 2.6.3.3 and running on
> Windows XP.

On Windows the date picker is a native control, and for
SetBackgroundColour a message will be sent to its window handle like for
any other widget. So apparently the native control is ignoring the
message for some reason.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

A.M. wrote:

I want to explain further that I am more interested in setting the
background color of the control (looks like a combo box) that displays
the date string. Not the calendar control itself that's presented when
you click the dropdown arrow. Maybe that is more doable?

I understood you the first time. I looked into it a little further and I had it a little backwards. The reason it is not displaying the bg color appears to be that the control is not asking for the background to draw itself with in the standard way. It looks like it may be drawing it's own background in the erase background event instead. So you can work around it by handling wx.EVT_ERASE_BACKGROUND yourself.

class DatePickerCtrl(wx.DatePickerCtrl):
     def __init__(self, *args, **kw):
         wx.DatePickerCtrl.__init__(self, *args, **kw)
         self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

     def OnEraseBackground(self, evt):
         dc = evt.GetDC()
         dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
         dc.Clear()

BTW, the other platforms will likely have troubles setting the bg colour for this control too since they are implemented as a composite control and I don't think it is forwarding the Set*groundColour calls to the components... I'll add that to my todo list.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

1 Like

It's 2.8 and this still hasn't been fixed. Is there any chance that
this can be fixed at all soon?

Christoper L. Spencer
CTO ROXX, LLC
4515 Leslie Ave.
Cincinnati, OH
45242
TEL: 513-545-7057
EMAIL: chris@roxx.biz

···

On Fri, 15 Sep 2006 19:53:53 -0700, Robin Dunn <robin@alldunn.com> wrote:

A.M. wrote:

I want to explain further that I am more interested in setting the
background color of the control (looks like a combo box) that displays
the date string. Not the calendar control itself that's presented when
you click the dropdown arrow. Maybe that is more doable?

I understood you the first time. I looked into it a little further and
I had it a little backwards. The reason it is not displaying the bg
color appears to be that the control is not asking for the background to
draw itself with in the standard way. It looks like it may be drawing
it's own background in the erase background event instead. So you can
work around it by handling wx.EVT_ERASE_BACKGROUND yourself.

class DatePickerCtrl(wx.DatePickerCtrl):
    def __init__(self, *args, **kw):
        wx.DatePickerCtrl.__init__(self, *args, **kw)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

    def OnEraseBackground(self, evt):
        dc = evt.GetDC()
        dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
        dc.Clear()

BTW, the other platforms will likely have troubles setting the bg colour
for this control too since they are implemented as a composite control
and I don't think it is forwarding the Set*groundColour calls to the
components... I'll add that to my todo list.

1 Like

Something new about this, fix or patch? I am triying the solution but bg color dont change. On Windows 10 x64 bits WxPython x32 (virtual enviroment) v4.2.1a1.

Looks like the issue in wxWidgets is still open: https://github.com/wxWidgets/wxWidgets/issues/3575