Style information is not calculated until the widget is anchored in the widget tree. Until that happens, it can't know which styles from the gtkrc file will apply (which may even affect the size of the entry widget). You could try ignoring text changes while not realised, but explicitly make the change from a realize handler.[gtk+-2.2.1, pygtk-1.99.15, python 2.3a1] I want to have an Entry change it's width to exactly track the width of it's string contents. What I have *almost* works: after I click on the widget and change something, it's fine. But initially only part of the string is shown. Here's my code:
import gtk, pango def ch_cb(w): l = w.get_layout() w.set_size_request((2 * w.get_layout_offsets()[0]) + l.get_pixel_size()[0], -1)
top = gtk.Window(gtk.WINDOW_TOPLEVEL) top.show() e = gtk.Entry() e.modify_font(pango.FontDescription('monospace')) e.connect('changed', ch_cb) e.show() h=gtk.HBox() top.add(h) h.show() e.set_text('the rain in spain stays') h.pack_start(e,gtk.TRUE, gtk.FALSE, 0) gtk.mainloop()
If the set_text line is put *after* the pack_start, then it works properly. It seems as if the font width info is incorrect until there is a complete chain of parent widgets up to the top.
I tried e.connect("realize",ch_cb), likewise with "map" and "show"
but to no avail. Is there some event I can connect to that would
happen late enough? Changing the font via gtkrc file
fails the same.
Of course, the fact that this is so hard to do may indicate that it isn't a good idea :) No other GTK applications do this, so your app will look and behave differently to them all. Is that intended?
James.
-- Email: [EMAIL PROTECTED] WWW: http://www.daa.com.au/~james/
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
