Seriously, this is so poorly implemented.
I'm having to read the full GTK documentation to understand how PyGTK operates.
It's all about the Graphics Context gtk.gdk.GC.
When you use gc.set_foreground(gdk.Color)
it will only work for an allocated color, which is a color that has a pixel value set (and registered in the colormap). However, the Color that gets set has its rgb fields garbled (don't ask me why).
So, at all times, the gc.foreground
object will have useless rgb fields. You can set them, but it won't do anything and if you read the value back that you just set, it is garbled again.
And the only way to obtain the rgb values (that is, a fully filled-in Color object) is to call gc.get_colormap().query_color(gc.foreground.pixel)
Then, you might as well save the colours you use yourself and not try to depend on the GC for readout or storage. I'm probably best off saving some (gc, color) tuple or even a custom class. It is also not hard to wrap the GC in another class that provides access to its methods.
It is however not possible to subclass gdk.GC properly. You cannot do anything useful with it, the class is written in C and when you try to set a custom attribute for your subclass, the following C code gets executed:PyErr_SetString(PyExc_AttributeError, "could not write attribute");edited before I saw there was a new reply:
And this behaviour is not specific to PyGTK.
Here is a mailing list post from 2003:
gtk-app-devel-list: gdk_gc_get_values returns strange things.
So I am sitting here spending hours discovering useless bugs that no one cares about, not even enough to document it. And I'm having to work my way around anomalies that make no sense and that have been left as they are for at least 11 years. And it takes me hours to realize what is going on, when a few lines of documentation would have made it clear to me in minutes.
I get the impression this is not exactly a brilliant way to spend time. Not for me, but also not for the people doing this. Every minute they save in not writing documentation costs other developers many many manhours combined. People are having to reinvent the wheel over and over and over and over again.
The PyGTK docs are just a subset inclusion of the full GTK docs for associated functions. And since it is a subset, important information is left out for you to discover after you access the full C documentation.
Real fun yes, I've already wasting hours trying to do something that should have worked instantly if people had cared enough.
I get the feeling I won't be around here long...