diff --git a/LICENSE b/LICENSE index bf01845..bc9f32f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 StefanSalewski +Copyright (c) 2017, 2018, 2019, 2020, 2021 StefanSalewski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.adoc b/README.adoc index 95d3ee1..9b94805 100644 --- a/README.adoc +++ b/README.adoc @@ -25,11 +25,12 @@ with code inserted from files directly. NOTE: This work is partly based on earlier works of J. Mansour and has been supported by A. Rumpf, E. Bassi and other _Nim_ and _GTK/Gnome_ developers. The `combinatorics` module was kindly provided by R. Behrends. -NOTE: We are currently preparing gintro v0.8.4. -You may install it with command [black yellow-background]#nimble install gintro@#head#. -We now try to support optional var out parameters, see https://github.com/StefanSalewski/gintro/issues/102 -and tried to fix https://github.com/StefanSalewski/gintro/issues/99. And GtkGestures should work now, thanks -to some hints of Mr. Bassi, see https://discourse.gnome.org/t/gtk4-gtkgesture-and-ref-count/4809. +NOTE: This is version 0.8.4 of the gintro Nim GTK bindings. We do support the +libnice module now for Linux and Windows. And we added gtksourceview5 to +support gtksourceview usage for GTK4. The module is called gtksourceview5 +because the underlying C library has mayor version 5 already. So you can +write your own GTK4 Nim editor now. Additional optional var out parameters +are supported now and GtkGestures should work also. NOTE: The version gintro v0.8.3 will have some internal cleanup, which removes the temporary Array types. In the past we used that names to indicate array parameters, it was working well, but still diff --git a/examples/gtk3/libnice_simple_test.nim b/examples/gtk3/libnice_simple_test.nim index 3bd1652..2c6bca4 100644 --- a/examples/gtk3/libnice_simple_test.nim +++ b/examples/gtk3/libnice_simple_test.nim @@ -1,3 +1,6 @@ +## This test program was kindly provided by Mr. Tomohiro, see +## https://github.com/StefanSalewski/gintro/issues/99 + # nim c libnice_simple_test.nim # # Test code for libnice. @@ -98,7 +101,7 @@ proc cbNiceRecv(agent: nice.Agent; streamID: cuint; componentID: cuint; len: cui proc main = gio.networkingInit() - + gloop = newMainLoop(nil, false) lagent = nice.newAgent(glib.getContext(gloop), nice.CompatibilityRfc5245) diff --git a/examples/gtk3/makeAll b/examples/gtk3/makeAll index 476dee0..394070b 100644 --- a/examples/gtk3/makeAll +++ b/examples/gtk3/makeAll @@ -16,10 +16,12 @@ nim c gsettings.nim nim c gstBasicTutorial1.nim nim c handy.nim nim c label.nim +nim c libnice_simple_test.nim nim c listview.nim nim c menubar.nim nim c overlay_tree1.nim nim c simpledrawingarea.nim +nim c simple_example.nim nim c spinbutton.nim nim c sourceview_test.nim nim c t0.nim diff --git a/examples/gtk3/makeAllArc b/examples/gtk3/makeAllArc index d7bdddd..40519f9 100644 --- a/examples/gtk3/makeAllArc +++ b/examples/gtk3/makeAllArc @@ -16,10 +16,12 @@ nim c --gc:arc gsettings.nim nim c --gc:arc gstBasicTutorial1.nim nim c --gc:arc handy.nim nim c --gc:arc label.nim +nim c --gc:arc libnice_simple_test.nim nim c --gc:arc listview.nim nim c --gc:arc menubar.nim nim c --gc:arc overlay_tree1.nim nim c --gc:arc simpledrawingarea.nim +nim c --gc:arc simple_example.nim nim c --gc:arc spinbutton.nim nim c --gc:arc sourceview_test.nim nim c --gc:arc t0.nim diff --git a/examples/gtk3/sdp_example.nim b/examples/gtk3/sdp_example.nim index a2d09f1..4a7aa9d 100644 --- a/examples/gtk3/sdp_example.nim +++ b/examples/gtk3/sdp_example.nim @@ -9,6 +9,8 @@ # ./sdp-example 0 $(host -4 -t A stun.stunprotocol.org | awk '{ print $4 }') # ./sdp-example 1 $(host -4 -t A stun.stunprotocol.org | awk '{ print $4 }') +## This is a legacy Nim libnice example. Deprecated, we may remove it, or improve the code... + # https://forum.nim-lang.org/t/3752 when (compiles do: import gintro/gtk): import gintro/[gtk, glib, gobject, gio, nice] diff --git a/examples/gtk3/simple_example.nim b/examples/gtk3/simple_example.nim index a16340b..29f94b2 100644 --- a/examples/gtk3/simple_example.nim +++ b/examples/gtk3/simple_example.nim @@ -8,8 +8,15 @@ ## simple-example 0 $(host -4 -t A stun.stunprotocol.org | awk '{ print $4 }') ## simple-example 1 $(host -4 -t A stun.stunprotocol.org | awk '{ print $4 }') ## +## this code contains the fixes of Mr. Tomohiro for Windows OS, see https://github.com/StefanSalewski/gintro/issues/99 +## The construct "when (compiles do: import ..." is fragile -- we let it in for now +## to support windows OS without a full gtk version available. +## Of course we could use dummygtk always and avoid that construct. +## We may improse the situation later somehow... +# https://github.com/nim-lang/Nim/issues/16287 # https://forum.nim-lang.org/t/3752 +# when (compiles do: import gintro/gtk): import gintro/[gtk, glib, gobject, gio, nice] else: @@ -190,7 +197,7 @@ proc cbCandidateGatheringDone(agent: nice.Agent; streamId: int) = echo("") ## Listen on stdin for the remote candidate list echo("Enter remote data (single line, no wrapping):") - discard addWatch(ioStdin, glib.PRIORITY_DEFAULT, {IOCFlag.`in`} , stdinRemoteInfoCb, agent) + discard addWatch(ioStdin, glib.PRIORITY_DEFAULT, {IOCFlag.`in`}, stdinRemoteInfoCb, agent) stdout.write("> ") flushFile(stdout) @@ -223,7 +230,7 @@ proc cbComponentStateChanged(agent: nice.Agent; streamId: int; componentId: int; echo(" [$1]:$2)" % [$ipaddr, $getPort(remote.impl.`addr`)]) ## Listen to stdin and send data written to it echo("\nSend lines to remote (Ctrl-D to quit):") - discard addWatch(ioStdin, glib.PRIORITY_DEFAULT, {IOCFlag.`in`} , stdinSendDataCb, agent) + discard addWatch(ioStdin, glib.PRIORITY_DEFAULT, {IOCFlag.`in`}, stdinSendDataCb, agent) stdout.write("> ") flushFile(stdout) elif state == ComponentState.failed.ord: diff --git a/examples/gtk3/spinbutton.nim b/examples/gtk3/spinbutton.nim index 95bf9c8..c7b8db0 100644 --- a/examples/gtk3/spinbutton.nim +++ b/examples/gtk3/spinbutton.nim @@ -16,7 +16,7 @@ proc prepareWindowForOrientation(orientation: gtk.Orientation) = discard connect(window, "delete_event", onDeleteEvent) let mainbox = gtk.newBox(if orientation == gtk.Orientation.horizontal: Orientation.vertical else: Orientation.horizontal, 2) window.add(mainbox) - let wrapButton = newToggleButtonWithLabel("Wrap") + let wrapButton = newToggleButton("Wrap") mainbox.add(wrapButton) var max = 0 while max <= 999999999: diff --git a/examples/gtk4/headerbar.nim b/examples/gtk4/headerbar.nim index d617d97..a8e1d82 100644 --- a/examples/gtk4/headerbar.nim +++ b/examples/gtk4/headerbar.nim @@ -118,7 +118,7 @@ proc main = box.append(content) let footer = newActionBar() footer.setCenterWidget(newCheckButton("Middle")) - let button = newToggleButtonWithLabel("Custom") + let button = newToggleButton("Custom") button.connect("clicked", changeHeader, window) footer.packStart(button) #var button1 = newButton("Subtitle") diff --git a/tests/gen.nim b/tests/gen.nim index ab07008..9717dac 100644 --- a/tests/gen.nim +++ b/tests/gen.nim @@ -1,6 +1,6 @@ # High level gobject-introspection based GTK3/GTK4 bindings for the Nim programming language # nimpretty --maxLineLen:130 gen.nim -# v 0.8.4 2020-DEC-06 +# v 0.8.4 2020-DEC-14 # (c) S. Salewski 2018 # usefull for finding death code: @@ -207,6 +207,8 @@ var suppressRaise = false fixedProcNames["gtk_button_new_with_label"] = "newButton" fixedProcNames["gtk_check_button_new_with_label"] = "newCheckButton" +fixedProcNames["gtk_toggle_button_new_with_label"] = "newToggleButton" +fixedProcNames["gtk_link_button_new_with_label"] = "newLinkButton" fixedProcNames["pango_font_description_from_string"] = "newFontDescription" fixedProcNames["pango_language_from_string"] = "languageFromString" @@ -1058,7 +1060,11 @@ proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; ge (h1, h2, h3) = hhh.split if name == h1 and str == h2: str.add(" = " & h3) - if genProxy and (str == "string" or str == "cstring") and mayBeNil and sym != "gtk_check_button_new_with_label": + + if genProxy and (str == "string" or str == "cstring") and mayBeNil and not sym.contains("_button_new_with_label"): + + + #if genProxy and (str == "string" or str == "cstring") and mayBeNil and sym != "gtk_check_button_new_with_label": str.add(" = \"\"") if genProxy and m == 0: if sym.contains("_set_") and str == "bool": @@ -2975,6 +2981,23 @@ proc mainQuit*(w: Window) = mainQuit() """ +const GTK4_EPI = """ + +proc getRootWidget*(self: Widget): Widget = + let h = self.getRoot + assert(toBool(g_type_check_instance_is_a(cast[ptr TypeInstance00](h.impl), gtk_widget_get_type()))) + #g_type_check_instance_is_a(cast[ptr TypeInstance00](result.impl), gt))) + cast[Widget](h) + +""" + +const GDK4_EPI = """ + +proc getPosition*(self: Event): (float, float) = + assert toBool(gdk_event_get_position(cast[ptr Event00](self.impl), result[0].float, result[1].float)) + +""" + const GTK_EPI = """ #proc loadFromData*(self: CssProvider; data: cstring): bool = @@ -3526,6 +3549,7 @@ proc init* = output.write("include gimplgobj\n") output.write("include gimplgtk\n") else: + output.write(GTK4_EPI) output.write("include gisup4\n") output.write("include gimplgobj\n") output.write("include gimplgtk\n") @@ -3613,6 +3637,9 @@ proc get$1*(builder: Builder; name: string): $1 = if ISGTK3: output.write(GDK3_EPI.replace("SomeEvent", "Event")) output.write(GDK_EPI.replace("SomeEvent", "Event")) + if not ISGTK3: + output.write(GDK4_EPI) + if namespace == "GtkSource": output.write(GTK_SOURCE_EPI % fixedModName("gtksource")) output.flush