wx.DC foreground color

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

wx.DC foreground color

Jeff Grimmett-3
Hi,

I'm working with wx.grid.Grid and custom column headers using wx.lib.mixins.gridlabelrenderer.GridLabelRenderer.  I am trying to create a black background with white foreground text column header.

Unfortunately, while the background color works fine, the foreground color is always black, not the selected color.

The code example is based off of the demo for GridLabelRenderer with minor mods.

import wx
import wx.grid as gridLib
import wx.lib.mixins.gridlabelrenderer as glr


class labelGridRenderer(glr.GridLabelRenderer):
    def __init__(self):
        self._bgcolor = "#000000"
        self._fgcolor = wx.Colour(255, 255, 255)

    def Draw(self, grid, dc, rect, col):
        dc.SetBrush(wx.Brush(self._bgcolor))
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangle(rect)
        hAlign, vAlign = grid.GetColLabelAlignment()
        text = grid.GetColLabelValue(col)
        self.DrawBorder(grid, dc, rect)
        dc.SetTextForeground(self._fgcolor)
        self.DrawText(grid, dc, rect, text, hAlign, vAlign)

What am I missing?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/74945e22-874a-4c75-b617-146a9cd78ea6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: wx.DC foreground color

Robin Dunn


On Monday, July 1, 2019 at 7:23:32 PM UTC-7, J Grimmtooth wrote:
Hi,

I'm working with wx.grid.Grid and custom column headers using wx.lib.mixins.gridlabelrenderer.GridLabelRenderer.  I am trying to create a black background with white foreground text column header.

Unfortunately, while the background color works fine, the foreground color is always black, not the selected color.


 
        self.DrawText(grid, dc, rect, text, hAlign, vAlign)

What am I missing?


The DrawText method does this:

        dc.SetTextForeground(grid.GetLabelTextColour())
 

So it is undoing the color you set it to. You can either do a grid.SetLabelTextColour or draw the text on the dc yourself.

--
Robin

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/d7dce1ca-02b0-4365-bbb6-590cabd88f0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: wx.DC foreground color

Jeff Grimmett-3
Robin,

Okay, I did it like this, and it worked, thanks :)

See any obvious gotchas before I move on to the next problem?

    def Draw(self, grid, dc, rect, col):
        dc.SetBrush(wx.Brush(self._bgcolor))
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangle(rect)
        hAlign, vAlign = grid.GetColLabelAlignment()
        text = grid.GetColLabelValue(col)
        self.DrawBorder(grid, dc, rect)
        grid.SetLabelTextColour(self._fgcolor)
        self.DrawText(grid, dc, rect, text, hAlign, vAlign)

Regards,

Jeff


Virus-free. www.avast.com

On Mon, Jul 1, 2019 at 11:00 PM Robin Dunn <[hidden email]> wrote:


On Monday, July 1, 2019 at 7:23:32 PM UTC-7, J Grimmtooth wrote:
Hi,

I'm working with wx.grid.Grid and custom column headers using wx.lib.mixins.gridlabelrenderer.GridLabelRenderer.  I am trying to create a black background with white foreground text column header.

Unfortunately, while the background color works fine, the foreground color is always black, not the selected color.


 
        self.DrawText(grid, dc, rect, text, hAlign, vAlign)

What am I missing?


The DrawText method does this:

        dc.SetTextForeground(grid.GetLabelTextColour())
 

So it is undoing the color you set it to. You can either do a grid.SetLabelTextColour or draw the text on the dc yourself.

--
Robin

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/d7dce1ca-02b0-4365-bbb6-590cabd88f0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/CA%2B1iZEeeG6BX7kx18QH0Cv_1n6PvynhyVNeCBAtbKJ%2BcrHSPqQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: wx.DC foreground color

Robin Dunn
On Tuesday, July 2, 2019 at 4:49:44 AM UTC-7, Jeff Grimmett wrote:
Robin,

Okay, I did it like this, and it worked, thanks :)

See any obvious gotchas before I move on to the next problem?

LGTM

--
Robin 

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/71ddcba7-19d1-47a2-ac83-0659a4161291%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.