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

Is there way to get GType from GObject / Widget #152

Open
gavr123456789 opened this issue Jul 14, 2021 · 4 comments
Open

Is there way to get GType from GObject / Widget #152

gavr123456789 opened this issue Jul 14, 2021 · 4 comments

Comments

@gavr123456789
Copy link

Im remaking this example, and cant find a method for get type from Widget, like was donw on this line:
https://github.com/aeldemery/simple-drag-n-drop/blob/main/sources/MainWindow.vala#L84

https://valadoc.org/gobject-2.0/GLib.Object.get_type.html
Looks like this bind vala to C G_TYPE_FROM_INSTANCE

@StefanSalewski
Copy link
Owner

From the Vala docs we learn that get_type() is related to

https://developer.gnome.org/gobject/stable/gobject-Type-Information.html#G-TYPE-FROM-INSTANCE:CAPS

which should only be used in type implementations.

But we have

grep "g_type_check_instance_is_a\*" ~/.nimble/pkgs/gintro-#head/gintro/*
/home/salewski/.nimble/pkgs/gintro-#head/gintro/gobject.nim:proc g_type_check_instance_is_a*(instance: ptr TypeInstance00; ifaceType: GType): gboolean {.

what may do what you need.

Generally we should be a bit careful porting Vala examples, as Vala code may be not of highest quality. May be fine for tiny examples, but for larger ones we may get code which is not 100% correct. The aeldemery examples may be nice, but he told me that he is a german doctor, not a professional programmer. Personally I use mostly C examples from gtk4-demo and from gtk/tests.

Have you seen the ugly GIR file bugs from https://gitlab.gnome.org/GNOME/gtk/-/issues/4097

That is really ugly as it may takes years until all people have the fixed version. I may have to fix that manually somehow.

@gavr123456789
Copy link
Author

The aeldemery examples may be nice, but he told me that he is a german doctor, not a professional programmer

He translates C examples from gtk4 demo to Vala, so I think they correct.
As you can see with DnD example https://github.com/aeldemery/gtk4_dnd/
image

Screen from C demo:
image

https://gitlab.gnome.org/GNOME/gtk/-/blob/master/demos/gtk-demo/dnd.c

@gavr123456789
Copy link
Author

gavr123456789 commented Jul 20, 2021

@StefanSalewski

g_type_check_instance_is_a what may do what you need

I need GType to create Gtk. Expression #144
Which I need to sort files in my file browser app.

Here Vala example
https://github.com/aeldemery/gtk4_list_colors/blob/master/sources/ColorGridWidget.vala#L66

Here my start code of doing this, but I need to get GType of FileInfo to create expression.

import gintro/[gio, glib, gtk4, gobject]

let
    file = gio.newGFileForPath(".")
    dl = gtk4.newDirectoryList("standard::name", file)
    sortListModel = newSortListModel(listModel(dl))
    listModel = sortListModel.listModel()
    expression = newPropertyExpression()
    strSorter = newStringSorter(expression)

sortListModel.sorter = strSorter

let x = cast[gio.FileInfo](listModel.getItem(0))
echo x.name

@gavr123456789
Copy link
Author

So far, I can use the typeFromName function

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

2 participants