TextCtrl background color problems

Thanks for looking into it Paul, I appreciate it. From your comment it sounds like there was no comment explaining why. A lot of code I read has comments explaining what it is doing and in general you can figure that out from reading the code itself. Often too they do not explain why as is the case here and that is unfortunate because that is usually what one is interested in. I won’t preach much because I am probably as guilty as the next.

Be that as it may, I want my multiline text widget to have a color when it is disabled. I wrote a short diddy (below) that makes it easy for me to allow a checkbox widget to control enabling/disabling widgets. In this diddy I take care of this phenom. I’m not familiar with how to obtain system colors so I guessed at one and got it close for my current system. What is the better way to do this (see code near red highlight)?

class WidgetEnabler(object):

def __init__(self,checkbox,widgets,enable=None):
    """

    checkbox -- wx.CheckBox widget that is used to disable/enable other widgets

    widgets -- list of widgets checkbox controls
    enable -- initial state of checkbox (defaults to not initializing checkbox)"""

    self.checkbox = checkbox

    self.widgets = widgets
   

    if enable is not None:
        checkbox.SetValue(enable)

    # Cause our update method to be called whenever the checkbox state changes

    # so that we can enable/disable the associated widgets.

    checkbox.Bind(wx.EVT_CHECKBOX,self.update)

    # Update (enable/disable) all the widgets based on initial state of checkbox.
    self.update()

def update(self,event=None):

    """Enables/Disables all the widgets associated with a checkbox based
    on the state of the checkbox."""

    # Get state of checkbox       

    enabled = self.checkbox.GetValue()

    # Enable/Disable all the associated widgets.
    for widget in self.widgets:       

        widget.Enable(enabled)

       
        # TextCtrl widgets with TE_MULTILINE style don't change their

        # background color when disabled, therefore we must do it manually.

        try:
            if widget.GetWindowStyle() & wx.TE_MULTILINE:

                if enabled:
                    widget.SetBackgroundColour

(‘WHITE’)
else:

                    # Yuk, is there a better way to do this?

                    # This color happens to be close to the light grey that

                    # is used to make widgets look disabled on my XP system.
                    widget.SetBackgroundColour

((234,230,217))
except AttributeError:

            pass
       

        widget.Refresh()

Thanks!

Dan

···

On 3/9/06, Lanier, Paul Paul.Lanier@analog.com wrote:

I confirm, it happens for style=wx.TE_MULTILINE with no other styles
added in.

Looking at the wxWidgets source it appears to be intentional:

WXHBRUSH wxTextCtrl::MSWControlColor(WXHDC hDC, WXHWND hWnd)

{
if ( !IsEnabled() && !HasFlag(wxTE_MULTILINE) )
return MSWControlColorDisabled(hDC);

return wxTextCtrlBase::MSWControlColor(hDC, hWnd);

}