[pygtk] How to size widgets below min size

Casey McGinty casey.mcginty at gmail.com
Wed Jun 18 17:28:11 WST 2008


Hi,

I'm trying to create a combobox object than can be sized smaller than the
text. What is the best way to go about doing this?

For example, with the code below, the width is fixed at the value needed for
the max length string. But I would like to allow it to shrink to a smaller
width, in which case the displayed text might show "Select a ...", then
"Sele...", and finally "...". An example of this behavior would be the
status combo box at the bottom of the main window in Pidgin / Gaim.

Thanks,
Casey

comboboxbasic.py
-----------------------------
#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk

class ComboBoxExample:
    def __init__(self):
        window =3D gtk.Window()
        window.connect('destroy', lambda w: gtk.main_quit())
        combobox =3D gtk.combo_box_new_text()
        window.add(combobox)
        combobox.append_text('Select a pie:')
        combobox.append_text('Apple')
        combobox.append_text('Cherry')
        combobox.append_text('Blueberry')
        combobox.append_text('Grape')
        combobox.append_text('Peach')
        combobox.append_text('Raisin')
        combobox.connect('changed', self.changed_cb)
        combobox.set_active(0)
        window.show_all()
        return

    def changed_cb(self, combobox):
        model =3D combobox.get_model()
        index =3D combobox.get_active()
        if index:
            print 'I like', model[index][0], 'pie'
        return

def main():
    gtk.main()
    return

if __name__ =3D=3D "__main__":
    bcb =3D ComboBoxExample()
    main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20080617/be31ce97/at=
tachment.htm


More information about the pygtk mailing list