Skip to content
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

Open
StefanSalewski opened this issue Oct 7, 2019 · 1 comment

Comments

@StefanSalewski
Copy link
Owner

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.

// 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[]) {

  printf("%s\n", g_type_name(G_TYPE_STRING));
  printf("%s\n", g_type_name(G_TYPE_SOURCE));

  return 0;
}

Reference: https://mail.gnome.org/archives/gtk-list/2017-September/msg00137.html

@StefanSalewski
Copy link
Owner Author

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)
G_TYPE_NONE: void
G_TYPE_NONE: void
G_TYPE_INTERFACE: GInterface
G_TYPE_CHAR: gchar
G_TYPE_UCHAR: guchar
G_TYPE_BOOLEAN: gboolean
G_TYPE_INT: gint
G_TYPE_UINT: guint
G_TYPE_LONG: glong
G_TYPE_ULONG: gulong
G_TYPE_INT64: gint64
G_TYPE_UINT64: guint64
G_TYPE_ENUM: GEnum
G_TYPE_FLAGS: GFlags
G_TYPE_FLOAT: gfloat
G_TYPE_DOUBLE: gdouble
G_TYPE_STRING: gchararray
G_TYPE_POINTER: gpointer
G_TYPE_BOXED: GBoxed
G_TYPE_PARAM: GParam
G_TYPE_OBJECT: GObject
G_TYPE_GTYPE: GType
G_TYPE_VARIANT: GVariant
G_TYPE_CHECKSUM: GChecksum (94162924034224)
G_TYPE_SOURCE: GSource

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant