Problems with Properties and Notify Signal Parts
- From: Richard Cole <rcole itee uq edu au>
- To: gtk-list <gtk-list gnome org>
- Subject: Problems with Properties and Notify Signal Parts
- Date: Fri, 29 Jul 2005 17:27:15 +1000
Dear Gtkers,
I just spent a day on a problem related to property names and notify
signal parts. Since I solved the problem I thought I'd email it here
incase someone else has the same problem. Maybe they'll find this email.
Let me preface my comments by saying that although I'm quite new to Gtk
I've been quite impressed by the 2.0 code and the very serious attempt
to produce high quality software (clean and regular interfaces, not too
many bugs).
So onto the description of my problem.
I created a widget derived from GtkDrawingArea and added some properties
to it as described in: The Official Gnome 2 Developers Guide by Matthias
Warkus (nice book).
So then, and please excuse my Ruby here as I haven't the heart to type
it out in C.
...
view = LatticeView.new(diagram, attr_names, obj_names)
view.connect_signal("notify::font_size") {
|view, value|
puts("Font Size updated, view=" + view.to_s + ", value=" + value.to_s)
}
view.set_property("font_size", 10)
...
But no dice! The callback attached to notify::font_size was not being
called. Due to a trace statement in my lattice_view_property_set
function I could see that the property was being set. So what is wrong?
Well you see somewhere in glib the property "font_size" is helpfully
changed to "font-size". (The underscore turned into a dash). I guess so
that if one's code says:
view.set_property("font-size", 10)
Then rather than a warning about a non-existent property one will get
what one intended: a change to the font size [1].
However this helpfull modification to property names isn't being
performed for signal details. At least not in: glib-2.6.5 as packaged by
debian. So what happens is the property name is being changed to
font-size and the signal being emitted is "notify::font-size", but the
modification to the signal name from "notify::font_size" to
"notify::font-size" is not being performed.
My guess is that this situation should be fixed so that underscores are
changed to hyphens in each of: property names, signal names, and signal
details. At the moment it seems to be missing on signal details. But
that is a bit of guess.
I think it would also be helpfull to put a note about signal names and
this kind of hidden conversion that goes on behind the scenes into the
description part of
file:///usr/share/doc/libgtk2.0-doc/gobject/gobject-Signals.html
i.e. from whereever that file is being generated.
regards,
Richard.
[1] Going from "font_size" to "font-size" seems a bit like lisp inspired
madness, but it turns out to be quite usefull in the following
situation: some widget writer has defined a property called font-desc
and you want to set it in Ruby (which has nicely automatically wrapped
property names) then you type:
view.font_desc = Pango::FontDescription.new_from_string("Sans 12")
and font_desc gets turned into font-desc and matches the property name.
If there was no conversion from '_' to '-' then you'd be stuck because
font-desc isn't a ruby identifier, it is 3 of them.
PS: Contrary to some statements floating around the web, one does not
need to call g_object_notify(gobject, "font_size"), or even
g_object_notify(gobject, "font-size") from within the
lattice_view_property_set function since the notify signal is
automatically produced by the apparatus in glib. In fact looking at the
code in gobject.c (2.6.5) it looks like you might get the font_size
notification signal twice if you interpose a g_object_notify(gobject,
"other_property") between you font_size notification and the end of the
property_set function. But, well, maybe such a thing is mostly harmless.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]