is there a way i can set the forground or text colour of a row's label? the only methods i can find set the colour for the whole grid.
Timothy Smith wrote:
is there a way i can set the forground or text colour of a row's label? the only methods i can find set the colour for the whole grid.
The Grid wasn't designed to allow for this so you need to take over the paint event for the window used for the row labels. I think that there have been some examples posted here in the past that show how to do this.
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
Robin Dunn wrote:
Timothy Smith wrote:
is there a way i can set the forground or text colour of a row's label? the only methods i can find set the colour for the whole grid.
The Grid wasn't designed to allow for this so you need to take over the paint event for the window used for the row labels. I think that there have been some examples posted here in the past that show how to do this.
ok i'v eplayed around with some of the examples i'f found, however while i'm able to mess up my grids nicely so far i haven't been able to produce a rowlabel i can actually see. i'm guessing i'm missing something that makes my new rectangle visible?
once i can see what i'm painting i can recreate normal looking row labels, and colour them as i please.
rowLabelWindow = self.GetGridRowLabelWindow()
event.eventManager.Register( self.OnRowHeaderPaint,wx.EVT_PAINT,rowLabelWindow)
def OnRowHeaderPaint(self, evt):
"This will alter the painting of rows"
RowLabel = self.GetGridRowLabelWindow()
dc = wx.PaintDC(RowLabel)
dc.SetBrush(wx.Brush("WHEAT", wx.TRANSPARENT))
dc.SetTextForeground(wx.BLACK)
dc.DrawRectangle(100,30,150,60)
self.Refresh()
Timothy Smith wrote:
awesome it works, however, how do you get that gradient look to the row labels? they look a little odd since other labels are a gradient type gray where mine are a flat colour.
You must be on Linux. In that case the Grid uses wx.RendererNative to draw the labels, calling the DrawHeaderButton method, which makes native gtk API calls. I'm not sure why the Grid doesn't use the renderer for the other platforms, it probably could without problems.
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
Timothy Smith wrote:
Robin Dunn wrote:
Timothy Smith wrote:
Robin Dunn wrote:
Timothy Smith wrote:
awesome it works, however, how do you get that gradient look to the row labels? they look a little odd since other labels are a gradient type gray where mine are a flat colour.
You must be on Linux. In that case the Grid uses wx.RendererNative to draw the labels, calling the DrawHeaderButton method, which makes native gtk API calls. I'm not sure why the Grid doesn't use the renderer for the other platforms, it probably could without problems.
ok, i also have one last question, by over riding the paint method myself it appears to break GetRowLabelValue etc.
In what way does it appear to break?
it returns nothing, sample code
Handling the paint event should have nothing to do with the row labels, they are either fetched from the table, or it is just converted from the row number. It has a very simple implementation:
wxString wxGrid::GetRowLabelValue( int row )
{
if ( m_table )
{
return m_table->GetRowLabelValue( row );
}
else
{
wxString s;
s << row;
return s;
}
}
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
Timothy Smith wrote:
your right, i've got it working fine now. i also had a play with it in both windows and under gtk (freebsd), and under gtk it doesn't inherit the default theme for the grid labels.
Right. This is what I mentioned before about it using the wx.RendererNative class for drawing the labels.
under windows you can't see anything different since it's just a flat colour.
one last question. when i create my labels, how do i give them that raised border look like the default ones? at the moment mine are just flat black borders.
You need to draw some lighter and darker lines to give it a 3D look. For an example you can look at the wx.lib.buttons module. Also, this is how the Grid does it when it draws the labels itself on platforms other than wxGTK:
int rowTop = GetRowTop(row),
rowBottom = GetRowBottom(row) - 1;
dc.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW), 1, wxSOLID) );
dc.DrawLine( m_rowLabelWidth - 1, rowTop, m_rowLabelWidth - 1, rowBottom );
dc.DrawLine( 0, rowTop, 0, rowBottom );
dc.DrawLine( 0, rowBottom, m_rowLabelWidth, rowBottom );
dc.SetPen( *wxWHITE_PEN );
dc.DrawLine( 1, rowTop, 1, rowBottom );
dc.DrawLine( 1, rowTop, m_rowLabelWidth - 1, rowTop );
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!