I am trying to develop a GTK application in Python, and I am really fixated on using gtk.TreeStore
. My main problem: I already parsed some JSON, and I have my own data structure, which is basically a Python list and two types of objects: One is a collection of elements (collections cannot be nested) and one for representing elements (which may appear in a list as well as in a collection).
I am already familiar with the main uses of TreeStore
and have the opportunity to correctly display elements on the screen. I donβt know how to cope with the fact that the treestore is only able to store gobject types (at the moment Iβm not sure, because I know little about a system like gobject). The documentation for C lists the following (except PixBuf) base types that can be inserted and automatically mapped to Python data types:
As an example, gtk_tree_store_new (3, G_TYPE_INT, G_TYPE_STRING, GDK_TYPE_PIXBUF); will create a new GtkTreeStore with three columns of type int, string and GdkPixbuf respectively.
In addition, it says that you can insert GType
. A link from the documentation directly points to this paragraph:
A numeric value that represents the unique identifier of a registered type.
My research on the topic ends here, and Google finds mostly GTK 2.x tutorials and nothing about inserting data types other than str
and int
, etc.
Questions:
Is it possible to implement a new GType (or any other interface that makes the insertion of user data into the treestore possible) and how to do it?
I already tried to get GObject
, but that didn't help.
How can I get rid of saving two data structures at the same time?
Namely, my analysis result and duplicate information in Treestore.
How can you deal with mixed content?
In my case, I have collections and elements with various additional information (which are reflected in the tree structure as nodes with or without children).
If the above issues are resolved, I also get rid of the problem when processing the choices: it is difficult to match a simple type, for example str
or int
, to match the element that I inserted before. Such an attribute should be the key, and you should still look for a list with analysis results that is inefficient.
Thank you in advance!
Additional information not directly related to the question:
I thought this could be a real task to implement a custom TreeModel
until I read this in a tutorial for GTK 2 :
However, all this is expensive: you are unlikely to write a useful user model in less than a thousand lines if you do not split all the newline characters. Writing a custom model is not as difficult as it might sound, but it can be worth the effort, not least because it will lead to significantly more robust code if you have a lot of tracking data.
Is this still relevant?
I just stumbled upon http://www.pygtk.org/articles/subclassing-gobject/sub-classing-gobject-in-python.htm Could this be helpful? How many resoucres is for PyGTK 2.0. outdated.