-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I find names of GTypes -- I need the name for typeFromName() to get the GType #58
Comments
Starting with gintro v0.6.0 we have the get_type() functions available as well as we can use (g)typeFromeName(). The funny fact of the g_type_from_name() is, that it do not register the GTypes, so it does generally not work for GtkSourceView types before the corresponding get_type() function is called. So we try to provide all needed get_type() functions, which is not that easy at all. g_float_get_type() for example is not provided by GTK, maybe because gfloat is a basic type and C programmers use macros generally like G_TYPE_FLOAT. So we defined our get_type ourself, for gfloat by referring g_type_from_name("gfloat"). So generally all needed get_type() functions should be available now. typeFromName() can be used for most types, but may return 0 as long as corresponding get_type() has not been used. This behaviour is a bit strange indeed, it has been confirmed by one of the GTK maintainers for the GTK lib. listview.nim contains example use for typeFromName() as well as g_string_get_type(). This issue was about some strange GTK type names which can be hard to guess. Here is an extended C program which prints the type names of basic GTK types: ```// gcc -o t t.c `pkg-config --libs --cflags gtk+-3.0`
#include <gtk/gtk.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
// basic types
printf("%s: %s\n", "G_TYPE_INVALID", g_type_name(G_TYPE_INVALID));
printf("%s: %s\n", "G_TYPE_NONE", g_type_name(G_TYPE_NONE));
printf("%s: %s\n", "G_TYPE_NONE", g_type_name(G_TYPE_NONE));
printf("%s: %s\n", "G_TYPE_INTERFACE", g_type_name(G_TYPE_INTERFACE));
printf("%s: %s\n", "G_TYPE_CHAR", g_type_name(G_TYPE_CHAR));
printf("%s: %s\n", "G_TYPE_UCHAR", g_type_name(G_TYPE_UCHAR));
printf("%s: %s\n", "G_TYPE_BOOLEAN", g_type_name(G_TYPE_BOOLEAN));
printf("%s: %s\n", "G_TYPE_INT", g_type_name(G_TYPE_INT));
printf("%s: %s\n", "G_TYPE_UINT", g_type_name(G_TYPE_UINT));
printf("%s: %s\n", "G_TYPE_LONG", g_type_name(G_TYPE_LONG));
printf("%s: %s\n", "G_TYPE_ULONG", g_type_name(G_TYPE_ULONG));
printf("%s: %s\n", "G_TYPE_INT64", g_type_name(G_TYPE_INT64));
printf("%s: %s\n", "G_TYPE_UINT64", g_type_name(G_TYPE_UINT64));
printf("%s: %s\n", "G_TYPE_ENUM", g_type_name(G_TYPE_ENUM));
printf("%s: %s\n", "G_TYPE_FLAGS", g_type_name(G_TYPE_FLAGS));
printf("%s: %s\n", "G_TYPE_FLOAT", g_type_name(G_TYPE_FLOAT));
printf("%s: %s\n", "G_TYPE_DOUBLE", g_type_name(G_TYPE_DOUBLE));
printf("%s: %s\n", "G_TYPE_STRING", g_type_name(G_TYPE_STRING));
printf("%s: %s\n", "G_TYPE_POINTER", g_type_name(G_TYPE_POINTER));
printf("%s: %s\n", "G_TYPE_BOXED", g_type_name(G_TYPE_BOXED));
printf("%s: %s\n", "G_TYPE_PARAM", g_type_name(G_TYPE_PARAM));
printf("%s: %s\n", "G_TYPE_OBJECT", g_type_name(G_TYPE_OBJECT));
printf("%s: %s\n", "G_TYPE_GTYPE", g_type_name(G_TYPE_GTYPE));
printf("%s: %s\n", "G_TYPE_VARIANT", g_type_name(G_TYPE_VARIANT));
printf("%s: %s\n", "G_TYPE_CHECKSUM", g_type_name(G_TYPE_CHECKSUM));
printf("%s: %s (%ld)\n", "G_TYPE_CHECKSUM", g_type_name(G_TYPE_CHECKSUM), g_type_from_name(g_type_name(G_TYPE_CHECKSUM)));
// other types
printf("%s: %s\n", "G_TYPE_SOURCE", g_type_name(G_TYPE_SOURCE));
return 0;
}
Output is G_TYPE_INVALID: (null)
|
It seems that there is no complete list of GType names available, and some names are really hard to guess. We can use this C program which prints the names when we give the well known GTYPE C macro. Insert the desired GTYPE macro as G_TYPE_STRING, and compile and run the program.
Reference: https://mail.gnome.org/archives/gtk-list/2017-September/msg00137.html
The text was updated successfully, but these errors were encountered: