Git Product home page Git Product logo

gotk3's Introduction

gotk3 GoDoc

Build Status

The gotk3 project provides Go bindings for GTK 3 and dependent projects. Each component is given its own subdirectory, which is used as the import path for the package. Partial binding support for the following libraries is currently implemented:

  • GTK 3 (3.12 and later)
  • GDK 3 (3.12 and later)
  • GLib 2 (2.36 and later)
  • Cairo (1.10 and later)

Care has been taken for memory management to work seamlessly with Go's garbage collector without the need to use or understand GObject's floating references.

for better understanding see package reference documation

On Linux, see which version your distribution has here with the search terms:

  • libgtk-3
  • libglib2
  • libgdk-pixbuf2

Sample Use

The following example can be found in Examples.

package main

import (
    "github.com/gotk3/gotk3/gtk"
    "log"
)

func main() {
    // Initialize GTK without parsing any command line arguments.
    gtk.Init(nil)

    // Create a new toplevel window, set its title, and connect it to the
    // "destroy" signal to exit the GTK main loop when it is destroyed.
    win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
    if err != nil {
        log.Fatal("Unable to create window:", err)
    }
    win.SetTitle("Simple Example")
    win.Connect("destroy", func() {
        gtk.MainQuit()
    })

    // Create a new label widget to show in the window.
    l, err := gtk.LabelNew("Hello, gotk3!")
    if err != nil {
        log.Fatal("Unable to create label:", err)
    }

    // Add the label to the window.
    win.Add(l)

    // Set the default window size.
    win.SetDefaultSize(800, 600)

    // Recursively show all widgets contained in this window.
    win.ShowAll()

    // Begin executing the GTK main loop.  This blocks until
    // gtk.MainQuit() is run.
    gtk.Main()
}

To build the example:

$ go build example.go

To build this example with older gtk version you should use gtk_3_10 tag:

$ go build -tags gtk_3_10 example.go

Example usage

package main

import (
    "log"
    "os"

    "github.com/gotk3/gotk3/glib"
    "github.com/gotk3/gotk3/gtk"
)

// Simple Gtk3 Application written in go.
// This application creates a window on the application callback activate.
// More GtkApplication info can be found here -> https://wiki.gnome.org/HowDoI/GtkApplication

func main() {
    // Create Gtk Application, change appID to your application domain name reversed.
    const appID = "org.gtk.example"
    application, err := gtk.ApplicationNew(appID, glib.APPLICATION_FLAGS_NONE)
    // Check to make sure no errors when creating Gtk Application
    if err != nil {
        log.Fatal("Could not create application.", err)
    }
    // Application signals available
    // startup -> sets up the application when it first starts
    // activate -> shows the default first window of the application (like a new document). This corresponds to the application being launched by the desktop environment.
    // open -> opens files and shows them in a new window. This corresponds to someone trying to open a document (or documents) using the application from the file browser, or similar.
    // shutdown ->  performs shutdown tasks
    // Setup Gtk Application callback signals
    application.Connect("activate", func() { onActivate(application) })
    // Run Gtk application
    os.Exit(application.Run(os.Args))
}

// Callback signal from Gtk Application
func onActivate(application *gtk.Application) {
    // Create ApplicationWindow
    appWindow, err := gtk.ApplicationWindowNew(application)
    if err != nil {
        log.Fatal("Could not create application window.", err)
    }
    // Set ApplicationWindow Properties
    appWindow.SetTitle("Basic Application.")
    appWindow.SetDefaultSize(400, 400)
    appWindow.Show()
}
package main

import (
    "log"
    "os"

    "github.com/gotk3/gotk3/glib"
    "github.com/gotk3/gotk3/gtk"
)

// Simple Gtk3 Application written in go.
// This application creates a window on the application callback activate.
// More GtkApplication info can be found here -> https://wiki.gnome.org/HowDoI/GtkApplication

func main() {
    // Create Gtk Application, change appID to your application domain name reversed.
    const appID = "org.gtk.example"
    application, err := gtk.ApplicationNew(appID, glib.APPLICATION_FLAGS_NONE)
    // Check to make sure no errors when creating Gtk Application
    if err != nil {
        log.Fatal("Could not create application.", err)
    }

    // Application signals available
    // startup -> sets up the application when it first starts
    // activate -> shows the default first window of the application (like a new document). This corresponds to the application being launched by the desktop environment.
    // open -> opens files and shows them in a new window. This corresponds to someone trying to open a document (or documents) using the application from the file browser, or similar.
    // shutdown ->  performs shutdown tasks
    // Setup activate signal with a closure function.
    application.Connect("activate", func() {
        // Create ApplicationWindow
        appWindow, err := gtk.ApplicationWindowNew(application)
        if err != nil {
            log.Fatal("Could not create application window.", err)
        }
        // Set ApplicationWindow Properties
        appWindow.SetTitle("Basic Application.")
        appWindow.SetDefaultSize(400, 400)
        appWindow.Show()
    })
    // Run Gtk application
    application.Run(os.Args)
}

Documentation

Each package's internal go doc style documentation can be viewed online without installing this package by using the GoDoc site (links to cairo, glib, gdk, and gtk documentation).

You can also view the documentation locally once the package is installed with the godoc tool by running godoc -http=":6060" and pointing your browser to http://localhost:6060/pkg/github.com/gotk3/gotk3

Installation

gotk3 currently requires GTK 3.6-3.24, GLib 2.36-2.46, and Cairo 1.10 or 1.12. A recent Go (1.8 or newer) is also required.

For detailed instructions see the wiki pages: installation

Using deprecated features

By default, deprecated GTK features are not included in the build.

By specifying the e.g. build tag gtk_3_20, any feature deprecated in GTK 3.20 or earlier will NOT be available. To enable deprecated features in the build, add the tag gtk_deprecated. Example:

$ go build -tags "gtk_3_10 gtk_deprecated" example.go

The same goes for

  • gdk-pixbuf: gdk_pixbuf_deprecated

TODO

  • Add bindings for all of GTK functions
  • Add tests for each implemented binding
  • See the next steps: wiki page and add your suggestion

License

Package gotk3 is licensed under the liberal ISC License.

Actually if you use gotk3, then gotk3 is statically linked into your application (with the ISC licence). The system libraries (e.g. GTK+, GLib) used via cgo use dynamic linking.

gotk3's People

Contributors

andre-hub avatar b00f avatar bios-marcel avatar diamondburned avatar drakbar avatar equinox0815 avatar founderio avatar ftl avatar geoffholden avatar hfmrow avatar isolus avatar ivanyatcuba avatar jmoiron avatar jrick avatar juniorz avatar lidaobing avatar mjacred avatar movingtomars avatar okelet avatar olabini avatar patknight avatar pedropalau avatar pekim avatar raichu avatar rakete avatar shish avatar soreil avatar sqp avatar tbuen avatar yamnikov-oleg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gotk3's Issues

gtk.TreeStore: Unable to store gdk.Pixbuf objects

The attempt to store (and view) gdk.Pixbuf objects in a gtk.TreeStore leads to warning messages from the GTK library: Gtk-WARNING **: /build/buildd/gtk+3.0-3.14.13/./gtk/gtktreestore.c:856: Unable to convert from gpointer to GObject, and the icons are not drawn. Note: using a gtk.ListStore does not have this issue.

I will provide a (almost trivial) fix.

Can't convert IObject to Window after GetObject from builder

I tried to use gotk3 with a builder but I couldn't show the window because I couldn't cast IObject to Window. This is the code I wrote to try it:

func main() {
	gtk.Init(nil)

	builder, err := gtk.BuilderNew()
	if err != nil {
		panic(err)
	}
	builder.AddFromFile("example.glade")

	object, err := builder.GetObject("window1")
	if err != nil {
		panic(err)
	}

	window, ok := object.(gtk.Window)
	if ok {
		window.ShowAll()
		gtk.Main()
	}
}

The glade file is really simple, a GtkWindow object named window1 with a label inside of it.

cgo argument has Go pointer to Go pointer when setting with GOGC=1

I've battled this problem for a while, the solution was to use glib.IdleAdd
which seemed to work until today I tried to set the garbage collector to a minimal value GOGC=1
I don't know what I'm doing wrong at this point, any help would be appreciated.
source

func (w *Status) addMessage(msg string) bool {
	w.buffer.Insert(w.iter, msg)
	if !w.iter.IsEnd() {
		w.iter.ForwardToEnd()
	}
	return false
}
go func(s *Status) {
			for {
				var logmsg string
				select {
				case <-s.logStopper:
					return
				case logmsg = <-bot.LogCh:
					_, err := glib.IdleAdd(s.addMessage, logmsg)
					fatal(err)
				}
			}
		}(&st)
panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/gotk3/gotk3/gtk.(*TextIter).IsEnd.func1(0xc42001a4b0, 0x1c6bd50)
        /home/ugjka/goworks/src/github.com/gotk3/gotk3/gtk/text_iter.go:186 +0x52
github.com/gotk3/gotk3/gtk.(*TextIter).IsEnd(0xc42001a4b0, 0xc42001a4b0)
        /home/ugjka/goworks/src/github.com/gotk3/gotk3/gtk/text_iter.go:186 +0x30
main.(*Status).addMessage(0xc42001a2d0, 0xc4201e8150, 0x2c, 0xc420014f90)
        /home/ugjka/goworks/src/github.com/ugjka/newyearsbot/gui/status.go:78 +0x5e
main.(*Status).(main.addMessage)-fm(0xc4201e8150, 0x2c, 0x0)
        /home/ugjka/goworks/src/github.com/ugjka/newyearsbot/gui/main.go:61 +0x3e
reflect.Value.call(0x8f22c0, 0xc42025be10, 0x13, 0x9a8a26, 0x4, 0xc42024a0a0, 0x1, 0x1, 0xc4201e40c0, 0x8e0140, ...)
        /usr/lib/go/src/reflect/value.go:434 +0x91f
reflect.Value.Call(0x8f22c0, 0xc42025be10, 0x13, 0xc42024a0a0, 0x1, 0x1, 0x4b8001, 0x10858e8, 0xc4200f3748)
        /usr/lib/go/src/reflect/value.go:302 +0xa4
github.com/gotk3/gotk3/glib.sourceAttach.func2()
        /home/ugjka/goworks/src/github.com/gotk3/gotk3/glib/glib.go:311 +0x18c
reflect.Value.call(0x8d6300, 0xc42024c320, 0x13, 0x9a8a26, 0x4, 0x10858e8, 0x0, 0x0, 0x0, 0x0, ...)
        /usr/lib/go/src/reflect/value.go:434 +0x91f
reflect.Value.Call(0x8d6300, 0xc42024c320, 0x13, 0x10858e8, 0x0, 0x0, 0x0, 0x0, 0x4609cf)
        /usr/lib/go/src/reflect/value.go:302 +0xa4
github.com/gotk3/gotk3/glib.goMarshal(0x7fb378001150, 0x7ffc3277e060, 0x0, 0x0, 0x0, 0x0)
        /home/ugjka/goworks/src/github.com/gotk3/gotk3/glib/glib.go:216 +0x5ba
github.com/gotk3/gotk3/glib._cgoexpwrap_e280e468d867_goMarshal(0x7fb378001150, 0x7ffc3277e060, 0x0, 0x0, 0x0, 0x0)
        github.com/gotk3/gotk3/glib/_obj/_cgo_gotypes.go:3561 +0x5b
github.com/gotk3/gotk3/gtk._Cfunc_gtk_main()
        github.com/gotk3/gotk3/gtk/_obj/_cgo_gotypes.go:11253 +0x41
github.com/gotk3/gotk3/gtk.Main()
        /home/ugjka/goworks/src/github.com/gotk3/gotk3/gtk/gtk.go:874 +0x20
main.main()
        /home/ugjka/goworks/src/github.com/ugjka/newyearsbot/gui/main.go:69 +0x2dd
exit status 2

Does Gotk3 Support modern GTK+3 use?

The example on the front page uses the old-fashioned approach to using GTK+3, the old GTK+2 way. GTK+3 now emphasises use of Application and ApplicationWindow. Is this style possible with Gotk3? If it is, should the front page show the more modern approach to GTK+3?

Cairo Text rendering wrapper broken

Hi,

it seems that with the recent activity to break down cairo.go into smaller pieces, this commit has been lost:

24f3a1f

which adds text rendering to cairo.

I will add a text.go to cairo having the exact same content as the commit above.

Cheers
Axel

Change repository status (remove fork dependency)

The repository is currently seen as a fork of the conformal master. This disables searching of the repo on the github website. It also makes it so that when you make a pull request it defaults to diffing the conformal repo and the gotk3 repo. This takes a super long time to load on slow computers.

Install errors using "go get..."

From my 64-bit Linux Mint system, gcc version 4.8.4, go version 1.6

~/mygo $ go get github.com/gotk3/gotk3/gtk
github.com/gotk3/gotk3/gtk
could not determine kind of name for C.GtkActionBar
could not determine kind of name for C.gtk_action_bar_get_center_widget
could not determine kind of name for C.gtk_action_bar_get_type
could not determine kind of name for C.gtk_action_bar_new
could not determine kind of name for C.gtk_action_bar_pack_end
could not determine kind of name for C.gtk_action_bar_pack_start
could not determine kind of name for C.gtk_action_bar_set_center_widget

gcc errors for preamble:
In file included from src/github.com/gotk3/gotk3/gtk/actionbar_since_3_12.go:30:0:
actionbar_since_3_12.go.h:21:1: error: unknown type name 'GtkActionBar'
static GtkActionBar *
^

team communication

hello @gotk3/gotk3-core

we need a (simple, friendly, ..) communication channel.

have you a idea?

cgo blows up with runtime error: `cgo argument has Go pointer to Go pointer`

Go 1.6 has some more strict checking on what you can and can't do with Go pointers --

panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running, locked to thread]:
panic(0x65d200, 0xc4200185f0)
    /usr/lib/go-1.7/src/runtime/panic.go:500 +0x1a1
github.com/sourcegraph/go-webkit2/webkit2.(*WebView).RunJavaScript(0xc420018530, 0xc4200595d8, 0xf, 0xc4200185e0)
    /home/paultag/.goenvs/epson/src/github.com/sourcegraph/go-webkit2/webkit2/webview.go:147 +0xea
main.main.func3(0xc4200380b8, 0x3)
    /home/paultag/dev/local/go-webkit2/cmd/webkit-eval-js/evaljs.go:84 +0xfb
reflect.Value.call(0x650f40, 0xc42000c5a0, 0x13, 0x6aeb1c, 0x4, 0xc42000c7b0, 0x2, 0x2, 0x0, 0x6490c0, ...)
    /usr/lib/go-1.7/src/reflect/value.go:434 +0x5c8
reflect.Value.Call(0x650f40, 0xc42000c5a0, 0x13, 0xc42000c7b0, 0x2, 0x2, 0xc4200185d0, 0x82, 0x0)
    /usr/lib/go-1.7/src/reflect/value.go:302 +0xa4
github.com/gotk3/gotk3/glib.goMarshal(0x16b2180, 0x0, 0x2, 0x7ffe3a989690, 0x7ffe3a989610, 0x0)
    /home/paultag/.goenvs/epson/src/github.com/gotk3/gotk3/glib/glib.go:283 +0x601
github.com/gotk3/gotk3/glib._cgoexpwrap_cca433d51eec_goMarshal(0x16b2180, 0x0, 0x2, 0x7ffe3a989690, 0x7ffe3a989610, 0x0)
    ??:0 +0x5b
github.com/gotk3/gotk3/gtk._Cfunc_gtk_main()
    ??:0 +0x41
github.com/gotk3/gotk3/gtk.Main()
    /home/paultag/.goenvs/epson/src/github.com/gotk3/gotk3/gtk/gtk.go:766 +0x14
main.main()
    /home/paultag/dev/local/go-webkit2/cmd/webkit-eval-js/evaljs.go:93 +0x474

https://groups.google.com/forum/#!searchin/golang-nuts/cgo$20argument$20has$20Go$20pointer$20to$20Go$20pointer/golang-nuts/gnH0nhPf36I/4Shly3gxEwAJ

golang/go#12416

Design docs: https://github.com/golang/proposal/blob/master/design/12416-cgo-pointers.md

Originally reported as sourcegraph/go-webkit2#33

win32: Preventing cmd window behind GUI

Greetings, I have written a test application in gotk3 on Linux and now compiled on Windows. But on Win32, when I double-click the resulting .exe file in Explorer or similar, then there always opens a cmd-like window behind the GUI application window. How can this prevented?

TextView.GetBuffer throws panic

[ancient@NickolayPC gtBot]$ go run *.go
#Main thread is started
# gtBot vDev
#GTK thread is started
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x815e2a1]

goroutine 5 [running]:
panic(0x83f3e00, 0x95b7a038)
    /usr/lib/go/src/runtime/panic.go:481 +0x326
github.com/gotk3/gotk3/gtk.(*TextView).native(0x881e974, 0x95b70b60)
    /home/ancient/load/go/src/github.com/gotk3/gotk3/gtk/text_view.go:38 +0x21
github.com/gotk3/gotk3/gtk.(*TextView).GetBuffer(0x881e974, 0x80f0439, 0x0, 0x0)
    /home/ancient/load/go/src/github.com/gotk3/gotk3/gtk/text_view.go:73 +0x2f
main.guiCTVAddText(0x0, 0x0)
    /home/ancient/code/gtBot/gui.go:100 +0x30
main.runGui.func2()
    /home/ancient/code/gtBot/gui.go:91 +0xe0
reflect.Value.call(0x8315a40, 0x95b7a1c8, 0x13, 0x8475ba0, 0x4, 0x882ea10, 0x0, 0x0, 0x0, 0x0, ...)
    /usr/lib/go/src/reflect/value.go:435 +0xeeb
reflect.Value.Call(0x8315a40, 0x95b7a1c8, 0x13, 0x882ea10, 0x0, 0x0, 0x0, 0x0, 0x0)
    /usr/lib/go/src/reflect/value.go:303 +0x8c
github.com/gotk3/gotk3/glib.goMarshal(0x978e360, 0x0, 0x1, 0xbfe197d0, 0xbfe19774, 0x0)
    /home/ancient/load/go/src/github.com/gotk3/gotk3/glib/glib.go:215 +0x857
github.com/gotk3/gotk3/glib._cgoexpwrap_cb9c2bed3ab7_goMarshal(0x978e360, 0x0, 0x1, 0xbfe197d0, 0xbfe19774, 0x0)
    ??:0 +0x49
github.com/gotk3/gotk3/gtk._Cfunc_gtk_main()
    ??:0 +0x33
github.com/gotk3/gotk3/gtk.Main()
    /home/ancient/load/go/src/github.com/gotk3/gotk3/gtk/gtk.go:873 +0x17
main.runGui(0x95b82180)
    /home/ancient/code/gtBot/gui.go:96 +0xa0c
created by main.main
    /home/ancient/code/gtBot/main.go:15 +0x226
exit status 2

Could not install it

When I tried this go get https://github.com/gotk3/gotk3 and go build example.go
I tried to build it because it managed to get the code, and it was added as go build example.go returned an error with a statement referring to the location it is installed in
I got this error-->

github.com/gotk3/gotk3/glib

../work/src/github.com/gotk3/gotk3/glib/glib.go:259: cannot use idleSrc (type *_Ctype_GSource) as type *_Ctype_struct__GSource in function argument
../work/src/github.com/gotk3/gotk3/glib/glib.go:282: cannot use timeoutSrc (type *_Ctype_GSource) as type *_Ctype_struct__GSource in function argument
../work/src/github.com/gotk3/gotk3/glib/glib.go:293: cannot use src (type *_Ctype_struct__GSource) as type *_Ctype_GSource in function argument
../work/src/github.com/gotk3/gotk3/glib/glib.go:319: cannot use src (type *_Ctype_struct__GSource) as type *_Ctype_GSource in function argument
../work/src/github.com/gotk3/gotk3/glib/glib.go:326: cannot use src (type *_Ctype_struct__GSource) as type *_Ctype_GSource in function argument
../work/src/github.com/gotk3/gotk3/glib/glib.go:330: cannot use src (type *_Ctype_struct__GSource) as type *_Ctype_GSource in function argument
../work/src/github.com/gotk3/gotk3/glib/list.go:40: cannot use v.native() (type *_Ctype_struct__GList) as type *_Ctype_GList in function argument
../work/src/github.com/gotk3/gotk3/glib/list.go:41: cannot use glist (type *_Ctype_GList) as type *_Ctype_struct__GList in function argument
../work/src/github.com/gotk3/gotk3/glib/list.go:46: cannot use v.native() (type *_Ctype_struct__GList) as type *_Ctype_GList in function argument
../work/src/github.com/gotk3/gotk3/glib/list.go:47: cannot use glist (type *_Ctype_GList) as type *_Ctype_struct__GList in function argument
../work/src/github.com/gotk3/gotk3/glib/list.go:47: too many errors

Win8.1x64: libintl.h: No such file or directory

Sorry for my bad english...
I used https://github.com/gotk3/gotk3/wiki/Installing-on-Windows
pkg-config --cflags --libs gtk+-3.0 - no error
go get github.com/gotk3/gotk3/gtk return:

# github.com/gotk3/gotk3/glib
In file included from ./glib.go.h:31:0,
                 from D:\GOPATH\src\github.com\gotk3\gotk3\glib\application.go:7:
C:/Fedora/include/glib-2.0/glib/gi18n.h:25:21: fatal error: libintl.h: No such file or directory
 #include <libintl.h>
                     ^
compilation terminated.

GOPATH: D:\GOPATH
GOROOT: C:\Go\
Path: ;C:\Fedora\include;C:\Fedora\bin;C:\Program Files\mingw-builds\x64-4.8.1-posix-seh-rev5\mingw64\bin;C:\mingw64\bin;C:\mingw\bin

File libintl.h exist in C:\Fedora\include
I really do not know how to solve this problem...

Installation on Windows error libintl.h not found

I followed the wiki guide and I'm getting this error:
gotk3-error

I installed the exact same versions mentionend on the guide, the only difference was that mingw-builds-install was not working so I downloaded x64-4.8.1-release-posix-seh-rev5.7z and uncompressed it on C, also modified the enviroment PATHS accordingly.

Any ideas?
BTW, is it possible to cross compile it from linux?

Build failed: unrecognized relocation (0x2a) in section `.text'

Tried to build simple.go

$ go build -tags gtk_3_14 simple.go

# command-line-arguments
/usr/lib/go-1.7/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: /tmp/go-link-073651445/000001.o: unrecognized relocation (0x2a) in section `.text'
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

OS: Debian GNU/Linux 8

Package: libgtk-3-0
Version: 3.14.5-1+deb8u1

Package: libgtk-3-dev
Version: 3.14.5-1+deb8u1

$ gcc --version
gcc (Debian 4.9.2-10) 4.9.2

(Also tried with gcc 4.8.4 as default version)

GtkColorButton and other widgets missing from WrapMap

After adding a ColorButton to my UI (I'm using GtkBuilder), to my surprise GetObject returned an error saying:

unrecognized class name 'GtkColorButton'

which I traced back to the lack of an entry for this widget in the WrapMap map in gtk.go. Adding its name and wrapping function to the map, I can now use this widget without problems.

Other widgets are missing, including (but possibly not limited to) all the GtkColor* ones.

Deprecation warnings with GTK 3.20.x

➤ go get github.com/gotk3/gotk3/gtk
# github.com/gotk3/gotk3/gdk
code/go/src/github.com/gotk3/gotk3/gdk/gdk.go:288:6: warning: 'gdk_device_grab' is deprecated [-Wdeprecated-declarations]
/usr/include/gtk-3.0/gdk/gdkdevice.h:250:15: note: 'gdk_device_grab' has been explicitly marked deprecated here
code/go/src/github.com/gotk3/gotk3/gdk/gdk.go:305:25: warning: 'gdk_device_manager_get_client_pointer' is deprecated [-Wdeprecated-declarations]
/usr/include/gtk-3.0/gdk/gdkdevicemanager.h:44:14: note: 'gdk_device_manager_get_client_pointer' has been explicitly marked deprecated here
code/go/src/github.com/gotk3/gotk3/gdk/gdk.go:357:25: warning: 'gdk_device_manager_list_devices' is deprecated [-Wdeprecated-declarations]
/usr/include/gtk-3.0/gdk/gdkdevicemanager.h:41:14: note: 'gdk_device_manager_list_devices' has been explicitly marked deprecated here
code/go/src/github.com/gotk3/gotk3/gdk/gdk.go:373:2: warning: 'gdk_device_ungrab' is deprecated [-Wdeprecated-declarations]
/usr/include/gtk-3.0/gdk/gdkdevice.h:259:15: note: 'gdk_device_ungrab' has been explicitly marked deprecated here
code/go/src/github.com/gotk3/gotk3/gdk/gdk.go:511:25: warning: 'gdk_display_get_device_manager' is deprecated [-Wdeprecated-declarations]
/usr/include/gtk-3.0/gdk/gdkdisplay.h:170:20: note: 'gdk_display_get_device_manager' has been explicitly marked deprecated here
# github.com/gotk3/gotk3/gtk
code/go/src/github.com/gotk3/gotk3/gtk/gtk.go:1417:6: warning: 'gtk_button_get_focus_on_click' is deprecated [-Wdeprecated-declarations]
/usr/include/gtk-3.0/gtk/gtkbutton.h:141:23: note: 'gtk_button_get_focus_on_click' has been explicitly marked deprecated here
code/go/src/github.com/gotk3/gotk3/gtk/gtk.go:1601:2: warning: 'gtk_button_set_focus_on_click' is deprecated [-Wdeprecated-declarations]
/usr/include/gtk-3.0/gtk/gtkbutton.h:138:23: note: 'gtk_button_set_focus_on_click' has been explicitly marked deprecated here
# github.com/gotk3/gotk3/gtk
code/go/src/github.com/gotk3/gotk3/gtk/text_iter.go:260:6: warning: 'gtk_text_iter_begins_tag' is deprecated [-Wdeprecated-declarations]
/usr/include/gtk-3.0/gtk/gtktextiter.h:178:10: note: 'gtk_text_iter_begins_tag' has been explicitly marked deprecated here
# github.com/gotk3/gotk3/gtk
code/go/src/github.com/gotk3/gotk3/gtk/window.go:703:2: warning: 'gtk_window_resize_to_geometry' is deprecated [-Wdeprecated-declarations]
/usr/include/gtk-3.0/gtk/gtkwindow.h:451:6: note: 'gtk_window_resize_to_geometry' has been explicitly marked deprecated here
code/go/src/github.com/gotk3/gotk3/gtk/window.go:771:2: warning: 'gtk_window_set_default_geometry' is deprecated [-Wdeprecated-declarations]
/usr/include/gtk-3.0/gtk/gtkwindow.h:447:6: note: 'gtk_window_set_default_geometry' has been explicitly marked deprecated here

I'm busy atm, so if someone gets around fixing it, please leave a note, otherwise I'll eventually submit a PR.

Can't convert from *gtk.Widget to *gtk.Label

gtk.Bin.GetChild() returns *gtk.Widget, but I can't find a way to convert that to a *gtk.Label. So I wrote this function:

func (v *Widget) ToLabel() *Label {
        return wrapLabel(wrapObject(unsafe.Pointer(v.native())))
}

Is this the right way to solve this?

could not determine kind of name for C.GtkActionBar

Full output below. I've upgraded GTK and GDK to their latest versions. Go get was performed today.

Is this a known problem?


#github.com/gotk3/gotk3/gtk
could not determine kind of name for C.GtkActionBar
could not determine kind of name for C.gtk_action_bar_get_center_widget
could not determine kind of name for C.gtk_action_bar_get_type
could not determine kind of name for C.gtk_action_bar_new
could not determine kind of name for C.gtk_action_bar_pack_end
could not determine kind of name for C.gtk_action_bar_pack_start
could not determine kind of name for C.gtk_action_bar_set_center_widget

gcc errors for preamble:
In file included from golang/src/github.com/gotk3/gotk3/gtk/actionbar_since_3_12.go:30:0:
actionbar_since_3_12.go.h:21:1: error: unknown type name 'GtkActionBar'
static GtkActionBar *
^

Inverted fill direction eg. bottom-up for ProgressBar (incl. patch)

GTK3 ProgressBar supports the ability to invert the fill direction. This is useful in conjunction with vertical progress bars. By default these fill up top to bottom, but if a "fill level"-like display is desired, then the inversion function is needed. Is allows to realize fill-level like progress (consuming a buffer, filling up a buffer).

This is related to issue #161.

Patch follows:

  1. Open gotk3/gtk/gtk.go.
  2. After func (v *ProgressBar) GetShowText, insert:
// SetInverted is a wrapper around gtk_progress_bar_set_inverted().
func (v *ProgressBar) SetInverted(inverted bool) {
	C.gtk_progress_bar_set_inverted(v.native(), gbool(inverted))
}

// GetInverted is a wrapper around gtk_progress_bar_get_inverted().
func (v *ProgressBar) GetInverted() bool {
	c := C.gtk_progress_bar_get_inverted(v.native())
	return gobool(c)
}
  1. Recompile your gotk3-based application, which will also re-compile gotk3/gtk.

Fails to build with Go 1.6beta1

Probably due to the new Cgo rules, works just fine on Go 1.5.2 on Windows and Linux but fails on both with the beta.

panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/gotk3/gotk3/gtk.Init(0xe6d000)
/home/sjon/go/src/github.com/gotk3/gotk3/gtk/gtk.go:830 +0x220
main.main()
/home/sjon/go/src/2048/main.go:63 +0x32
exit status 2

How to pass data to the handler?

Glade: https://yadi.sk/i/TnaMLyrw32P86v

Code:

signals := map[string]interface{}{
"myhandler": func(e *gtk.Button) {
fmt.Println(e.GetLabel())
},
}

If I add another variable to the function, it will error:

"myhandler": func(e *gtk.Button, obj interface{}) {

How to get "txt" object in handler?

Activity pulsing for ProgressBar (incl. patch)

GTK3 ProgressBar supports showing activity on the progress bar, without knowing how far the progress went / what its impact on progress was. This is shown by a bar moving back and forth inside the ProgressBar.

To go into this "activity" mode, call Pulse() - depending on how often you call it in your work loop, you can adjust the moving speed using pb.SetPulseStep(). Switching into fraction-mode is done using just setting regular pb.SetFraction() function.

Unfortunately, this is not currently wrapped by gotk3.

Patch follows:

  1. Open gotk3/gtk/gtk.go.
  2. Somewhere around func (v *ProgressBar) SetFraction(, insert:
// SetPulseStep is a wrapper around gtk_progress_bar_set_pulse_step().
func (v *ProgressBar) SetPulseStep(fraction float64) {
	C.gtk_progress_bar_set_pulse_step(v.native(), C.gdouble(fraction))
}

// GetPulseStep is a wrapper around gtk_progress_bar_get_pulse_step().
func (v *ProgressBar) GetPulseStep() float64 {
	c := C.gtk_progress_bar_get_pulse_step(v.native())
	return float64(c)
}

// Pulse is a wrapper arountd gtk_progress_bar_pulse().
func (v *ProgressBar) Pulse() {
	C.gtk_progress_bar_pulse(v.native())
}
  1. Recompile your gotk3-based application, which will also re-compile gotk3/gtk.

Fix travis build

The travis build is currently disabled. We have been able to run gotk3 on travis with a config file like this:

language: go

before_install:
  - sudo apt-get update -qq
  - sudo apt-get install -qq -y gtk+3.0 libgtk-3-dev

sudo: required
dist: trusty

Note we use trusty to get more recent versions of GTK+ 3.

For testing, we have used something like this to setup the correct build tag:

GTK_VERSION=$(pkg-config --modversion gtk+-3.0 | tr . _| cut -d '_' -f 1-2)
go test -tags "gtk_${GTK_VERSION}" github.com/gotk3/gotk3/...

You can try something along these lines, and enable the travis build.

Could not install gtk. Error: could not determine kind of name for....

On CentOS-7-x86_64 I'm trying to install webloop but i get the following error. How to solve it?

[root@localhost package]# go get github.com/sourcegraph/webloop
# github.com/gotk3/gotk3/gtk
could not determine kind of name for C.gtk_paned_get_wide_handle
could not determine kind of name for C.gtk_paned_set_wide_handle
could not determine kind of name for C.gtk_scrolled_window_get_overlay_scrolling
could not determine kind of name for C.gtk_scrolled_window_set_overlay_scrolling

TreeSelection.GetSelected is broken

and panics preparing the arguments for the actual C call.

The interface is poor Go: func (v *TreeSelection) GetSelected(model *ITreeModel, iter *TreeIter) bool

It has (1) a pointer to interface argument and (2) another (input) arguments that is actually a return. I would rather change the interface to be more Go like: func (v *TreeSelection) GetSelected() (model ITreeModel, iter TreeIter, ok bool).

I will provide a patch through pull request. Will also extend gotk3-examples (treeview2) to use this function.

Cheers
Axel

compiling webloop's example fails

I'm trying to compile the example of sourcegraph/webloop (https://github.com/sourcegraph/webloop/blob/master/examples/angular-static-seo/server.go), which has gotk3 as a dependency. I'm running into the following errors, that seem to be gotk3-related:

$ go build -tags gtk_3_10 server.go 
# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/tmp/go-link-659884296/000009.o: In function `removeClosure':
/tmp/go-build971982688/github.com/gotk3/gotk3/glib/_obj/_cgo_export.c:10: multiple definition of `removeClosure'
/tmp/go-link-659884296/000001.o:/tmp/go-build781173935/github.com/conformal/gotk3/glib/_obj/_cgo_export.c:10: first defined here
/tmp/go-link-659884296/000009.o: In function `goMarshal':
/tmp/go-build971982688/github.com/gotk3/gotk3/glib/_obj/_cgo_export.c:23: multiple definition of `goMarshal'
/tmp/go-link-659884296/000001.o:/tmp/go-build781173935/github.com/conformal/gotk3/glib/_obj/_cgo_export.c:23: first defined here
collect2: error: ld returned 1 exit status

My OS is ubuntu 14.04.

Filechooser dialog wait till other func end before destroy

Hello,
I have a problem, I am using filechooserdialog to select csv file but when I press button to open, dialog window wait till csv file will be readed and sent to display function and after this all dialog destroy. I want to kill this dialog instantly after choose file, and them show spinner or something that program is processing data.

package gui

import (
  "log"

  "github.com/gotk3/gotk3/gtk"
)

//OpenWindow use to launch filechooserdialog
//function set name of file to open
func (w *Window) OpenWindow() {
  filechooser, _ := gtk.FileChooserDialogNewWith2Buttons(
    "Open...",
    w.win,
    gtk.FILE_CHOOSER_ACTION_OPEN,
    "Cancel",
    gtk.RESPONSE_DELETE_EVENT,
    "Open",
    gtk.RESPONSE_ACCEPT)
  filter, _ := gtk.FileFilterNew()
  filter.AddPattern("*.csv")
  filter.SetName(".csv")
  filechooser.AddFilter(filter)

  switcher := filechooser.Run()
  log.Println(switcher, ": switcher")
  w.filename = filechooser.GetFilename()
  //here dialog should destroy but
  // it and till DisplayCSV func ends
  filechooser.Destroy()
  if switcher != -3 {

    //Nothing more to do here
    w.filename = ""
    return
  }
  log.Println("User choose file")

  //fielchooser.Destory() don't kill dialog instantly
  // it wait till this function below ends
  w.DisplayCSV()
}

Are the handlers?

Hi. Thanks for this project!

I use glade for design ui. I add handler on button (myhandler on clicked signal), but it does not call the handler from code. How do I properly declare it in the code?

P.S. Сonnect to the signals works (I caught the "clicked" signal)

2016-11-23 01-22-15

Building apps on Ubuntu 14.04

To build application on Ubuntu 14.04 you should use gtk_3_10 tag:
$ go build -tags gtk_3_10 example.go.

Maybe add this info to README?

Unable to build when importing gotk3/gotk3

I have libgtk-3-dev version 3.12.2 installed on Ubuntu 14.04, but when I run go build main.go I get the following output:

# github.com/gotk3/gotk3/gtk
could not determine kind of name for C.gtk_application_get_actions_for_accel
could not determine kind of name for C.gtk_application_get_menu_by_id
could not determine kind of name for C.gtk_application_prefers_app_menu

Do you have any suggestions?

MaxWidthChars for Entry control (incl. patch)

I wanted to set the maximum visible width of an Entry control today for an entry form. For example, only 10 characters should be visible = control width. I noticed that

  • Entry.SetMaxLength sets the maximum characters the user can enter (useful),
  • Entry.SetWidth(charcount) sends a resize request, but when an Entry is inside a container (Grid in my case), then this is not enough. Therefore, the ...
  • Entry.SetMaxWidthChars(charcount) function is needed.

Unfortunately, this function is not wrapped in gotk3.

See the gtk3 documentation about the functions here:

Patch for gotk3: Paste the following into gtk/gtk.go file:

// SetMaxWidthChars() is a wrapper around gtk_entry_set_max_width_chars().
func (v *Entry) SetMaxWidthChars(nChars int) {
	C.gtk_entry_set_max_width_chars(v.native(), C.gint(nChars))
}

// GetMaxWidthChars() is a wrapper around gtk_entry_get_max_width_chars().
func (v *Entry) GetMaxWidthChars() int {
	c := C.gtk_entry_get_max_width_chars(v.native())
	return int(c)
}

Already tested this today. I am using libgtk-3.0 version 3.18.9 for reference.

I could file a PR, but it's really just a matter of copy & paste into any place in gtk/gtk.go.

Please include this change into gotk3.

LabelNew throws panic

LabelNew throws a panic here on Mac OS X El Capitan

(process:42530): GLib-GObject-CRITICAL **: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed

(process:42530): GLib-GObject-CRITICAL **: g_object_set_qdata_full: assertion 'G_IS_OBJECT (object)' failed
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x0 pc=0x5389d71]

runtime stack:
runtime.throw(0x46681e0, 0x2a)
    /usr/local/Cellar/go/1.5.3/libexec/src/runtime/panic.go:527 +0x90
runtime.sigpanic()
    /usr/local/Cellar/go/1.5.3/libexec/src/runtime/sigpanic_unix.go:12 +0x5a

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x42b84a0, 0xc8200d9378, 0x0)
    /usr/local/Cellar/go/1.5.3/libexec/src/runtime/cgocall.go:120 +0x11b fp=0xc8200d9348 sp=0xc8200d9318
github.com/gotk3/gotk3/gtk._Cfunc_gtk_label_new(0x5f00060, 0x0)
    ??:0 +0x36 fp=0xc8200d9378 sp=0xc8200d9348
github.com/gotk3/gotk3/gtk.LabelNew(0x45a1910, 0x4, 0x0, 0x0, 0x0)
    /Users/Edward/Dropbox/Studie/2015-2016/Blok4/SoftwareConstruction/multi-ql/EdwardPoot/src/github.com/gotk3/gotk3/gtk/label.go:49 +0x82 fp=0xc8200d93b0 sp=0xc8200d9378
ql/gui.CreateLabel(0xc82009c0e1, 0x1d, 0x50)

Make everything interface based to facilitate testing

When doing unit testing, the gotk3 package is a bit problematic - it is large and compiles slowly, and it builds real GUIs on the screen.

My proposal is that in order to facilitate testing, we make use of Golang interfaces - we publish interfaces in a different package, such as gotk3/gtk/interfaces - and then use these interfaces instead of the real names of the types. We make all the top level functions part of interfaces as well. In that way, you can mock out the whole gtk subsystem in tests if you want to. We could also supply empty mock implementations of all interfaces, but that's less urgent.

There shouldn't be a noticeable performance impact from this - doing interface dispatch in golang is fairly efficient when there is only one implementor around.

The initial effort to make this happen would be large, but if this is something the team thinks would be good, I'm fine with doing it. The ongoing effort is small - just make sure every time we change the signature or add a method we also add it to the corresponding interface.

Thoughts?

Bindings for g_menu_item_set_attribute_value function

Are there any plans to implement g_menu_item_set_attribute_value and their friends in glib.GMenuItem and glib.GMenu?

I've also looked around for other usages of functions that work with GVariant, but none of them are implemented, and while I could add those functions to glib.GMenuItem and glib.GMenu, the lack of GVariant examples prevents me to do so...

Can't get RadioButton work ok, it always hangs my program.

This code works ok with conformal/gtk but hangs with gotk3/gtk
In both cases compilation occurs fine.
Tested in OS X and Archlinux

package main

import (
    "github.com/gotk3/gotk3/glib"
    "github.com/gotk3/gotk3/gtk"
    //"github.com/conformal/gotk3/glib"
    //"github.com/conformal/gotk3/gtk"  
)

func main() {

    gtk.Init(nil)
    win := window()
    win.ShowAll()
    gtk.Main()

}

func window() *gtk.Window {     
    win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
    win.SetBorderWidth(8)
    win.SetSizeRequest(240, 80)
    win.SetPosition(gtk.WIN_POS_CENTER)
    win.SetTitle("Radio Buttons")
    win.Connect("destroy", func() {
        gtk.MainQuit()
    })

    var buttonL *glib.SList 
    button1, _ := gtk.RadioButtonNewWithLabel(buttonL, "First Button")
    button2, _ := gtk.RadioButtonNewWithLabelFromWidget(button1, "Second Button")

    vbox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
    vbox.Add(button1)
    vbox.Add(button2)

    win.Add(vbox)
    return win  

}

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x40c1301]

goroutine 1 [running]:
github.com/gotk3/gotk3/gtk.RadioButtonNewWithLabel(0x0, 0x442c750, 0xc, 0x0, 0x0, 0x0)
/Users/bdaemon/code/go/src/github.com/gotk3/gotk3/gtk/gtk.go:6576 +0x31
main.window(0x0)
/Users/bdaemon/code/go/src/_gtk_radiobutton_bis/main.go:32 +0x137
main.main()
/Users/bdaemon/code/go/src/_gtk_radiobutton_bis/main.go:14 +0x25

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1696 +0x1

Vertical orientation for ProgressBar (incl. patch)

GTK3 ProgressBars support GtkOrientable in order to produce vertical progress bars or "fillbars" to show some fill level, buffer fill level, memory fill level or similar.

Unfortunately, this is not wrapped in gotk3.

Patch follows:

  1. Open gotk3/gtk/gtk.go.

  2. Add Orientable interface to ProgressBar. Change:

    // ProgressBar is a representation of GTK's GtkProgressBar.
    type ProgressBar struct {
    	Widget
    }
    

to

```
// ProgressBar is a representation of GTK's GtkProgressBar.
type ProgressBar struct {
	Widget

	// Interfaces
	Orientable
}
```

in a fashion similar to (what I used as template)

```
type Grid struct {
	Container

	// Interfaces
	Orientable
}
```
  1. Change:

    func wrapProgressBar(obj *glib.Object) *ProgressBar {
    	return &ProgressBar{Widget{glib.InitiallyUnowned{obj}}}
    }
    

to

```
func wrapProgressBar(obj *glib.Object) *ProgressBar {
	o := wrapOrientable(obj)
	return &ProgressBar{Widget{glib.InitiallyUnowned{obj}}, *o}
}
```

in a fashion similar to

```
func wrapGrid(obj *glib.Object) *Grid {
	o := wrapOrientable(obj)
	return &Grid{Container{Widget{glib.InitiallyUnowned{obj}}}, *o}
}
```

just without the Container{}, because ProgressBar is not a container.

  1. Recompile your gotk3-based application, which will also re-compile gotk3/gtk.

Pixbuf memory leak

I like your project and I try to apply it to build an application. But it looks like the Pixbuf library does not work well, I checked and get a lot of memory leak.

HeaderBar

Hey guys,

thank you for the awesome work you are doing and please do not read this as a complaint, but more like a lack of understanding question.

I am learning GO and wanted to build a simple Note gui. I was looking at the Header struct and i wanted to add some buttons on it. The thing is that it does not render as a HeaderBar, but as normal grid box inside the app. What I mean is below :

What it should be :

screenshot from 2017-07-05 13 57 43

What Im getting :

screenshot from 2017-07-05 13 58 38

The "ds" button and the label should be in the header as in the first screenshot.

Here is my code :

screenshot from 2017-07-05 14 00 57

Is this the intention ? Am I missing something ?

FileChooser dialog setting select multiple

Is there a way to allow selecting multiple files from the FileChooserDialog (New, NewWith1Button, NewWith2Buttons)?
If this feature is currently missing, it'd be great to have something like

dialog.SetSelectMultiple(true)

Menubar/Menu questions

To create the menus (File, edit, etc) for a menubar, you use MenuNew() for the menu, MenuItemNewWithLabel() for the text header (ie. File) and then add menu items to the menu.

However to attach the menu to the menubar, (in C) you use gtk_menu_shell_append, which is a method in MenuNew's parent (in go = func (v *MenuShell) Append(child IMenuItem)). How do you get MenuShell from Menu?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.