You are not logged in.

#1 2010-02-08 06:00:38

passbe
Member
Registered: 2009-03-14
Posts: 74
Website

[SOLVED] Pygtk - Treeview Problems

I'm creating my first python gui app. A small todo list, nothing fancy. I have all the underlying code working I just need to format my Treeview in the desired way. This is where the problem lies.

Is there anyway to hide a particular cell, or change a render on a cell by cell basis. For instance I have a list of tasks in the first column and the second column has a checkbox. Now on category titles I do not want to have the checkbox visible as it is not classified as a task, is there any way to achieve this ?

Thanks for your help

Edit: should have mentioned I'm using pygtk.

Last edited by passbe (2010-02-10 08:52:37)

Offline

#2 2010-02-08 08:05:51

lman
Member
From: CZ
Registered: 2007-12-18
Posts: 255

Re: [SOLVED] Pygtk - Treeview Problems

maybe define a callback to the column with set_cell_data_func: http://library.gnome.org/devel/pygtk/st … -data-func
and modify the cell yourself.

Last edited by lman (2010-02-08 08:06:06)

Offline

#3 2010-02-08 08:15:47

passbe
Member
Registered: 2009-03-14
Posts: 74
Website

Re: [SOLVED] Pygtk - Treeview Problems

@lman: I should have mentioned I have tried that, once I define that function and get the CellRenderer, i can only ever refer to the entire column and not that individual cell.

Offline

#4 2010-02-08 10:33:34

lman
Member
From: CZ
Registered: 2007-12-18
Posts: 255

Re: [SOLVED] Pygtk - Treeview Problems

I used it before, and it worked for me. I used it to highlight the current track in a playlist.
[url=http://code.google.com/p/etude-music-player/source/browse/etude/gui/collview.py#212]example[url]see the current_highlight function
Edit: try using the iter variable to get data from other columns/same column to filter

Last edited by lman (2010-02-08 10:34:54)

Offline

#5 2010-02-09 02:31:56

passbe
Member
Registered: 2009-03-14
Posts: 74
Website

Re: [SOLVED] Pygtk - Treeview Problems

So I have setup the function, but when adding the visible = false property to hide the toggle box for that one cell, it hides the entire cellrenderer ie the entire column.

        self.cellrender_complete = gtk.CellRendererToggle()
        self.col_complete = gtk.TreeViewColumn('Complete', self.cellrender_complete, active=3)
        self.treeview.append_column(self.col_complete)
        self.col_complete.set_cell_data_func(self.cellrender_complete, self.currentCell)

and the current cell function

    def currentCell(self, column, cell, model, iter):
        if self.treestore.get_value(iter, 1) == 'C':
            cell.set_property('visible', False)

Offline

#6 2010-02-09 16:42:01

lman
Member
From: CZ
Registered: 2007-12-18
Posts: 255

Re: [SOLVED] Pygtk - Treeview Problems

Do you have the whole code on a public page, so I can try it out myself?
Why not use the 'model' from the parameters instead of 'self.treestore'?

Offline

#7 2010-02-10 07:53:54

passbe
Member
Registered: 2009-03-14
Posts: 74
Website

Re: [SOLVED] Pygtk - Treeview Problems

I do: http://github.com/trcm/todo/blob/gui2/todo.py you will see line 47 is where I bind the function, and line 71 is where I attempt to set the visible status to that cell.

Yes I do need to store the parameters in the model, need to sort that out.

Offline

#8 2010-02-10 08:46:00

lman
Member
From: CZ
Registered: 2007-12-18
Posts: 255

Re: [SOLVED] Pygtk - Treeview Problems

I'm not sure exactly why, but you should set it back to visible, when it's not a category. This worked for me:

def currentCell(self, column, cell, model, iter):
    if model.get_value(iter, 1) == 'C':
        cell.set_property('visible', False)
    else:
        cell.set_property('visible', True)

Last edited by lman (2010-02-10 08:51:07)

Offline

#9 2010-02-10 08:52:23

passbe
Member
Registered: 2009-03-14
Posts: 74
Website

Re: [SOLVED] Pygtk - Treeview Problems

that worked a treat, can't believe I didn't think to do that. thank you for your help.

Offline

Board footer

Powered by FluxBB