[pygtk] Re: How to size widgets below min size
Casey McGinty
casey.mcginty at gmail.com
Mon Jun 23 12:49:17 WST 2008
On Tue, Jun 17, 2008 at 11:28 PM, Casey McGinty <casey.mcginty at gmail.com>
wrote:
> 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?
>
>
Posting the solution to my previous question. Any comments are welcome. Hope
someone can use this in the future.
comboboxbasic.py
-----------------------------
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import pango
class ComboBoxExample:
def __init__(self):
window =3D gtk.Window()
window.connect('destroy', lambda w: gtk.main_quit())
liststore =3D gtk.ListStore(gobject.TYPE_STRING)
liststore.append( ['Select a pie:'])
liststore.append( ['Apple'])
liststore.append( ['Cherry'])
liststore.append( ['Blueberry'])
liststore.append( ['Grape'])
liststore.append( ['Peach'])
liststore.append( ['Raisin'])
combobox =3D gtk.ComboBox(liststore)
cell =3D gtk.CellRendererText()
###########
# ellipsize the text box is the key to getting the '...' feature
cell.set_property( 'ellipsize', pango.ELLIPSIZE_END )
###########
combobox.pack_start(cell, True)
window.add(combobox)
combobox.add_attribute(cell, 'text', 0)
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/20080622/50e19078/at=
tachment.htm
More information about the pygtk
mailing list