grid.SetLabelTextColour

Hi all,

In my grid I want to set the text colour for individual labels to red. I cannot find any method to do this.
My labels are Monday, Tuesday,....,Sunday. I want to set the colour of Saturday and Sunday. How can I do this?

Ralf Schoenian

Ralf Schoenian wrote:

In my grid I want to set the text colour for individual labels to red. I cannot find any method to do this.

There isn't a method for that. You can set the color for all but not not each individually.

My labels are Monday, Tuesday,....,Sunday. I want to set the colour of Saturday and Sunday. How can I do this?

AFAIK you need to draw them manually using a PaintDC in the grid column window. Here's what we do in Dabo (simplified):

# in the grid table:
   def GetColLabelValue(self, col):
     # The column headers are painted when the wxGrid queries this method, as
     # this is the most appropriate time to do so. We return "" so that wx
     # doesn't draw the string itself.
     self.grid._paintHeader(col)
     return ""

# in the grid:
Well, _paintHeader is too complicated to post here, but basically you figure out the rect for the column, and set the forecolor/backcolor of the dc depending on column attributes set elsewhere, and paint manually.

The header window is gotten with:
  grid.GetGridColLabelWindow()
and is the window that contains all the headers. You'll want to not erase the background, unless you also want to repaint the rectangle borders, which is problematic because then you don't get platform-specific looks.

I hope this at least starts to help. If you want to try Dabo, you can specify the header properties column by column (forecolor, backcolor, font, size, alignment, etc.) Or you could harvest the relevant code from our dGrid.py file.

···

--
Paul

Paul McNett schrieb:

[...]

I hope this at least starts to help. If you want to try Dabo, you can specify the header properties column by column (forecolor, backcolor, font, size, alignment, etc.) Or you could harvest the relevant code from our dGrid.py file.

Thanks for your explanations.
Do you know a way of not showing the labels in wxPython? I could use the first line of the grid as my header.

But it seems that dabo would make my life easier. Can I just extend my code with dabo or do I have to do a complete rewrite?

Ralf Schoenian

Ralf Schoenian wrote:

Paul McNett schrieb:

[...]

I hope this at least starts to help. If you want to try Dabo, you can specify the header properties column by column (forecolor, backcolor, font, size, alignment, etc.) Or you could harvest the relevant code from our dGrid.py file.

Thanks for your explanations.
Do you know a way of not showing the labels in wxPython? I could use the first line of the grid as my header.

  grid.SetColLabelSize(0)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Ralf Schoenian wrote:

Paul McNett schrieb:

[...]

I hope this at least starts to help. If you want to try Dabo, you can specify the header properties column by column (forecolor, backcolor, font, size, alignment, etc.) Or you could harvest the relevant code from our dGrid.py file.

Thanks for your explanations.
Do you know a way of not showing the labels in wxPython? I could use the first line of the grid as my header.

Sorry, I missed your reply yesterday but I see Robin gave you the answer (setting the column header size to 0).

But it seems that dabo would make my life easier. Can I just extend my code with dabo or do I have to do a complete rewrite?

You should be able to convert class by class, or only daboize certain areas. Each of dabo's UI classes are just the wx classes with dabo stuff mixed-in. So, when you are just starting you can change, e.g.:

import wx
class MyTextBox(wx.TextCtrl):

to:

import dabo
dabo.ui.loadUI("wx")
class MyTextBox(dabo.ui.dTextBox)

and leave everything else alone. Well, there are some things you could do in your __init__ that would screw things up, but it would probably just work.

Most classes don't care if they are a child or parent of a wx or dabo object, so you should be able to just do it piecemeal.

However, some features require the existence of a dApp object, or to be a child object of a dForm. So, you'd probably want to start by daboizing your application object and your frames.

It will be work, and Dabo isn't complete, but you won't find out if it is practical in your case until you spend a couple hours experimenting with it.

···

--
Paul

Robin Dunn schrieb:

Ralf Schoenian wrote:

Paul McNett schrieb:

[...]

I hope this at least starts to help. If you want to try Dabo, you can specify the header properties column by column (forecolor, backcolor, font, size, alignment, etc.) Or you could harvest the relevant code from our dGrid.py file.

Thanks for your explanations.
Do you know a way of not showing the labels in wxPython? I could use the first line of the grid as my header.

    grid.SetColLabelSize(0)

Many thanks for your answer Robin. I just noticed that my workaround is not working. I need a fixed headline for my table because I want to see the days when I am scrolling down. Can I split the table after row 0 or glue this row to her position?

Till now I did the following:

···

#---------------------
backgroundColour=self.grid.GetLabelBackgroundColour()
for i in xrange(lastDay):
    label = "\n".join( (firstDay.weekday,str(firstDay.longDay))) self.grid.SetColLabelValue(int(i), label)
    self.grid.SetCellValue(0,int(i),label)
    self.grid.SetCellAlignment(0,int(i),wx.ALIGN_CENTRE,wx.ALIGN_CENTER)
    self.grid.SetCellBackgroundColour(0,int(i),backgroundColour)
     if firstDay.weekday in ["Sa","So"]:
                self.grid.SetCellTextColour(0,int(i),wx.RED)
    firstDay.add_days(1)

# ----------------

Ralf Schoenian wrote:

Robin Dunn schrieb:

Ralf Schoenian wrote:

Paul McNett schrieb:

[...]

I hope this at least starts to help. If you want to try Dabo, you can specify the header properties column by column (forecolor, backcolor, font, size, alignment, etc.) Or you could harvest the relevant code from our dGrid.py file.

Thanks for your explanations.
Do you know a way of not showing the labels in wxPython? I could use the first line of the grid as my header.

    grid.SetColLabelSize(0)

Many thanks for your answer Robin. I just noticed that my workaround is not working. I need a fixed headline for my table because I want to see the days when I am scrolling down. Can I split the table after row 0 or glue this row to her position?

No, the Grid class doesn't have any features like that.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

With Robins and your help and the example from the wiki page (http://wiki.wxpython.org/index.cgi/DrawingOnGridColumnLabel) I could manage to create the following table :slight_smile: (see png)
The dabo library is great. I have learnt a lot from your dGrid but at the moment I do not dare to completly rewrite my app.

The wiki example is still using the old import style. Because I am now able to alter the example I would like to ask for your permission to alter some lines - although I did not understand the whole source code :frowning:

Ralf Schoenian

Paul McNett schrieb:

···

Ralf Schoenian wrote:

Paul McNett schrieb:

[...]

I hope this at least starts to help. If you want to try Dabo, you can specify the header properties column by column (forecolor, backcolor, font, size, alignment, etc.) Or you could harvest the relevant code from our dGrid.py file.

Thanks for your explanations.
Do you know a way of not showing the labels in wxPython? I could use the first line of the grid as my header.

Sorry, I missed your reply yesterday but I see Robin gave you the answer (setting the column header size to 0).

But it seems that dabo would make my life easier. Can I just extend my code with dabo or do I have to do a complete rewrite?

You should be able to convert class by class, or only daboize certain areas. Each of dabo's UI classes are just the wx classes with dabo stuff mixed-in. So, when you are just starting you can change, e.g.:

import wx
class MyTextBox(wx.TextCtrl):

to:

import dabo
dabo.ui.loadUI("wx")
class MyTextBox(dabo.ui.dTextBox)

and leave everything else alone. Well, there are some things you could do in your __init__ that would screw things up, but it would probably just work.

Most classes don't care if they are a child or parent of a wx or dabo object, so you should be able to just do it piecemeal.

However, some features require the existence of a dApp object, or to be a child object of a dForm. So, you'd probably want to start by daboizing your application object and your frames.

It will be work, and Dabo isn't complete, but you won't find out if it is practical in your case until you spend a couple hours experimenting with it.

Ralf Schoenian wrote:

With Robins and your help and the example from the wiki page (http://wiki.wxpython.org/index.cgi/DrawingOnGridColumnLabel) I could manage to create the following table :slight_smile: (see png)

Great, good to hear.

The wiki example is still using the old import style. Because I am now able to alter the example I would like to ask for your permission to alter some lines - although I did not understand the whole source code :frowning:

Please modify it as appropriate. I haven't looked at that in a long time and I was a wxPython newbie when I posted it. I'm sure it could use some tightening and tweaking.

···

--
Paul