Bug(?) in SetBackgroundColour

Hi,

I have a problem changing the background colour of different widgets (see
example) under Linux. I've tested the example on windows and on linux (with
different WindowManagers) with the following results.

Should I write a bug-report?

My System:
Windows XP SP 2
S.u.S.E Linux 9.2
wxPython 2.6.0.0

The Example App:

···

================

import wx

class _MainFrame(wx.Frame):

    def __init__(self, parent, ID, title):

  wx.Frame.__init__(self, parent, ID, title,

        wx.DefaultPosition, wx.Size(800, 600))

  # Panel

  #

  # Windows: Ok

  # Gnome: Ok

  # KDE: Fails

  # fvwm2: Ok

  # TWM: Ok

  # WindowMaker: Ok

  self.Panel = wx.Panel(self)

  self.Panel.SetBackgroundColour(wx.RED)

  self.TopSizer = wx.BoxSizer(wx.VERTICAL)

  # StaticText

  #

  # Windows: Ok

  # Gnome: Fails

  # KDE: Fails

  # fvwm2: Ok

  # TWM: Ok

  # WindowMaker: Ok

  self.Text = wx.StaticText(self.Panel, -1, "Hello World")

  self.Text.SetBackgroundColour(wx.GREEN)

  self.TopSizer.Add(self.Text, 0, wx.EXPAND | wx.ALL, 5)

  # Button

  #

  # Windows: Ok

  # Gnome: Fails

  # KDE: Fails

  # fvwm2: Ok

  # TWM: Ok

  # WindowMaker: Ok

  self.Button = wx.Button(self.Panel, -1, "Hello World")

  self.Button.SetBackgroundColour(wx.GREEN)

  self.TopSizer.Add(self.Button, 0, wx.EXPAND | wx.ALL, 5)

  # TextCtrl

  #

  # Windows: Ok

  # Gnome: Shows a green frame around the widget

  # KDE: Fails

  # fvwm2: Ok

  # TWM: Ok

  # WindowMaker: Ok

  self.TextCtrl = wx.TextCtrl(self.Panel, -1)

  self.TextCtrl.SetBackgroundColour(wx.GREEN)

  self.TopSizer.Add(self.TextCtrl, 0, wx.EXPAND | wx.ALL, 5)

  # Listbox

  #

  # Windows: Ok

  # Gnome: Fails

  # KDE: Fails

  # fvwm2: Fails

  # TWM: Fails

  # WindowMaker: Fails

  Choices = ["one", "two", "three", "Four"]

  self.ListBox = wx.ListBox(self.Panel, -1, choices=Choices)

  self.ListBox.SetBackgroundColour(wx.GREEN)

  self.TopSizer.Add(self.ListBox, 0, wx.EXPAND | wx.ALL, 5)

  # ComboBox

  #

  # Windows: Ok

  # Gnome: Shows a green frame around the widget. The box has a green

  # BGColour

  # KDE: Fails

  # fvwm2: Ok

  # TWM: Ok

  # WindowMaker: Ok

  self.ComboBox = wx.ComboBox(self.Panel, -1, choices=Choices)

  self.ComboBox.SetBackgroundColour(wx.GREEN)

  self.TopSizer.Add(self.ComboBox, 0, wx.EXPAND | wx.ALL, 5)

  self.Panel.SetSizer(self.TopSizer)

class _MyApp(wx.App):

    def OnInit(self):

  frame = _MainFrame(None, -1, "Test App")

  frame.Show(True)

  self.SetTopWindow(frame)

  return True

if __name__ == '__main__':

  app = _MyApp(0)

  app.MainLoop()

Hi Guido,

Try calling self.Panel.SetThemeEnabled(False) before calling SetBackgroundColour and see if it makes a difference.

In some cases, though, this is simply an issue with how the native controls work. SetBackgroundColour doesn't work, or sometimes does unexpected things, depending on the native control it is being called on. There's really not much we can do about that because it is "by design" at the native toolkit level. ;-/

Thanks,

Kevin

···

On Nov 2, 2005, at 6:13 AM, Guido Roth wrote:

Hi,

I have a problem changing the background colour of different widgets (see
example) under Linux. I've tested the example on windows and on linux (with
different WindowManagers) with the following results.

Should I write a bug-report?

My System:
Windows XP SP 2
S.u.S.E Linux 9.2
wxPython 2.6.0.0

The Example App:

import wx

class _MainFrame(wx.Frame):

    def __init__(self, parent, ID, title):

    wx.Frame.__init__(self, parent, ID, title,

              wx.DefaultPosition, wx.Size(800, 600))

    # Panel

    #

    # Windows: Ok

    # Gnome: Ok

    # KDE: Fails

    # fvwm2: Ok

    # TWM: Ok

    # WindowMaker: Ok

    self.Panel = wx.Panel(self)

    self.Panel.SetBackgroundColour(wx.RED)

    self.TopSizer = wx.BoxSizer(wx.VERTICAL)

    # StaticText

    #

    # Windows: Ok

    # Gnome: Fails

    # KDE: Fails

    # fvwm2: Ok

    # TWM: Ok

    # WindowMaker: Ok

    self.Text = wx.StaticText(self.Panel, -1, "Hello World")

    self.Text.SetBackgroundColour(wx.GREEN)

    self.TopSizer.Add(self.Text, 0, wx.EXPAND | wx.ALL, 5)

    # Button

    #

    # Windows: Ok

    # Gnome: Fails

    # KDE: Fails

    # fvwm2: Ok

    # TWM: Ok

    # WindowMaker: Ok

    self.Button = wx.Button(self.Panel, -1, "Hello World")

    self.Button.SetBackgroundColour(wx.GREEN)

    self.TopSizer.Add(self.Button, 0, wx.EXPAND | wx.ALL, 5)

    # TextCtrl

    #

    # Windows: Ok

    # Gnome: Shows a green frame around the widget

    # KDE: Fails

    # fvwm2: Ok

    # TWM: Ok

    # WindowMaker: Ok

    self.TextCtrl = wx.TextCtrl(self.Panel, -1)

    self.TextCtrl.SetBackgroundColour(wx.GREEN)

    self.TopSizer.Add(self.TextCtrl, 0, wx.EXPAND | wx.ALL, 5)

    # Listbox

    #

    # Windows: Ok

    # Gnome: Fails

    # KDE: Fails

    # fvwm2: Fails

    # TWM: Fails

    # WindowMaker: Fails

    Choices = ["one", "two", "three", "Four"]

    self.ListBox = wx.ListBox(self.Panel, -1, choices=Choices)

    self.ListBox.SetBackgroundColour(wx.GREEN)

    self.TopSizer.Add(self.ListBox, 0, wx.EXPAND | wx.ALL, 5)

    # ComboBox

    #

    # Windows: Ok

    # Gnome: Shows a green frame around the widget. The box has a green

    # BGColour

    # KDE: Fails

    # fvwm2: Ok

    # TWM: Ok

    # WindowMaker: Ok

    self.ComboBox = wx.ComboBox(self.Panel, -1, choices=Choices)

    self.ComboBox.SetBackgroundColour(wx.GREEN)

    self.TopSizer.Add(self.ComboBox, 0, wx.EXPAND | wx.ALL, 5)

    self.Panel.SetSizer(self.TopSizer)

class _MyApp(wx.App):

    def OnInit(self):

    frame = _MainFrame(None, -1, "Test App")

    frame.Show(True)

    self.SetTopWindow(frame)

    return True

if __name__ == '__main__':

    app = _MyApp(0)

    app.MainLoop()

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

Try calling self.Panel.SetThemeEnabled(False)

Tried this. Doesn't help.

There's really not much we can do about that because it is "by
design" at the native toolkit level. ;-/

I think I will have to live with it then... :-}

Thanx for your help.

Guido