import gtk
import pango

if __name__ == "__main__":
    gtk.rc_parse_string('''
style "mono" { font_name = "Bitstream Vera Sans 24" }
class "GtkEntry" style "mono"
class "GtkLabel" style "mono"
    ''')
    win = gtk.Window()
    win.connect('delete-event', gtk.main_quit)

    s = '1234567890' * 4
    if 0:
	entry = gtk.Entry()
	entry.set_editable(False)
	entry.set_text(s)
	entry.set_position(0)
    else:
	entry = gtk.Label(s)
	entry.set_ellipsize(pango.ELLIPSIZE_END)

    win.add(entry)
    entry.ensure_style()

    context = entry.get_pango_context()
    print context.get_font_description().to_string()
    font_metrics = context.get_metrics(context.get_font_description(), 
                                       context.get_language())
    print font_metrics.get_approximate_digit_width() / 1024.
    char_width = font_metrics.get_approximate_digit_width()
    entry_width = pango.PIXELS(char_width * len(s))
    entry.set_size_request(entry_width, -1)

    win.show_all()

    gtk.main()
