gtk treeview: place image buttons on rows
Asked Answered
C

3

7

For each row in my treeview, I want 4 image buttons next to each other. They will act like radio buttons, with only one being activateable at a time. Each button has an 'on' and 'off' image.

How do I do this? I figured out how to put images there, and how to put togglebuttons, but this seems to require some more effort as there is no pre-built cellrenderer that does what I want.

Basically what'd solve my problem is figuring out how to make an image in a gtk.treeview clickable. any ideas?

Chartreuse answered 9/2, 2011 at 1:1 Comment(0)
C
2

Have a look at this 'http://www.daa.com.au/pipermail/pygtk/2010-March/018355.html'. It shows you how to make a gtk.CellRendererPixbuf activatable, and able to connect to a click event signal.

cell = CellRendererPixbufXt()
cell.connect('clicked', func)

Update

As pointed out this answer, or the reference given doesn't work as advertised. It's missing the do_activate method, which needs to emit the clicked signal. Once it's done that, then the cell.connect will work.

Sorry if this answer mislead anyone.

Cancroid answered 6/7, 2011 at 6:45 Comment(5)
I don't know what you're looking at but my reference does. I notice your answer does pretty much the same thing as the reference I gave. If you're complaining about something else, please be a little clearerCancroid
The clicked signal is never triggered. Actually, this isn't a big surprise if I quote from your reference: "but i'm not sure how to emit the custom "clicked" signal, when the user clicks on the CellRenderer."Tonicity
At least your're being clearer now. Why you didn't say this in the first place. I'll check it out when I have the time, but it's been over a year, so I'm in no hurry. I'm surprised it got accepted in the first place if it doesn't work.Cancroid
The link is down. You could you extend your answer, please?Underbelly
I think the answer below mine by schlamar is a better answer and gives an example. Really it should be marked as the correct answer, not mine. Honestly I've not touched GTK for a few years now.Cancroid
T
3

Here is a short version without kiwi requirement.

class CellRendererClickablePixbuf(gtk.CellRendererPixbuf):

    __gsignals__ = {'clicked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                                (gobject.TYPE_STRING,))
                   }

    def __init__(self):
        gtk.CellRendererPixbuf.__init__(self)
        self.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE)

    def do_activate(self, event, widget, path, background_area, cell_area,
                    flags):
        self.emit('clicked', path)
Tonicity answered 16/1, 2013 at 15:51 Comment(2)
I'm trying to use your code but I'm getting gi.repository.Gtk' object has no attribute 'CELL_RENDERER_MODE_ACTIVATABLE' - any ideas why?Kovach
@Kovach - Only 8 years too late, but CELL_RENDERER_MODE_ACTIVATABLE is from GTK2Fluoroscopy
C
2

Have a look at this 'http://www.daa.com.au/pipermail/pygtk/2010-March/018355.html'. It shows you how to make a gtk.CellRendererPixbuf activatable, and able to connect to a click event signal.

cell = CellRendererPixbufXt()
cell.connect('clicked', func)

Update

As pointed out this answer, or the reference given doesn't work as advertised. It's missing the do_activate method, which needs to emit the clicked signal. Once it's done that, then the cell.connect will work.

Sorry if this answer mislead anyone.

Cancroid answered 6/7, 2011 at 6:45 Comment(5)
I don't know what you're looking at but my reference does. I notice your answer does pretty much the same thing as the reference I gave. If you're complaining about something else, please be a little clearerCancroid
The clicked signal is never triggered. Actually, this isn't a big surprise if I quote from your reference: "but i'm not sure how to emit the custom "clicked" signal, when the user clicks on the CellRenderer."Tonicity
At least your're being clearer now. Why you didn't say this in the first place. I'll check it out when I have the time, but it's been over a year, so I'm in no hurry. I'm surprised it got accepted in the first place if it doesn't work.Cancroid
The link is down. You could you extend your answer, please?Underbelly
I think the answer below mine by schlamar is a better answer and gives an example. Really it should be marked as the correct answer, not mine. Honestly I've not touched GTK for a few years now.Cancroid
N
1

Here is what worked for me:

class CellRendererClickablePixbuf(gtk.CellRendererPixbuf):
    gsignal('clicked', str)
    def __init__(self):
        gtk.CellRendererPixbuf.__init__(self)
        self.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE)
    def do_activate(self, event, widget, path, background_area, cell_area, flags):
        self.emit('clicked', path)
Negress answered 25/12, 2011 at 23:27 Comment(1)
I assume you refer to kiwi.utils.gsignal?Tonicity

© 2022 - 2024 — McMap. All rights reserved.