gobbi is a set of generated Go bindings for gtk et al.

gobbi

gobject bindings

Build Status builds.sr.ht status

gobbi is a set of generated Go bindings for gobject based libraries. There are bindings, with varying degrees of completeness, for gtk, gdk, gdkpixbuf, gio, gobject, and glib.

The intention is to provide the bindings required for writing gtk applications. So the focus is on supporting functions in the higher level libraries such as gtk, gdk, gdkpixbuf and gio. Much of the functionality provided by the lower level libraries, such as glib and gobject, is adequately supported in Go core packages.

example use

package main

import (
	"github.com/pekim/gobbi/lib/gtk"
	"os"
	"runtime"
)

func init() {
	runtime.LockOSThread()
}

func main() {
	gtk.Init(os.Args)

	window := gtk.WindowNew(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("A window title")
	window.SetDefaultSize(300, 300)

	window.Widget().ConnectDestroy(func(_ *gtk.Widget) {
		gtk.MainQuit()
	})
	window.Widget().ShowAll()

	gtk.Main()
}
go get github.com/pekim/gobbi
go run -tags "glib_2.48 gdk_3.4 gdkpixbuf_2.32 gio_2.32 gtk_3.18" gobbi-simple.go

documentation

https://pekim.github.io/gobbi/

At a minimum it's probably a good idea to read at least the Getting started and Application lifecycle pages.

code generation

The code that implements most of the APIs is generated from the GObject Introspection (gir) XML files in the internal/gir-files directory. The generation code is in the internal/generate package.

All of the generated API code, and a very small number of manually maintained files, is in the subdirectories of the lib directory.

status

The library should be perfectly servicable and complete enough to build most applications.

Some simple example applications have been created, and may be found in the example directory. It is possible that for more complex applications some necessary apis may be missing.

The API is reasonably stable, although some changes are certainly possible.

The generation code is rather messy in some areas, and needs tidying up. The generated code is simple, and fairly readable.

gotk3

gotk3 is a more mature library than gobbi. It might be a safer choice than gobbi for those who are cautious. However gobbi should work just as well in most cases.

gobbi supports a larger number of apis than gotk3. However gotk3 supports some apis that gobbi does not, and vice versa.

gobbi is more type safe in some areas, notably the callbacks connected to signals.

Owner
Comments
  • main_event_loop.go:55:10: undefined: SOURCE_REMOVE when running

    main_event_loop.go:55:10: undefined: SOURCE_REMOVE when running "Custom Drawing" Example Code

    This is a wonderful project, thank you for investing time into working on this. I'm interested in learning more about GTK and expanding my knowledge so I was experimenting with this and other Go and C GTK software and in my tests I ran into the following error:

    $ go run main.go 
    # github.com/pekim/gobbi/lib/glib
    ../../pekim/gobbi/lib/glib/main_event_loop.go:55:10: undefined: SOURCE_REMOVE
    

    I think this is a simple bug fix, I can submit the pull request to fix it if its not already done locally on your machine.

  • Can not run go get github.com/pekim/gobbi/lib/gtk

    Can not run go get github.com/pekim/gobbi/lib/gtk

    github.com/pekim/gobbi/lib/gio

    ../../go/src/github.com/pekim/gobbi/lib/gio/v-.go:1192:44: undefined: Converter ../../go/src/github.com/pekim/gobbi/lib/gio/v-.go:1197:43: undefined: Initable ../../go/src/github.com/pekim/gobbi/lib/gio/v-.go:1261:66: undefined: Converter ../../go/src/github.com/pekim/gobbi/lib/gio/v-.go:1280:58: undefined: PollableInputStream ../../go/src/github.com/pekim/gobbi/lib/gio/v-.go:1344:68: undefined: Converter ../../go/src/github.com/pekim/gobbi/lib/gio/v-.go:1363:60: undefined: PollableOutputStream ../../go/src/github.com/pekim/gobbi/lib/gio/v-.go:1461:41: undefined: MenuModel ../../go/src/github.com/pekim/gobbi/lib/gio/v-.go:4593:55: undefined: PollableInputStream ../../go/src/github.com/pekim/gobbi/lib/gio/v-.go:4675:57: undefined: PollableOutputStream ../../go/src/github.com/pekim/gobbi/lib/gio/v-.go:6429:51: undefined: ProxyResolver ../../go/src/github.com/pekim/gobbi/lib/gio/v-.go:6429:51: too many errors

    NOt sure what I did wrong ...

  • callback function signatures changed

    callback function signatures changed

    It appears that the "signal" callback function signatures have changed since the last time I played around with gobbi. There appears to be a redundant parameter targetObject introduced, which matches the "C" style non-object oriented API, but should not be necessary since the callbacks are passed to methods on the same targetObject.

    For example in file lib/gtk/v-3.22.29.go

    type WidgetSignalButtonPressEventCallback func(targetObject *Widget, event *gdk.EventButton) bool
    
    func (recv *Widget) ConnectButtonPressEvent(callback WidgetSignalButtonPressEventCallback) int 
    
  • code generation error

    code generation error

    Why do I get this error while compiling the "simple_window" example code in a new project module? Compiles fine when run inside gobbi/example/simple_window

    $ go build -tags "gobject_2.56 glib_2.56 gdk_3.22 gdkpixbuf_2.36 gio_2.56 gtksource_3.24 gtk_3.22"
    # github.com/pekim/gobbi/internal/generate
    ../../../go/pkg/mod/github.com/pekim/[email protected]/internal/generate/namespace-file-generate.go:21:6: file.NoFormat undefined (type *jen.File has no field or method NoFormat)
    
  • go modules: missing gtksource

    go modules: missing gtksource

    gtksource appears to be missing, while using gobbi via go modules.

    cannot load github.com/pekim/gobbi/lib/gtksource: cannot find module providing package github.com/pekim/gobbi/lib/gtksource
    
  • could not determine kind of name for C.g_networking_init

    could not determine kind of name for C.g_networking_init

    simple window example code fails to compile with gtk_3.22 (ubuntu 18.04)

    $ go build -tags "gobject_2.56 glib_2.56 gdk_3.22 gdkpixbuf_2.36 gio_2.56 gtk_3.22" main.go
    # github.com/pekim/gobbi/lib/gio
    ../../../go/pkg/mod/github.com/pekim/[email protected]/lib/gio/function-2.36.go:39:2: could not determine kind of name for C.g_networking_init
    

    Using older versions works fine.

    $ go build -tags "gobject_2.10 glib_2.48 gdk_3.4 gdkpixbuf_2.32 gio_2.32 gtk_3.18" main.go
    

    Good job on the bindings :+1:

  • Support connecting signals for a Builder

    Support connecting signals for a Builder

    There is no means of connecting signal handler functions to named signals in a builder description. This was initially mentioned in #9.

    Use of gtk_builder_connect_signals_full is probably the way to go. gotk3's approach in https://github.com/gotk3/gotk3/pull/9 provides some inspiration.

    Unlike gobbi's normally type-safe approach to connecting signal handlers this is probably going to have to connect the handler functions without regard to type-safety.

  • Builder connect signals

    Builder connect signals

    Add a new ConnectSignals method for gtk.Builder. This addresses #10.

    Documentation can be previewed at https://github.com/pekim/gobbi/blob/builder-connect-signals-2/internal/docs-src/builder-connect-signals.md.

  • Use girepository to invoke library functions

    Use girepository to invoke library functions

    The current generation code is unfortunately an unmaintainable mess. I had no idea when I started writing it how many parameter types and variations there were. Nor did I understand how many of the permutations would need to be handled. As a result I can't see a way to migrate the current code to a better place. I'd normally prefer to iteratively refactor code to improve it, but in this case I don't think that it's practical.

    The generated code is also problematic in that it's very slow to build. This is mostly because of the extensive use of cgo. It's in every wrapping function, and there are many generated C functions for callbacks. This makes development of gobbi painful, with continuous rounds of code generation and slow builds.

    It's difficult to move forward with the code as it is. Issues #16 and #17 are examples of cases where I struggle to work with the existing generation code.

    I am looking at re-writing to use girepository for invocation of library functions.

    Pros

    • the generated functions that wrap library functions will be become simpler, and will not contain any cgo code
    • the code that generates the wrapper functions will be simpler
    • all cgo code will be in one or two internal packages
      • all of the complexity of the multitude of parameter types and variations will be in here
      • all of the marshalling of parameters between Go types and C types will be in here
      • all of code dealing with transfer of ownership will be in here
      • much of the code will be amenable to unit testing
    • building will be much quicker

    Cons

    • there will be a small overhead on function calls
    • unavailabilty of a library function (for example running an application on a system with older than required version of a library) will not be detected until it is first called

    Initial work is proving promising. It will be at least several more weeks before it's in a reasonably useable state.

  • How to extract element from GList

    How to extract element from GList

    I am confused as to how to extract the GtkWidget element held inside the GList returned by gtk_container_get_children(). Any help would be appreciated.

  • redundant code generation

    redundant code generation

    I notice that the binding generation in Gobbi is not incremental for newer versions of the Gtk library. I have not run the code generation tool myself, but it appears to be a lot of work to regenerate the same bindings over and over for different versions.

    While going through the Gotk3 codebase, I found that their binding files are named *_since_<version>.go and only newer API's are found in the newer version file.

    gtk_since_3_22.go
    gtk_since_3_20.go
    

    And the version selection during build is done using Inverted selection.

    // +build gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16,!gtk_3_18,!gtk_3_20
    

    I understand that Gotk3 is manual bindings, but is there anything holding us back from going incremental and lessening the burden during binding generation.

  • nullable string parameters

    nullable string parameters

    Some Gtk functions take string parameters that can be null, such as the one below.

    GtkWidget * gtk_frame_new (const gchar *label);
    

    Creates a new GtkFrame, with optional label label . If label is NULL, the label is omitted.

    In the above case we are unable to omit/disable the label widget, as we are unable to pass NULL to the C function.

    Gobbi's implementation currently does'nt take into account the nullable string parameters.

    func FrameNew(label string) *Frame {
    	c_label := C.CString(label)
    	defer C.free(unsafe.Pointer(c_label))
    
    	retC := C.gtk_frame_new(c_label)
    	retGo := FrameNewFromC(unsafe.Pointer(retC))
    
    	return retGo
    }
    

    The Gotk3 library handles this correctly.

    func FrameNew(label string) (*Frame, error) {
    	var cstr *C.char
    	if label != "" {
    		cstr = C.CString(label)
    		defer C.free(unsafe.Pointer(cstr))
    	}
    	c := C.gtk_frame_new((*C.gchar)(cstr))
    	if c == nil {
    		return nil, nilPtrErr
    	}
    	obj := glib.Take(unsafe.Pointer(c))
    	return wrapFrame(obj), nil
    }
    

    The Gir files do indicate nullable parameters (nullable="1"). So code generation should be possible.

    <parameter name="label"
               transfer-ownership="none"
               nullable="1"
               allow-none="1">
      <doc xml:space="preserve">the text to use as the label of the frame</doc>
      <type name="utf8" c:type="const gchar*"/>
    </parameter>
    

    Would appreciate if you could get this working and a possible workaround if possible until then :)

  • Incompatible with gobject 2.62.4

    Incompatible with gobject 2.62.4

    lib/glib/v-.go:308:46: could not determine kind of name for C.G_KEY_FILE_DESKTOP_KEY_FULLNAME
    lib/glib/v-.go:309:52: could not determine kind of name for C.G_KEY_FILE_DESKTOP_KEY_GETTEXT_DOMAIN
    lib/glib/v-.go:310:46: could not determine kind of name for C.G_KEY_FILE_DESKTOP_KEY_KEYWORDS
    
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

Dec 28, 2022
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

Jan 1, 2023
Basic Go bindings for FLTK

Go FLTK This is a simple go wrapper for FLTK2, which I did to support my Go version of Ober (based on Acme), Gober. It's very small and should be fair

Mar 12, 2022
qt5 bindings for go

#go-qt5 ##Before you start This is a fork of visualfc's qt4 bindings, and several critical bugs are inherited along the way. Until these bugs are fixe

Jan 1, 2023
Tcl/Tk Go bindings

Tcl/Tk Go bindings. VERSION NOTICE Recently Tcl/Tk 8.6 were released. I use them as a default, if you still have Tcl/Tk 8.5 use `go get -tags tcl85

Nov 21, 2022
Go bindings for GTK3

gotk3 The gotk3 project provides Go bindings for GTK 3 and dependent projects. Each component is given its own subdirectory, which is used as the impo

Jan 6, 2023
Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development

Go bindings for Sciter Check this page for other language bindings (Delphi / D / Go / .NET / Python / Rust). Attention The ownership of project is tra

Dec 23, 2022
:traffic_light: Go bindings for libappindicator3 C library

go-appindicator Go bindings for libappindicator3 C library. Libappindicator is a library to allow applications to export a menu into the Unity Menu ba

Jun 19, 2022
Go bindings for GLFW 3

GLFW 3.3 for Go Installation GLFW C library source is included and built automatically as part of the Go package. But you need to make sure you have d

Dec 27, 2022
This project provides Go bindings for nuklear.h — a small ANSI C GUI library.
This project provides Go bindings for nuklear.h — a small ANSI C GUI library.

Nuklear Package nk provides Go bindings for nuklear.h — a small ANSI C gui library. See github.com/vurtun/nuklear. All the binding code has automatica

Jan 1, 2023
A GTK4 bindings generator for Go.

gotk4 A GTK4 bindings generator for Go. Progress tracker: https://github.com/diamondburned/gotk4/issues/2 All generated packages are in pkg/. The gene

Jan 6, 2023
Golang bindings for XCGUI, Windows GUI library, DirectUI design idea.
Golang bindings for XCGUI, Windows GUI library, DirectUI design idea.

XCGUI 项目文档 帮助文档 程序示例 介绍 English | 简体中文 DirectUI设计思想: 在窗口内没有子窗口,界面元素都是逻辑上的区域(无HWND句柄,安全,灵活), 所有UI元素都是自主开发(不受系统限制), 更加灵活的实现各种程序界面,满足不同用户的需求.

Dec 22, 2022
Go bindings for divideon/xvc

go-xvc [WIP] Go bindings for divideon/xvc Requirements requires xvc install on your system $ git clone https://github.com/divideon/xvc.git $ cd xvc $

Feb 7, 2022
Source code editor written in Go using go-gtk bindings. It aims to handle navigation effectively among large number of files.
Source code editor written in Go using go-gtk bindings. It aims to handle navigation effectively among large number of files.

tabby Source code editor written in Go using go-gtk bindings. It aims to handle navigation effectively among large number of files. screenshot: depend

Nov 16, 2022
Go binding for GTK
Go binding for GTK

go-gtk WHATS Go bindings for GTK SCREENSHOT INSTALL You can experiment with go-gtk by running the various example programs: git clone https://github.c

Jan 5, 2023
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

Dec 28, 2022
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

Jan 1, 2023
Go bindings for OpenGL (generated via glow)

gl This repository holds Go bindings to various OpenGL versions. They are auto-generated using Glow. Features: Go functions that mirror the C specific

Dec 12, 2022
A simple, fast, embeddable, persistent key/value store written in pure Go. It supports fully serializable transactions and many data structures such as list, set, sorted set.

NutsDB English | 简体中文 NutsDB is a simple, fast, embeddable and persistent key/value store written in pure Go. It supports fully serializable transacti

Jan 1, 2023
Quick add or delete ASN/AS-SET to your AS-SET through RIPE RESTful API

RIPE AS-SET updater Quick add or delete ASN/AS-SET to your AS-SET through RIPE RESTful API. Requirenments You need to add "auth:" attribute in mntner

Apr 19, 2022