dc/wx.lib.plot BackgroundColour

So, I'm trying to learn about the wx.lib.plot for a simple xy graph
project. I would very much like to use a white foreground color
(axes, ticks, labels, etc.) on a black background. My trouble is
in trying to get the PlotCanvas to display the black background.

I am overriding the _Draw() method of PlotCanvas in an attempt to
get access to the dc that is used. I have really only added 5 lines
to the function. In the attached sample the relevant lines are
73 - 77.

         dc.FloodFill(0, 0, wx.BLACK, wx.FLOOD_SURFACE)
         dc.SetBackground(wx.Brush(wx.BLACK, wx.SOLID))
         print dc.GetBackground().GetColour()
         dc.SetBackgroundMode(wx.SOLID)
         dc.SetTextForeground(wx.WHITE)

All the methods seem to be completing successfully, but in my test
the background continues to be white. I am not very familiar with
DCs thought I have been mining the docs and the wx.lib.plot source
code, but I just can't find the instruction that is making the
background white! Can anyone help illuminate the path?

Thanks,

plotting.py (8.63 KB)

···

--
Colin Barnette
<colin dot barnette at gmail dot com>

Colin Barnette wrote:

So, I'm trying to learn about the wx.lib.plot for a simple xy graph
project. I would very much like to use a white foreground color
(axes, ticks, labels, etc.) on a black background.

It's been a long time since I've poked into wx.lib.plot, but you might try:

# no need for FloodFill, I dont' think it's what you want anyway.

         dc.FloodFill(0, 0, wx.BLACK, wx.FLOOD_SURFACE)

           dc.SetBackground(wx.Brush(wx.BLACK, wx.SOLID))
# insert a dc.Clear() here -- it draws teh background color oever whatever is there:
            dc.clear()

         print dc.GetBackground().GetColour()

# SetBackgroundMode only applies to text you probably want it wx.TRANSPARENT

         dc.SetBackgroundMode(wx.SOLID)
         dc.SetTextForeground(wx.WHITE)

I hope the Clear() does it for you.

If not, then you may need to trace through the code an see where else dc.SetBackground or dc.Clear() are being called.

-Chris

···

--
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.Barker@noaa.gov

Thanks, Chris! It certainly did.

···

On Thu, 10 Sep 2009 16:37:44 -0400, Christopher Barker <Chris.Barker@noaa.gov> wrote:

I hope the Clear() does it for you.

--
Colin Barnette
<colin dot barnette at gmail dot com>

Colin Barnette wrote:

So, I'm trying to learn about the wx.lib.plot for a simple xy graph
project. I would very much like to use a white foreground color
(axes, ticks, labels, etc.) on a black background. My trouble is
in trying to get the PlotCanvas to display the black background.

I am overriding the _Draw() method of PlotCanvas in an attempt to
get access to the dc that is used. I have really only added 5 lines
to the function. In the attached sample the relevant lines are
73 - 77.

         dc.FloodFill(0, 0, wx.BLACK, wx.FLOOD_SURFACE)
         dc.SetBackground(wx.Brush(wx.BLACK, wx.SOLID))
         print dc.GetBackground().GetColour()
         dc.SetBackgroundMode(wx.SOLID)
         dc.SetTextForeground(wx.WHITE)

All the methods seem to be completing successfully, but in my test
the background continues to be white. I am not very familiar with
DCs thought I have been mining the docs and the wx.lib.plot source
code, but I just can't find the instruction that is making the
background white! Can anyone help illuminate the path?

Have you tried just calling the plot's SetBackgroundColour and SetForegroundColour methods? It looks like the default _Draw method is already using those properties appropriately. If it doesn't already work that way then it really should and I'll accept any patches that fix it.

···

--
Robin Dunn
Software Craftsman

Robin,

I did some tests regarding PlotCanvas.SetBackgroundColor() and it
seems to not be working. (I think it might be setting the Panel
background, and the DC is blitted over it?) I am by no means an
expert wx-user, and have never before submitted a patch, but
I do feel up to the task!

I figure it's simply setting up a couple more variables in
PlotCanvas.__init__, and adding some methods to the tune of
Set/GetBackgroundColour, Set/GetTextForegroundColour, etc.

Also, I notice that in _ticks() the 'ideal' variable (which I assume
indicates the ideal number of ticks to shoot for per axis) is
somewhat
hardcoded to the value of: upper - lower / 7. As my project uses a
small plot, I notice that 7 or so ticks/labels gets a bit crowded.
If there is not another way already implemented, I might variablize
the
ideal variable and implement a corresponding Set/Get method?

I just want to make sure this all sounds rational, as I say I have
never submitted a patch!

Thanks,

···

On Sep 10, 5:36 pm, Robin Dunn <ro...@alldunn.com> wrote:

Have you tried just calling the plot's SetBackgroundColour and
SetForegroundColour methods? It looks like the default _Draw method is
already using those properties appropriately. If it doesn't already
work that way then it really should and I'll accept any patches that fix it.

--
Colin Barnette
<colin dot barnette at gmail dot com>