[pygtk] TreeView / ListStore question: tabbing through coulmns

Jordan Callicoat monkeesage at gmail.com
Thu Feb 1 08:11:47 WST 2007


Forward to list:

On Wed, 31 Jan 2007 14:08:19 -0800
Seth Mahoney <smahoney at pdx.edu> wrote:

> 
> 
>    You probably just need to connec to the "edited" event.  gtk  
> doesn't seem to automatically apply changes to edited cells, so in  
> your callback for the edited signal you need to explicitely set the  
> text of the cell.  You can find more info in the pygtk docs for  
> gtk.CellRendererText
> 
>    Quoting Jordan Callicoat <monkeesage at gmail.com>:
> 
> > Hi list,
> >
> > I have a callback connected to a treeview (liststore model,
> > editable) for 'key_press_event', and I want to capture 'Tab' key
> > presses and move from one column to the next. I have this working;
> > the problem is, when the current cell is being edited, and I call
> > 'set_cursor' to move to the next column, the text from the original
> > cell is not updated. I think I need to emit the 'edited' signal on
> > the cellrenderer before I call 'set_cursor', but I'm running into
> > the problem of getting the updated text from the cell in order to
> > pass it to emit. How can I do this properly? Here's the callback:
> >
> >
> >    def on_key_press(self, widget, event):
> >      keyname = gtk.gdk.keyval_name(event.keyval)
> >      if keyname == 'Tab': # event.keyval = 65289
> >        row, col = widget.get_cursor()
> >        if row == None:
> >          row = self.get_first_selected_row()
> >        if col == None:
> >          col = 0
> >        else:
> >          col = col.get_data('id') + 1
> >        if col == self.colcount:
> >          col = 0
> >        if isinstance(row, (list, tuple)):
> >          row = row[0]
> >        renderer  = widget.get_column(col - 1).get_data('renderer')
> >        tree_iter = self.model.get_iter(row)
> >        text      = self.model.get_value(tree_iter, col - 1)
> >        renderer.emit('edited', row, text)
> >        widget.set_cursor(row, widget.get_column(col), True) #
> > <- ????? self.get_rows()
> >        return True # cancel the event
> >
> > Ps. This is just draft code, I know it's ugly. I'll refactor
> > and clean everything after I get it working right. :)
> >
> > Thanks,
> > Jordan
> > _______________________________________________
> > pygtk mailing list   pygtk at daa.com.au
> > http://www.daa.com.au/mailman/listinfo/pygtk
> > Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
> >
> >
> 
> 
> 

Hi Seth,

Thanks for your reply. I have a callback connected to 'edited' on the
cellrenderer already, but it doesn't appear to be getting called here.
Seems like it's getting 'editing-canceled' when I call 'set_cursor',
which is why I thought I might have to emit 'edited' manually prior
to setting the cursor on the next cell.

Regards,
Jordan


More information about the pygtk mailing list