GNOME Bugzilla – Bug 646536
Cannot install Gtk.Widget style properties
Last modified: 2018-01-10 20:07:36 UTC
I used gtk.widget_class_install_style_property in my app before, and trying to simply replace that with Gtk.WidgetClass.install_style_property does not seem effective, I get the error message: TypeError: unbound method install_style_property() must be called with WidgetClass instance as first argument (got GObjectMeta instance instead) Is this a libgtk2 but or a pygobject bug? I need to be able to pass the (Python) subclass of Gtk.Bin into install_style_property. Is there a different preferred method to add style properties that can be used as a workaround? thank you.
I'm not sure about style properties but we don't support Gtk2, only Gtk3 for introspection. PyGtk is still the preferred way to write Gtk2 apps. If there is an issue with style properties in Gtk3, that does need to be fixed.
Ok, a question then from someone who has not fit the whole of GTK and PyGTK into the brain yet, even though I've used it a lot. What's the easiest way forward to port my application (Kupfer). I've "translated" it whole, reported bugs on missing annotations and what I can see only the style properties are missing for it to run under pygi. Frankly, I didn't know if it was using gtk3 or gtk2 :-) Anyway, is there a good path for porting? So porting to "gtk2 over introspection" doesn't exist as an option? thanks.
We don't recommend porting to introspection if you will continue to use GTK+-2.0. The overrides and codepaths for GTK-3.0 are not as well tested and likely more buggy. You should explicity require a GTK version using import gi gi.require_version("Gtk", "3.0") I can't answer the rest of your question confidently i'm afraid. Theming changed in GTK+-3.0 a lot, and you might be hitting some of that transition here. I really like the new kupfer UI, but I fear it might need to be re-implemented using the new CSS theming....
(I was porting against gir1.2-gtk-2.0 + pygobject 2.28 + libgtk 2.24.3 packages from Debian's experimental) Thank you for the straight information. I'm seeing the introspection data being prepared in Debian, and yet it is suggested here that it will never be really useful for GTK 2. For me, I think the porting will simply have to begin at a later time then, going straight to GTK 3. Nice that you like the new kupfer :-) I don't think its a too big undertaking to eventually port the style properties etc.
Yes, we should stop building Gtk2 girs by default. There is nothing saying someone won't come along and fix the issues but I don't think it will ever be 100%. There is just too much legacy code that is not wrappable.
> GTK+-2.0. The overrides and codepaths for GTK-3.0 are not as well tested and > likely more buggy. You should explicity require a GTK version using Bah, of course I meant GTK-2.0 here.
Ok, so after some more porting work... I'm porting to Gtk3 instead. After finishing up all my merge conflicts, I feel like I was fooled here, because this same bug happens with Gtk3. TypeError: unbound method install_style_property() must be called with WidgetClass instance as first argument (got GObjectMeta instance instead) GTK 3.0.8 pygobject 2.28.3
(In reply to comment #7) > Ok, so after some more porting work... I'm porting to Gtk3 instead. > > After finishing up all my merge conflicts, I feel like I was fooled here, > because this same bug happens with Gtk3. > > TypeError: unbound method install_style_property() must be called with > WidgetClass instance as first argument (got GObjectMeta instance instead) > > GTK 3.0.8 > pygobject 2.28.3 AFIAK, install_style_property and StyleProperty is the gtk+-2 API (depreciated in favour of the css based stylecontext) With gtk+-3 theming went to GtkStyleContext and properties via css are installed using gtk_style_properties_new() (of course the pygobject version) and installed with gtk_style_properties_register() Glad to hear you are porting to gtk+-3. I just finished the gnome-sudoku port, which used quite a lot of custom widget drawing/cairo/theming/stylecontext API. Feel free to take a look over the commit logs for some inspiration
hmm, on further reflection only about half of what I said may have been true... I still think install_style_property is gtk+-2 API, but looking at the gtk+-3 docs perhaps the equivilent registration of css is done with the theming engine, something like gtk_theming_engine_register in both cases im not sure of the state of this binding in PyGObject (i have not yet ported custom colors on gnome-sudoku)
Thanks for this information. I will look at your port, but I think I will also need to wait for a more mature version and a larger porting guide, right now I'm stuck with my custom GtkBin subclass not being shown/drawn at all. There are also issues such as the 'allocation' object passed to the size-allocate handler is an opaque unusable object (can't access its value).
allocation object should be fine with the latest versions of pygobject. File a bug if not. As for subclassing GtkBin, we need to fix how we handle forall (e.g. we need to implement callable C callbacks when passed into a python callback). I have a proof of concept but we won't support full subclassing like that until PyGObject 3.
Keeping this open, as currently there is no way to produce a WidgetClass instance, and neither a GObject.ParamSpec object using GI.
Now that bug 685218 has landed, Widget.install_style_property() is available, but we still need to unify GObject.ParamSpec (introspection) and gobject.GParamSpec (static bindings). Marking this as depending on bug 685275.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/13.