[gtk] webkit.webviev in notebook

Hello everyone

package main
import (
“github_com/mattn/go-webkit/webkit”
“github_com/conformal/gotk3/gtk”
)
func main() {
gtk.Init(nil)
win,:=gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
win.Connect(“destroy”,func(){gtk.MainQuit()})
nbt,
:=gtk.NotebookNew()
wv:=webkit.NewWebView()
wv.LoadUri(“http://www.google.fr”)
lab,_:=gtk.LabelNew(“google”)
nbt.AppendPage(wv,lab)
win.Add(nbt)
win.ShowAll()
gtk.Main()
}

gives the error

./test.go:14: cannot use wv (type *webkit.WebView)
as type “github_com/conformal/gotk3/gtk”.IWidget in argument
to nbt.AppendPage: *webkit.WebView does not implement
"github_com/conformal/gotk3/gtk".IWidget
(missing “github_com/conformal/gotk3/gtk”.toWidget method)

replace github_com by github.com ( question rejected otherwise )
same with other packages
how to do ?
thank you in advance

The error message says that wv (of type webkit.WebView) does not implement gtk.IWidget.

gtk.IWidget is an interface type that declares one method:

type IWidget interface {
	toWidget() *C.GtkWidget
}

The type webkit.WebView cannot implement this interface for two reasons:

  1. The method toWidget() is not exported (note that it begins with a lowercase letter!), hence it is not visible outside the package where it is declared.
  2. webkit.WebView() would have to know about the type C.GtkWidget to be able to implement the toWidget() method. However, mattn/go-webkit does not import conformal/gogtk3/gtk, and therefore webkit.WebView() cannot possibly implement the interface.

I noticed that the go-widget package uses its own GTK package, github.com/mattn/go-gtk - maybe you need to use that one instead of conformal/gotk3/gtk (although I bet that the API’s of the two are quite different).

1 Like

thank you very much, with github.com/mattn/go-gtk it works

Thanks for the feedback! Glad to hear you got it working.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.