View previous topic :: View next topic |
Author |
Message |
teales
Joined: 21 May 2007 Posts: 24 Location: Bangalore
|
Posted: Thu Jul 28, 2011 5:37 am Post subject: Strange behavior getting a property from a TextTag |
|
|
I've been trying to add some new methods to ObjectG.d in gtkD. As an example:
public string getString(string propertyName)
{
// void g_object_get(gpointer object, gchar* firstPropertyName, ... )
// gchar* is described as being a C style string
char* csz;
writefln("%s", propertyName);
g_object_get(gObject, cast(char*) std.string.toStringz(propertyName), &csz); // try 1
//g_object_get(gObject, cast(char*) "font\0".ptr, &csz); // try 2
uint n;
for (char* p = csz; *p; p++, n++) {}
return csz[0..n].idup;
}
When I use this in code to get a property from a GtkTextTag I get a warning from Glib-GObject telling me there's no such property, and then the expected result is returned. I've done this several different ways. It works, but with different warning message string values, like:
font
(thost:9068): GLib-GObject-WARNING **: g_object_get_valist: object class `GtkTextTag' has no property named `\xb8;\u001a \u0003'
ArtBrush 12
font
(thost:8524): GLib-GObject-WARNING **: g_object_get_valist: object class `GtkTextTag' has no property named `XO\xdc\u0008\u0003'
ArtBrush 12
This is with DMD2.054. Can anyone hazard a guess as to what's going on here?
Thanks
Steve |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Thu Jul 28, 2011 3:41 pm Post subject: |
|
|
You are missing null as the last param for g_object_get.
g_object_get accepts a vararg which should end with a null. |
|
Back to top |
|
|
teales
Joined: 21 May 2007 Posts: 24 Location: Bangalore
|
Posted: Fri Aug 05, 2011 12:00 am Post subject: |
|
|
Thanks Mike - I noticed that later. Once I had fixed it the warning messages, or at least the attribute name reported just got longer. |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sat Aug 06, 2011 6:33 am Post subject: |
|
|
What are the error messages you are getting now? |
|
Back to top |
|
|
teales
Joined: 21 May 2007 Posts: 24 Location: Bangalore
|
Posted: Sun Aug 28, 2011 4:27 am Post subject: |
|
|
Sorry Mike,
I had missed the terminating null in one case, so your answer was spot on.
For any interested parties, I had done this in the first place because I did not know how to recover the 'foreground-gdk' property for a TextTag. The GTK documentation says this property is of type GdkColor, and I could not figure out what kind of gobject.Value to use. The answer is along the lines:
Value v = new Value();
v.init(Type.fromName("GdkColor"));
textTag.getProperty ("foreground-gdk", v);
GdkColor* p = cast(GdkColor*) v.getBoxed();
It's always easy when you know how ;=)
Steve |
|
Back to top |
|
|
|