I would like to pass to a function a list of types and data to register a Gtk.ListStore object. It works with a single type, passed directly as an argument, but as soon as there are several types it is necessary to use a container (list?). And in this case, I do not know how to rebase these types (str, int, etc.) into gobject.Gtype. If anyone has a solution that would be great. Sample code below.
thank you in advance.
# Fonctions
def initListStore(lesTypes, laListe):
leStore = Gtk.ListStore(gobject.Gtype(lesTypes))
for item in laListe:
leStore.append(item)
return leStore
# Appli
liste = [('Albert','Einstein'),('Salvador','Dali'),('Alexandre','Dumas')]
lesTypes = 'str str'
lsAuteurs = initListStore(lesTypes,liste)
for row in lsAuteurs:
print (row[:])
Here is one possible solution:
from gi.repository import Gtk
def initListStore(lesTypes, laListe):
leStore = Gtk.ListStore()
leStore.set_column_types(lesTypes)
for item in laListe:
leStore.append(item)
return leStore
# Appli
liste = [('Albert','Einstein'),('Salvador','Dali'),('Alexandre','Dumas')]
lesTypes = (str, str)
lsAuteurs = initListStore(lesTypes,liste)
for row in lsAuteurs:
print (row[:])