Johannes Bauer wrote:
And so I learn something new! On a hunch, I compared a Glade file with an empty (unaltered) combo box and a combo box with its "Items" field "changed". I put the "changed" in quotes, because what I did was add a character and delete it again, so no text was really added. It turns out that the output XML differs by one line that defines an "items" property (see attached comboboxes.diff).Timo schrieb:for item in ["foo", "bar"]: combobox.get_model().append([item])Apparently after entering something in Glade, the liststore etc are generated. And by removing these items, it keeps these.Sadly, my version of Glade does not generate the XML the way you described when I do it the way you described :-( I guess I'll stick with Walter's solution then. It's just very very confusing for a GTK beginner to have to do such low-level tasks in order to perform such a relatively simple and common thing. Kind regards and thanks for your help, Johannes
The inclusion of that "items" property causes the created ComboBox to be initialized (ListStore and CellRendererText created and correctly associated with the ComboBox). In fact you can use the *_text() methods with such an "initialized" ComboBox!
I've attached my test program and Glade file as well.This is certainly a new discovery for me and should make it much simpler to work with simple ComboBoxes.
HTH, -- Walter Leibbrandt http://translate.org.za/blogs/walter Software Developer +27 12 460 1095 (w) Translate.org.za Recent blogs: * Firefox-style button with a pop-up menu http://www.translate.org.za/blogs/walter/en/content/firefox-style-button-pop-menu * Virtaal's MVCisation * Things that changed the way I code
--- combo_without_items.glade 2009-03-06 17:05:47.000000000 +0200
+++ combo_with_items.glade 2009-03-06 17:04:04.000000000 +0200
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Fri Mar 6 17:05:47 2009 -->
+<!--Generated with glade3 3.4.5 on Fri Mar 6 17:04:04 2009 -->
<glade-interface>
<widget class="GtkWindow" id="window1">
<child>
<widget class="GtkComboBox" id="combobox1">
<property name="visible">True</property>
+ <property name="items" translatable="yes"></property>
</widget>
</child>
</widget>
combo_with_items.glade
Description: application/glade
#!/usr/bin/env python
import gtk
from gtk import glade
xml = glade.XML('combo_with_items.glade')
win = xml.get_widget('window1')
win.connect('destroy', lambda *args: gtk.main_quit())
cmb = xml.get_widget('combobox1')
# ^^ Note that there is no more combo box initialization above!
# Add initial items to combo box
for i in ['a', 'b', 'c', 'd']:
cmb.get_model().append([str(i)])
# Test _text() methods
cmb.append_text('e') # Items: a b c d e
cmb.insert_text(2, 'X') # Items: a b X c d e
cmb.prepend_text('_') # Items: _ a b X c d e
cmb.remove_text(1) # Items: _ b X c d e
win.show_all()
gtk.main()
_______________________________________________ pygtk mailing list [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
