Choad
February 12th, 2007, 08:05 PM
im really beggining to love this language
anyhow... question time
if i have a list
weights ("kilos", "grams", "pounds", "ounces")
and so on. and i use it as a list in a function. but what if i wanted to add another dimension to the array, so each weight metric could have a value associated with it (this is for a conversion app, if you hadnt guessed)
how would i go about this, and how would i make sure its still useable by the function that treats it as a string list?
def setModelFromList (cb, items):
""" Setup a ComboBox or ComboBoxEntry based on a list of strings.
Note: This function was taken from
http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq16.008.htp """
model = gtk.ListStore(str)
for i in items:
model.append([i])
cb.set_model(model)
if type(cb) == gtk.ComboBoxEntry:
cb.set_text_column(0)
elif type(cb) == gtk.ComboBox:
cell = gtk.CellRendererText()
cb.pack_start(cell, True)
cb.add_attribute(cell, 'text', 0)
that be the function in which its used. the list "weights" is passed to this as it's second argument
anyhow... question time
if i have a list
weights ("kilos", "grams", "pounds", "ounces")
and so on. and i use it as a list in a function. but what if i wanted to add another dimension to the array, so each weight metric could have a value associated with it (this is for a conversion app, if you hadnt guessed)
how would i go about this, and how would i make sure its still useable by the function that treats it as a string list?
def setModelFromList (cb, items):
""" Setup a ComboBox or ComboBoxEntry based on a list of strings.
Note: This function was taken from
http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq16.008.htp """
model = gtk.ListStore(str)
for i in items:
model.append([i])
cb.set_model(model)
if type(cb) == gtk.ComboBoxEntry:
cb.set_text_column(0)
elif type(cb) == gtk.ComboBox:
cell = gtk.CellRendererText()
cb.pack_start(cell, True)
cb.add_attribute(cell, 'text', 0)
that be the function in which its used. the list "weights" is passed to this as it's second argument