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() }
// NewBrowser returns a new browser component func NewBrowser(uri string) *Browser { vbox := gtk.NewVBox(false, 1) urlBarEntry := gtk.NewEntry() urlBarEntry.SetText(uri) urlBarEntry.GrabFocus() vbox.PackStart(urlBarEntry, false, false, 0) swin := gtk.NewScrolledWindow(nil, nil) swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin.SetShadowType(gtk.SHADOW_IN) webview := webkit.NewWebView() swin.Add(webview) vbox.Add(swin) // urlBarEntry.Connect("activate", func() { // webview.LoadUri(urlBarEntry.GetText()) // }) //return vbox browser := &Browser{ VBox: vbox, WebView: webview, URLEntry: urlBarEntry, Link: "", } browser.connectSignals() urlBarEntry.Emit("activate") return browser }
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() }
// StartBrowser launches a web browser with given url and size func StartBrowser(url string, width, height int) { gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle("gogp") window.Connect("destroy", gtk.MainQuit) swin := gtk.NewScrolledWindow(nil, nil) swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) swin.SetShadowType(gtk.SHADOW_IN) webview := webkit.NewWebView() swin.Add(webview) window.Add(swin) window.SetSizeRequest(width, height) webview.LoadUri(url) window.ShowAll() gtk.Main() }
func main() { if len(os.Args) < 2 { filename = "" } else { filename = os.Args[1] } gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle(filename) window.Connect("destroy", gtk.MainQuit) vbox := gtk.NewVBox(false, 1) menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) webview = webkit.NewWebView() vbox.Add(webview) filemenu := gtk.NewMenuItemWithMnemonic("_File") menubar.Append(filemenu) submenu := gtk.NewMenu() filemenu.SetSubmenu(submenu) menu_open := gtk.NewMenuItemWithMnemonic("_Open") menu_open.Connect("activate", func() { filechooserdialog := gtk.NewFileChooserDialog( "Choose file", window, gtk.FILE_CHOOSER_ACTION_OPEN, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT) filter := gtk.NewFileFilter() filter.AddPattern("*.md") filter.AddPattern("*.markdown") filter.SetName("Markdown files") filechooserdialog.AddFilter(filter) filechooserdialog.Response(func() { filename = (filechooserdialog.GetFilename()) filechooserdialog.Destroy() }) filechooserdialog.Run() reload() }) submenu.Append(menu_open) menu_reload = gtk.NewMenuItemWithMnemonic("_Reload") menu_reload.Connect("activate", func() { reload() }) submenu.Append(menu_reload) menu_exit = gtk.NewMenuItemWithMnemonic("E_xit") menu_exit.Connect("activate", func() { gtk.MainQuit() }) submenu.Append(menu_exit) viewmenu := gtk.NewMenuItemWithMnemonic("_View") menubar.Append(viewmenu) viewsubmenu := gtk.NewMenu() viewmenu.SetSubmenu(viewsubmenu) menu_dark := gtk.NewCheckMenuItemWithMnemonic("D_ark Theme") menu_dark.Connect("activate", func() { if menu_dark.GetActive() { dark_theme = true } else { dark_theme = false } reload() }) viewsubmenu.Append(menu_dark) window.Add(vbox) window.SetSizeRequest(480, 600) bytesSlice := bytesFromXpmData(xpm_data) icon_file := "/tmp/hackdown-icon.xpm" ioutil.WriteFile(icon_file, bytesSlice, os.ModePerm) window.SetIconFromFile(icon_file) window.ShowAll() webview.LoadString(getContent(), "text/html", "utf-8", ".") gtk.Main() }