This commit is contained in:
Stefan Salewski 2020-10-28 13:27:28 +01:00
commit 2b47727c93
3 changed files with 21 additions and 12 deletions

View file

@ -25,7 +25,8 @@ 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. 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. The `combinatorics` module was kindly provided by R. Behrends.
NOTE: We are currently preparing v0.8.3. You may install it with command [black yellow-background]#nimble install gintro@#head#. NOTE: This is finally gintro v0.8.3.
// You may install it with command [black yellow-background]#nimble install gintro@#head#.
This version will have some internal cleanup, which removes the temporary This version 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 Array types. In the past we used that names to indicate array parameters, it was working well, but still
it was ugly using names to indicates data types. So we fixed that. And we have added some better support for it was ugly using names to indicates data types. So we fixed that. And we have added some better support for
@ -37,7 +38,15 @@ into two units called gimplgobj.nim and gimplgtk.nim, and we added a module call
which can be imported to make the connect() macro available while a real gtk module is not available. which can be imported to make the connect() macro available while a real gtk module is not available.
Please let us know if these changes should break something for ordinary gtk users. Please let us know if these changes should break something for ordinary gtk users.
To test libnice we added the sdp_example.nim converted from To test libnice we added the sdp_example.nim converted from
a C example, it seems to compile and run. And finally with v0.8.3 the examples from the GTK4 book should work. a C example, it seems to compile and run. But we have not tested real communication between
different computers yet, and not tested it on windows at all. If you have a use case for libnice you may test it yourself,
possible issues may Nim's string vs seq[uint8] vs plain ptr char, or the uint data types in C example which we replaced
by plain int as used in Nim prefereable. Debugging should be not hard, if you do not manage it yourself then you may
open a github issue. Version v0.8.3 uses also some more light entities like gtk.TextIter or glib.Mutex, that are entities
which are generally allocated on the stack and are only initialized to plain binary zero. For these types no
proxy symbols are needed. Unfortunately discovering these entities by use of gobject-introspection works
not reliable, so we are using a manually created list, which may contain errors.
And finally with v0.8.3 the examples from the GTK4 book (http://ssalewski.de/gtkprogramming.html) should work.
For the GTK3 examples we had to do some minimal fixes, so you may have to do similar fixes for your own code as well. For the GTK3 examples we had to do some minimal fixes, so you may have to do similar fixes for your own code as well.
For gintro/examples/gtk3 this was For gintro/examples/gtk3 this was
@ -80,8 +89,8 @@ diff gintronew/examples/gtk3/overlay_tree1.nim gintro/examples/gtk3/overlay_tree
> let store = newListStore(Columns, cast[pointer](unsafeaddr h)) # cast is ugly, we should fix it in bindings. > let store = newListStore(Columns, cast[pointer](unsafeaddr h)) # cast is ugly, we should fix it in bindings.
---- ----
NOTE: This is version 0.8.2 of gintro. It is only a fix for recent gstreamer 1.18 which added some uncommon NOTE: Version 0.8.2 of gintro was only a fix for recent gstreamer 1.18 which added some uncommon
gobject-introspection stuff which brook the install of 0.8.1 for a few users. We where not yet able to gobject-introspection stuff which brook the install of 0.8.1 for a few users. We were not yet able to
verify that the gst example which is bases on the gst C tutorial1 works with gstreamer 1.18. verify that the gst example which is bases on the gst C tutorial1 works with gstreamer 1.18.
NOTE: For version 0.8.1 of gintro, requested by FedericoCeratto, we have added libhandy support. NOTE: For version 0.8.1 of gintro, requested by FedericoCeratto, we have added libhandy support.

View file

@ -9,7 +9,6 @@
# ./sdp-example 0 $(host -4 -t A stun.stunprotocol.org | awk '{ print $4 }') # ./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 }') # ./sdp-example 1 $(host -4 -t A stun.stunprotocol.org | awk '{ print $4 }')
# https://forum.nim-lang.org/t/3752 # https://forum.nim-lang.org/t/3752
when (compiles do: import gintro/gtk): when (compiles do: import gintro/gtk):
import gintro/[gtk, glib, gobject, gio, nice] import gintro/[gtk, glib, gobject, gio, nice]
@ -85,7 +84,7 @@ proc cbComponentStateChanged(agent: nice.Agent; streamID: int; componentID: int;
# this has to be a low level function! # this has to be a low level function!
# AgentRecvFunc* = proc (agent: ptr Agent00; streamId: uint32; componentId: uint32; len: uint32; # AgentRecvFunc* = proc (agent: ptr Agent00; streamId: uint32; componentId: uint32; len: uint32;
# buf: cstring; userData: pointer) {.cdecl.} # buf: cstring; userData: pointer) {.cdecl.}
proc cbNiceRecv(agent: ptr nice.Agent00; streamID: uint32; componentID: uint32; len: uint32; buf: cstring; userData: pointer) {.cdecl.} = proc cbNiceRecv(agent: ptr nice.Agent00; streamID: cuint; componentID: cuint; len: cuint; buf: cstring; userData: pointer) {.cdecl.} =
if len == 1 and buf[0] == '\x00': if len == 1 and buf[0] == '\x00':
glib.quit(gloop) glib.quit(gloop)
discard stdout.writeBuffer(buf, len) discard stdout.writeBuffer(buf, len)
@ -105,8 +104,8 @@ proc exampleThread(data: pointer): pointer {.cdecl.} =
ioStdin = win32NewFd(system.stdin.getFileHandle) ioStdin = win32NewFd(system.stdin.getFileHandle)
else: else:
ioStdin = unixNew(system.stdin.getFileHandle) ioStdin = unixNew(system.stdin.getFileHandle)
discard setFlags(ioStdin, glib.IOFlags.nonBlock) # not implemented for windows? But it is used in C code!
discard setFlags(ioStdin, glib.IOFlags.nonBlock)
# Create the nice agent # Create the nice agent
agent = nice.newAgent(glib.getContext(gloop), nice.CompatibilityRfc5245) agent = nice.newAgent(glib.getContext(gloop), nice.CompatibilityRfc5245)
if agent == nil: if agent == nil:
@ -143,7 +142,8 @@ proc exampleThread(data: pointer): pointer {.cdecl.} =
stdout.write("Generated SDP from agent :\n$1\n\n" % [sdp]) stdout.write("Generated SDP from agent :\n$1\n\n" % [sdp])
stdout.write("Copy the following line to remote client:\n") stdout.write("Copy the following line to remote client:\n")
sdp64 = base64Encode(sdp) sdp64 = base64Encode(sdp)
stdout.write("\n $1\n", sdp64) #stdout.write("\n $1\n" % [sdp64])
stdout.write("\n ", sdp64, "\n")
# Listen on stdin for the remote candidate list # Listen on stdin for the remote candidate list
stdout.write("Enter remote data (single line, no wrapping):\n") stdout.write("Enter remote data (single line, no wrapping):\n")
stdout.write("> ") stdout.write("> ")
@ -159,7 +159,7 @@ proc exampleThread(data: pointer): pointer {.cdecl.} =
if sdp.len > 0 and parseRemoteSdp(agent, sdp) > 0: if sdp.len > 0 and parseRemoteSdp(agent, sdp) > 0:
break break
else: else:
write(stderr, "ERROR: failed to parse remote data\n") write(stderr, "ERROR: failed to parse remote data\n") # here we may get an error -- we have to debug!
write(stdout, "Enter remote data (single line, no wrapping):\n") write(stdout, "Enter remote data (single line, no wrapping):\n")
stdout.write("> ") stdout.write("> ")
flushFile(stdout) flushFile(stdout)

View file

@ -1,6 +1,6 @@
# High level gobject-introspection based GTK3/GTK4 bindings for the Nim programming language # High level gobject-introspection based GTK3/GTK4 bindings for the Nim programming language
# nimpretty --maxLineLen:130 gen.nim # nimpretty --maxLineLen:130 gen.nim
# v 0.8.3 2020-OCT-26 # v 0.8.3 2020-OCT-28
# (c) S. Salewski 2018 # (c) S. Salewski 2018
# usefull for finding death code: # usefull for finding death code:
@ -2713,7 +2713,7 @@ proc attachRecv*(self: Agent; streamID: int; componentID: int; ctx: MainContext;
const GLib_EPI = """ const GLib_EPI = """
when not defined(g_thread_new): when not declared(g_thread_new):
proc g_thread_new(name: cstring; fn: ThreadFunc; data:pointer): ptr Thread00 {.importc, libprag.} proc g_thread_new(name: cstring; fn: ThreadFunc; data:pointer): ptr Thread00 {.importc, libprag.}
proc newThread*(name: string; fn: ThreadFunc; data:pointer): Thread = proc newThread*(name: string; fn: ThreadFunc; data:pointer): Thread =
@ -3455,7 +3455,7 @@ launch()
# if not xcallerAlloc.contains(el): # if not xcallerAlloc.contains(el):
# echo el # echo el
# 3453 lines include # 3453 lines defined
# troubles: gTypeFundamental(gRegisteredTypeInfoGetGType(info)) == G_TYPE_BOXED: # troubles: gTypeFundamental(gRegisteredTypeInfoGetGType(info)) == G_TYPE_BOXED:
#[ #[