Is there a document anywhere relating the gtk2.nim identifiers to the original C gtk2, gdk2, glib2 identifiers?
I am trying to work my way through the Krause book "Foundations of GTK+ Development" but using nim instead of C.
I have got through a simple window program (Listing 2.2). Then I tried to examine the event->type value of a GdkEvent* sent by a "delete_event" signal connection by printing:
cast[PEventAny](event).`type`
and I get 0. Supposedly this is GDK_DELETE - but I cannot seem to find that identifier (even in the importc pragmas) - much less any of the other defined GDK constants.
HELP !
As you may know I am more familiar with GTK3. But I have the old Krause book somewhere -- can look at that listing tonight.
I had similar problems with GTK2 in early Nim days -- looking at Aporia source code can help. For GTK3 I tried hard to get the wrapper files clean and well sorted, so it is not that difficult to find symbols. For GTK2 I have to do some (re)-search. Of course you should try hard to avoid casts in your own code.
I guess you do not intent to do serious work with GTK? Do you know that other, maybe more popular GUI toolkits are already available? That includes wxWidgets, QML, XNim.
OK, found the book and hacked together the Nim code for GTK3.
import gtk3, gdk3, glib, gobject
proc destroy(widget: Widget, data: gpointer) {.cdecl.} = main_quit()
proc delete_event(widget: Widget, event: gdk3.Event; data: gpointer): bool {.cdecl.} = false
proc main =
var window = window_new()
window.title = "Hello World!"
window.border_width = 10
window.set_size_request(200, 100)
discard g_signal_connect(window, "destroy", g_callback(test.destroy), nil)
discard g_signal_connect(window, "delete_event", g_callback(test.delete_event), nil)
var label = label_new("Hello World")
label.selectable = true
window.add(label)
window.show_all
gtk3.init_with_argv()
main()
gtk3.main()
Can currently not test with GTK2, because I have it not installed. Generally it should be very similar for GTK2, but you may still need these P and T prefixes for Types? And I think in the past they used the term nimrod_init instead of gtk3.init_with_argv(). I can see the GTK2 code only at github currently, and that does not work very well. If you really should intend to continue with GTK and need more help, then let me know, I may download the GTK2.nim file and search for symbols.
[EDIT]
Ah, forgot your question for delete event: Well, in gdk3.nim we seach for term Event, find the area with all the event stuff..
And now we may replace the callback with this code:
proc delete_event(widget: Widget, event: gdk3.Event; data: gpointer): bool {.cdecl.} =
assert event.`type` == gdk3.EventType.DELETE
echo event.`type`
false
Prints "DELETE" in my terminal when I close the window, so I guess it is OK. For the GTK2 some more search effort may be necessary unfortunately. Try to search for a more unique event name like FOCUS_CHANGE, maybe without underscore and maybe in downcase. Delete event enum should be defined at the same location. There is a Nim grep tool available which can better handle Nim symbols, you may try that.
Trying to find the gtk2.nim equivalent to gtk3.EventType.DELETE is exactly my problem.
I don't like casts either, but did not see how gdk2 was going to let me access the Event subclass fields without casting to the subclass pointer.
Is gtk2 dead for nim at this point? And if so, is there an officially supported gtk3 module?
WxWidgets would be perfect (cross platform) for my needs - except the client base will dislike installing it - and it has a pretty big footprint.
FLTK would be small enough, but I cannot find a way to do preferredsize/naturalsize for its widgets so as to implement layout managers. Fixed pixel layout is NOT cross platform.
IUP is also nicely small, but I have not yet been able to implement the layout manager I want.
Oh, Well. Thanks for your effort (No - do not dig through your old gtk2 stuff)
Is gtk2 dead for nim at this point?
As you may know Dominik used gtk2 for Aporia -- I think he is busy now with university and his book. I do know no other Nim users, and only very few people interested in old GTK2 at all.
>And if so, is there an officially supported gtk3 module?
What support do you need? Generally I do support GTK3, it is available for 3.15.x since a year now, with only few bugs. I think for making the 3.20 version the estimated effort was 150 hours, so I think I will make that when I need it or when I see that some other people are seriously interested in it. For the GC support, I think I will wait until delegates or something similar is available.