Example #1
1
func initPage(title string, uri string, size_x int, size_y int) {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle(title)
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(false, 1)

	swin := gtk.NewScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)

	webview := webkit.NewWebView()
	webview.LoadUri(uri)
	swin.Add(webview)

	vbox.Add(swin)

	window.Add(vbox)
	window.SetSizeRequest(size_x, size_y)
	window.ShowAll()

	proxy := os.Getenv("HTTP_PROXY")
	if len(proxy) > 0 {
		soup_uri := webkit.SoupUri(proxy)
		webkit.GetDefaultSession().Set("proxy-uri", soup_uri)
		soup_uri.Free()
	}
	gtk.Main()
}
Example #2
0
func main() {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("webkit")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(false, 1)

	entry := gtk.NewEntry()
	entry.SetText("http://golang.org/")
	vbox.PackStart(entry, false, false, 0)

	swin := gtk.NewScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)

	webview := webkit.NewWebView()
	webview.Connect("load-committed", func() {
		entry.SetText(webview.GetUri())
	})
	swin.Add(webview)

	vbox.Add(swin)

	entry.Connect("activate", func() {
		webview.LoadUri(entry.GetText())
	})
	button := gtk.NewButtonWithLabel("load String")
	button.Clicked(func() {
		webview.LoadString("hello Go GTK!", "text/plain", "utf-8", ".")
	})
	vbox.PackStart(button, false, false, 0)

	button = gtk.NewButtonWithLabel("load HTML String")
	button.Clicked(func() {
		webview.LoadHtmlString(HTML_STRING, ".")
	})
	vbox.PackStart(button, false, false, 0)

	button = gtk.NewButtonWithLabel("Google Maps")
	button.Clicked(func() {
		webview.LoadHtmlString(MAP_EMBED, ".")
	})
	vbox.PackStart(button, false, false, 0)

	window.Add(vbox)
	window.SetSizeRequest(600, 600)
	window.ShowAll()

	proxy := os.Getenv("HTTP_PROXY")
	if len(proxy) > 0 {
		soup_uri := webkit.SoupUri(proxy)
		webkit.GetDefaultSession().Set("proxy-uri", soup_uri)
		soup_uri.Free()
	}
	entry.Emit("activate")
	gtk.Main()
}
Example #3
0
func setupProxy() {
	// Handle proxy
	proxy := os.Getenv("HTTP_PROXY")
	if len(proxy) > 0 {
		soupURI := webkit.SoupUri(proxy)
		webkit.GetDefaultSession().Set("proxy-uri", soupURI)
		soupURI.Free()
	}
}