Background color mismatch

87 views
Skip to first unread message

mkeeter

unread,
May 20, 2013, 5:01:01 PM5/20/13
to wxpytho...@googlegroups.com
I'm having trouble setting the background color of a wx.Frame.  The color
displayed on my screen is not the color that I set using SetBackgroundColour.

A very simple test program is below.  I set the color to be to be #002b36, but it
is displayed as #003945 (calling GetBackgroundColour still returns #002b36).

A screenshot of the miscolored frame is at http://imgur.com/bXfLKcM

I'm running Mac OS X 10.6.8, wxPython 2.9.4.0 osx-cocoa (classic).

Any suggestions?

Thanks,
Matt Keeter

--------------------------------------------------------------------------------

#!/usr/bin/env python
import wx

app = wx.App(False) # Create a new app, don't redirect stdout/stderr to a window.
frame = wx.Frame(None, wx.ID_ANY, "Hello World") # A Frame is a top-level window. 

frame.SetBackgroundColour('#002b36')

frame.Show(True) # Show the frame.
app.MainLoop()

--------------------------------------------------------------------------------

Chris Barker - NOAA Federal

unread,
May 20, 2013, 6:28:17 PM5/20/13
to wxpytho...@googlegroups.com
Frames can be a bit odd by themselves -- you might try putting a Panel
on it and setting the BackgroundColour on the Panel.

-Chris
> --
> You received this message because you are subscribed to the Google Groups
> "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to wxpython-user...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris....@noaa.gov

mkeeter

unread,
May 20, 2013, 8:32:50 PM5/20/13
to wxpytho...@googlegroups.com
Thanks for the advice, but that doesn't seem to be the problem.  In my actual application,
this error is occurring consistently across Frames, Panels, and even the STC Editor.

The slightly larger demo application below (with a Panel added) shows the same issue
It also looks like the problem isn't in the hex string interpretation: replacing it with
wx.Colour(0, 43, 54) has no effect on the incorrect output.

Regards,
Matt

-------------------------------------------------------------------------------- 
#!/usr/bin/env python
import wx

app = wx.App(False)  # Create a new app, don't redirect stdout/stderr to a window.
frame = wx.Frame(None, wx.ID_ANY, "Hello World") # A Frame is a top-level window.

sizer = wx.BoxSizer(wx.VERTICAL)

panel = wx.Panel(frame, wx.ID_ANY, size=(100,100))
sizer.Add(panel, flag=wx.ALL, border=10)
panel.SetBackgroundColour('#002b36')

frame.SetSizerAndFit(sizer)

frame.Show(True)     # Show the frame.
app.MainLoop()
-------------------------------------------------------------------------------- 

Robin Dunn

unread,
May 21, 2013, 12:40:47 AM5/21/13
to wxpytho...@googlegroups.com
mkeeter wrote:
> I'm having trouble setting the background color of a wx.Frame. The color
> displayed on my screen is not the color that I set using
> SetBackgroundColour.
>
> A very simple test program is below. I set the color to be to be
> #002b36, but it
> is displayed as #003945 (calling GetBackgroundColour still returns #002b36).

How are you checking the displayed color value?


>
> A screenshot of the miscolored frame is at http://imgur.com/bXfLKcM
>
> I'm running Mac OS X 10.6.8, wxPython 2.9.4.0 osx-cocoa (classic).
>
> Any suggestions?


What is the bit-depth setting for your display? If it's not 32-bit then
there could be some color interpolation going on to make the requested
color fit in to the available color space. If it is 32-bit then there
could be some other adjustments happening in the display driver or
something due to color calibration settings or similar.


--
Robin Dunn
Software Craftsman
http://wxPython.org

mkeeter

unread,
May 21, 2013, 9:42:37 AM5/21/13
to wxpytho...@googlegroups.com
I'm running in 32-bit mode.
After a bit more digging, I've found this problem showing up twice before:

2011:  https://groups.google.com/forum/#!msg/wxpython-users/MH7dmipGbbQ/QdGtwLwOqZcJ
2008:  http://wxwidgets.10942.n7.nabble.com/wxMac-2-8-8-color-handling-bug-td27720.html

The second thread seems to explain the root cause: wxMac is using the "Generic RGB Profile" color
profile, rather than the display device's current profile (which is "Color LCD" on my machine).  Mapping
between the generic profile and the machine's profile is causing the colors to become wrong.

With this added info, are there any options other than hacking into the wxMac source?

For reference, I'm trying to use the solarized color scheme.  This screenshot shows my app
compared to Vim with correctly displayed colors -- the background color discrepancy makes
a huge difference.


Regards,
Matt

Robin Dunn

unread,
May 21, 2013, 8:21:57 PM5/21/13
to wxpytho...@googlegroups.com
mkeeter wrote:
> I'm running in 32-bit mode.
> After a bit more digging, I've found this problem showing up twice before:
>
> 2011:
> https://groups.google.com/forum/#!msg/wxpython-users/MH7dmipGbbQ/QdGtwLwOqZcJ
> 2008:
> http://wxwidgets.10942.n7.nabble.com/wxMac-2-8-8-color-handling-bug-td27720.html
>
> The second thread seems to explain the root cause: wxMac is using the
> "Generic RGB Profile" color
> profile, rather than the display device's current profile (which is
> "Color LCD" on my machine). Mapping
> between the generic profile and the machine's profile is causing the
> colors to become wrong.
>
> With this added info, are there any options other than hacking into the
> wxMac source?


There still isn't anything in the API for it, so you'll have to hack wx.
Or, even better, you could add a new API, perhaps a new method in wxDC,
to select if the default profile or the device profile should be used
and then submit a patch.
Reply all
Reply to author
Forward
0 new messages