On Thu, 13 Mar 2003 09:22:10 +0800
James Henstridge <[EMAIL PROTECTED]> wrote:
> george young wrote:
>
> >[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.
> >
> >
> 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.
Setting initial text on "realize" worked, thanks much!
> 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?
This application is used in an integrated circuit research fabrication
lab -- users are wearing face shields and gloves and handling dangerous
chemicals and fragile silicon wafers. If the wrong thing is done to a
batch of wafers, many weeks of work can be lost. It is very important
that displayed text be complete.
I am disappointed that the gtk Entry widget does not give a
visual cue when text lies scrolled beyond the visible window. I've seen
GUI's where an arrow appeared at the end of an entry if text was scrolled
out of sight. Though in fact, I think that would not be adequate for
this application. All text must be in plain view.
The software has to do everything possible to avoid user error.
People make enough mistakes on their own ;-).
So it is not capriciously that I am twisting the toolkit...
Thanks again for your help,
George
--
SCSI is not magic. There are fundamental technical reasons why it
is necessary to sacrifice a young goat to your SCSI chain now and
then.
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/