0

I'm trying to show a GtkFileChooserDialog when a GtkTreeView column that contains paths is edited.

I've come up with 2 possible ways to implement this:

  1. Hook the "editing-started" signal on the GtkCellRendererText that shows the path. However this still requires that the "editing" be done inside the cell. I can't show a dialog and then cancel the usual editing process.
  2. Add a "..." button into the column. Catch "clicked" signals on the button, and use this to show the dialog. However only GtkCellRenderers can be added to a column, so I have no idea how to implement this.

How should I proceed? What's the standard method to edit paths in a GtkTreeView?

gpoo
  • 8,408
  • 3
  • 38
  • 53
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526

1 Answers1

1

You can override CellRendererText's do_start_editing method to completely change its behaviour:

class CellRendererFile(gtk.CellRendererText):
    def __init__(self):
        gtk.CellRendererText.__init__(self)
        self.props.editable = True

    def do_start_editing(self, event, widget, path, background_area, cell_area, flags):
        # TODO: Show dialog.
        self.emit('edited', path, "TODO: Dialog output")

gobject.type_register(CellRendererFile)

And then just use normally, connect to the "edited" signal.

Johannes Sasongko
  • 4,178
  • 23
  • 34
  • I tried this by calling self.editing_stopped in the "editing-started" handler, and that didn't work. I'll try it this way thanks. – Matt Joiner Jan 27 '11 at 02:32