Question

I develop in python with glade and pygtk since 3 months, but even before I had time to get used to it, it was already obsolete.

Using Archlinux, my system is constantly up to date, so I am forced to use gtk3 even if I found it a bit lacking of features compared to gtk2.

So I decided to switch to pygobject. Unfortunately, the documentation is not complete.

I successfully upgraded my glade file and my python code to the new system, but one error subsists.

In one of my programs, I have a combobox with an entry. I use to call the method get_active_text() to get the content of the entry, regardless if it was selected from the combobox or entered by the user.

This method does not exist any more (I suppose, because it gave me an error) so I use this instead :

def get_license(self):
    #return self.combobox_license.get_active_text()
    tree_iter = self.combobox_license.get_active_iter()
    if tree_iter != None:
        model = self.combobox_license.get_model()
        return model[tree_iter][0]
    else:
        entry = self.combobox_license.get_child()
        return entry.get_text()

As you can see the old code is commented.

This code works, but I have an odd issue : I can't use the entry !

I am able to select the text from the combobox, but the entry is not usable. I can select, but I can't type in it.

Is this a new behavior I need to activate somewhere ? With the gtk2 version of the program, I don't have any problem.

Here is the part in my glade file that describes the combobox entry :

  <object class="GtkComboBox" id="combobox_license">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="model">liststore_license</property>
    <property name="has_entry">True</property>
    <property name="entry_text_column">0</property>
    <signal name="changed" handler="on_combobox_license_changed" swapped="no"/>
    <child>
      <object class="GtkCellRendererText" id="cellrenderertext_license"/>
    </child>
    <child internal-child="entry">
      <object class="GtkEntry" id="combobox-entry2">
        <property name="can_focus">False</property>
        <property name="buffer">entrybuffer1</property>
      </object>
    </child>
  </object>

I created a liststore with one column of type gchararray containing the text. The cell is rendered by the GtkCellRenderer (but the property "text" of the cellrenderer is not defined, because if I define it to 0 (the gchararray), I get the text twice !)

I thought adding an entrybuffer would help, but it does not change anything.

EDIT : I found the solution : can_focus was false for the embedded entry. Now it works, without the need to an entrybuffer.

I found the solution before posting this, but I post it in case other users have this issue too.

Was it helpful?

Solution

Change the can_focus property of the embedded entry of the combobox to true.

OTHER TIPS

If you prefer to use the get_active_text() methods, then you just need to create a Gtk.ComboBoxText instead of a Gtk.ComboBox. This API was split off into another class in GTK 3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top