0

I have a simple question. I am using a GtkTreeView, where one column is displayed as GtkCellRendererCombo. The user can either freely edit the text of the cell, or choose for it a value from the combo.

The problem is that once the user chooses a value from the combo, I need to capture the text he was previously writing into the cell.

I cannot use the GtkTreeStore object for capturing the text, because the edit has not finished yet and therefore the GtkTreeStore is not up to date.

Is there anyone with any suggestion?

madmurphy
  • 1,451
  • 11
  • 20

1 Answers1

2

If you are using Gtk 2, it works to hook up to the 'editing-started' signal of the cellrenderercombo. Then do a combobox.get_child(), which returns the text entry of the combo. Then you would hook up a 'changed' signal to the text entry to retrieve the text the user is typing.

If you are using Gtk 3 you need to create your own custom cell renderer widget so that you can have access to the entry. I created my own combo widget in Python to have autocompletion in the entry, but I am not sure if that would help you.

theGtknerd
  • 3,647
  • 1
  • 13
  • 34
  • Thanks for your answer! I had already solved the problem, by doing exactly as you would have suggested. – madmurphy Oct 02 '16 at 01:11
  • Thanks for accepting my answer. I am trying to gain reputation on StackOverflow. :) However for my own info, could you tell me if you went the Gtk 2 route, or did you make your own custom cell renderer widget? – theGtknerd Oct 02 '16 at 02:54
  • 1
    I am using GTK3. But your suggestion regarding GTK2 is still perfectly valid and seems to be the way suggested by the GTK+ 3 Reference Manual: «Further properties of the combo box can be set in a handler for the “editing-started” signal» – see: https://developer.gnome.org/gtk3/stable/GtkCellRendererCombo.html#GtkCellRendererCombo.description So, under the "editing-started" signal of the GtkCellRendererCombo, I saved a reference to the GtkComboBox child (to be reused later) and connected a signal to the "format-entry-text" event of its GtkEntry object. – madmurphy Oct 03 '16 at 13:08
  • I am writing a general purpose GNOME editor for editing system configuration files. I would like to involve also other people, since it is an opensource hobby project. My treeview has a “Value” column (combo) and a “Comment” column (text). When someone chooses a value from the combo I need to update also the “Comment” cell, therefore I try to change the GtkTreeStore object. But by doing so I stop the edit before the value from the combo is inserted, so if I update the comment I cannot update the value. Do you by chance know a solution? If it's needed I will open a new thread. – madmurphy Oct 03 '16 at 13:24
  • Honestly, my primary limitation is going to be that I know python, and not C. :( But yes, start a new thread and post it back here. That way we don't clutter this thread with a different topic. Furthermore, you don't have a SourceForge or GitHub repository I can download do you? I love opensource too. And yes, I have a couple suggestions for you. – theGtknerd Oct 04 '16 at 15:11
  • I do have a GitHub account: https://github.com/madmurphy/. I just published there my library for parsing .conf/.ini files: https://github.com/madmurphy/libconfini/ (it is going to do the “dirty job” for the GUI editor). The reasons behind that library are a bit explained in the README file. Unfortunately, regarding the GUI editor, it's a bit too early for publishing anything (I am still making experiments in a very messy code and planning things). But I would be very happy if we keep in touch. My email address is madmurphy333 at gmail dot com. – madmurphy Oct 05 '16 at 23:43