[pygtk] liststore (ComboBoxEntry) alignment (justify)
John Kelly
kelly_worth2003 at yahoo.co.uk
Fri Mar 9 00:55:21 WST 2007
On Thu, 2007-03-08 at 16:10 +0200, Miki wrote:
> Hi all,
> I'm still new to pygtk and I have two question, i hope it's not too
> stupid questions :)
>
> 1. I want to create a ComboBox by using the liststore object. my issue
> is that I want to set the alignment (justify) of the text in the
> combobox to right, how can I do that?
>
> 2. In addition, I want to to head default value to the liststore to
> show it as default in the combo box, something like "== Choose from
> List ==. I can add it to liststore but how can I show it by default in
> the combo box?
>
> 3. It is posible to add icons next to the text in the ComboBox? if yes
> how can I do that?
>
>
> Thanks for any help,
>
> Miki
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
To use a liststore object with a combobox. You first need to declare
what you want the liststore to contain. e.g. To create a liststore which
will hold a pixbuf and string
liststore = gtk.ListStore(gtk.gdk.Pixbuf, str)
Create an image to be added to the liststore.
image = gtk.gdk.pixbuf_new_from_file("/home/user/image.png")
Append the created image and a string to the liststore.
liststore.append((image, "Some Text"))
The append method requires a tuple or a list which contains the items to
be added to the model.
We now need the combobox to use the model we created.
combobox.set_model(liststore)
We now need to render the data we have in the model.
We create a gtk.CellRendererPixbuf() for our image and a
gtk.CellRendererText() for our string.
px = gtk.CellRendererPixbuf()
text = gtk.CellRendererText()
Pack the cell renderer into the combobox.
combobox.pack_start(px, False, False)
combobox.pack_start(text, False, False)
Use the add_attribute method to specify which column in the model the
CellRendererPixbuf() will get values from.
combobox.add_attribute(px, "pixbuf", 0)
Do the same for CellRendererText()
combobox.add_attribute(text, "text" 1)
The first parameter for the add_attribute method specifies the cell
renderer to use. The second parameter specifies the attribute of the
cell to be used to get its value. The last parameter specifies which
column in the model the cell renderer will use.
To align the string to the left, i would use combobox.pack_end(text,
False, False)
To set a default choice in the combobox, i would use
combobox.set_active() to set the default choice in the combobox.
John
___________________________________________________________
Does your mail provider give you FREE antivirus protection?
Get Yahoo! Mail http://uk.mail.yahoo.com
More information about the pygtk
mailing list