I'm building a GUI with GTK-3 in Python using Glade. There is also a ListStore with its columns defined in the Glade file. Now I want to fill the ListStore with numeric values (there are int & float columns) that I receive as strings, so I need to convert them according to the column types.
I would like to use the column types as defined in the ListStore object for the conversion instead of a hardcoded list to maintain the column types only once (preferably in the Glade file) and to keep this part modular for other similar ListStores that will be added later. Unfortunately, the column types I get out of the ListStore by calling TreeModel.get_column_type(index_)
are GObject.GTypes
and I've no idea how to create an appropriate value using the GType or get the related Python type from it.
I already tried to play around with a gint
type object and the GObject.GType
class in the interactive Python shell and read through the online docu, but everything without getting a clue to solve my problem. Also creating a GObject.Value
of type gint
from a string like "123"
or transform()
a gchararray
value into a gint
one didn't work.
How can I convert my strings into the proper numeric type based on a GType? Is it actually achievable what I want to do or do I need a different approach? I could use some static mapping of GTypes to Pyhton types instead, but if I just miss something about the GType system I would like to understand it.