Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using Glade to write a PyGI app, and I've come across a problem whereby I've got a Gtk.ComboBoxText with a Gtk.Entry, but I cannot make the entry editable for some reason. I.e. when the UI is loaded, there is no way to input text in it.

I've looked at all the entry's properties and also those of the comboboxtext parent, but I could not find anything obvious that I'm missing. Oddly enough, if I create it with code only (i.e. with no Glade .ui files), that seems to work and the entry is then editable.

This code does not work

Code:

#!/usr/bin/env python

from gi.repository import Gtk

class Combo:
    def __init__(self):
        builder = Gtk.Builder()
        builder.add_from_file('combo.ui')
        window = builder.get_object('window1')
        window.connect('destroy', lambda w: Gtk.main_quit())
        window.show_all()

Combo()
Gtk.main()

Glade file:

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <!-- interface-requires gtk+ 3.0 -->
  <object class="GtkWindow" id="window1">
    <property name="can_focus">False</property>
    <child>
      <object class="GtkComboBoxText" id="comboboxtext1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="has_entry">True</property>
        <property name="entry_text_column">0</property>
        <property name="id_column">1</property>
        <child internal-child="entry">
          <object class="GtkEntry" id="comboboxtext-entry">
            <property name="can_focus">False</property>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

This code works

#!/usr/bin/env python

from gi.repository import Gtk

class Combo:
    def __init__(self):
        window = Gtk.Window()
        window.set_default_size(200, 200)

        combo = Gtk.ComboBoxText.new_with_entry()
        combo.set_hexpand(True)

        window.connect("destroy", lambda w: Gtk.main_quit())

        window.add(combo)
        window.show_all()

Combo()
Gtk.main()

Any pointers on how to make the text entry editable in the Glade code?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Try setting can_focus to True, if you can't give keyboard focus to the entry you won't be able to type anything into it.

share|improve this answer
    
Weird, I thought I had tried that already, but perhaps I had only set it for the Gtk.ComboBoxText. In any case, setting can_focus to True for the Gtk.Entry does the trick. A bit confusing that Glade does not do that by default, as with a regular text entry... –  David Planella May 19 '12 at 14:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.