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() }
func main() { gtk.Init(&os.Args) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle("Arrow Buttons") window.Connect("destroy", gtk.MainQuit) box := gtk.NewHBox(false, 0) box.Show() window.Add(box) up := createArrowButton(gtk.ARROW_UP, gtk.SHADOW_IN) down := createArrowButton(gtk.ARROW_DOWN, gtk.SHADOW_OUT) left := createArrowButton(gtk.ARROW_LEFT, gtk.SHADOW_ETCHED_IN) right := createArrowButton(gtk.ARROW_RIGHT, gtk.SHADOW_ETCHED_OUT) box.PackStart(up, false, false, 3) box.PackStart(down, false, false, 3) box.PackStart(left, false, false, 3) box.PackStart(right, false, false, 3) up.Clicked(func() { println("↑") }) down.Clicked(func() { println("↓") }) left.Clicked(func() { println("←") }) right.Clicked(func() { println("→") }) window.Show() gtk.Main() }
func main() { gtk.Init(&os.Args) glib.SetApplicationName("go-gtk-statusicon-example") mi := gtk.NewMenuItemWithLabel("Popup!") mi.Connect("activate", func() { gtk.MainQuit() }) nm := gtk.NewMenu() nm.Append(mi) nm.ShowAll() si := gtk.NewStatusIconFromStock(gtk.STOCK_FILE) si.SetTitle("StatusIcon Example") si.SetTooltipMarkup("StatusIcon Example") si.Connect("popup-menu", func(cbx *glib.CallbackContext) { nm.Popup(nil, nil, gtk.StatusIconPositionMenu, si, uint(cbx.Args(0)), uint(cbx.Args(1))) }) println(` Can you see statusicon in systray? If you don't see it and if you use 'unity', try following. # gsettings set com.canonical.Unity.Panel systray-whitelist \ "$(gsettings get com.canonical.Unity.Panel systray-whitelist \| sed -e "s/]$/, 'go-gtk-statusicon-example']/")" `) gtk.Main() }
func main() { gtk.Init(nil) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("Click me") label := gtk.Label("There have been no clicks yet") var clicks int button := gtk.ButtonWithLabel("click me") button.Clicked(func() { clicks++ if clicks == 1 { label.SetLabel("Button clicked 1 time") } else { label.SetLabel(fmt.Sprintf("Button clicked %d times", clicks)) } }) vbox := gtk.VBox(false, 1) vbox.Add(label) vbox.Add(button) window.Add(vbox) window.Connect("destroy", func() { gtk.MainQuit() }) window.ShowAll() gtk.Main() }
func board_display() { gtk.Init(&os.Args) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetPosition(gtk.WIN_POS_CENTER) window.SetTitle("Gomoku") window.SetResizable(false) window.Connect("destroy", gtk.MainQuit) player = 1 game = Gomoku{make([]int, 361), true, false, false, 1, [2]int{10, 10}, 0} vbox := gtk.NewVBox(false, 1) menu_bar(vbox) configure_board(vbox) status_bar(vbox) hintx, hinty, lastx, lasty = -1, -1, -1, -1 go calc_hint() window.Add(vbox) window.SetSizeRequest(WIDTH+40, HEIGHT+50) window.ShowAll() gtk.Main() }
func main() { gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetPosition(gtk.WIN_POS_CENTER) window.SetTitle("Hello GTK+Go world!") window.SetIconName("gtk-dialog-info") window.Connect("destroy", func(ctx *glib.CallbackContext) { gtk.MainQuit() }, "foo") vbox := gtk.NewVBox(false, 1) button := gtk.NewButtonWithLabel("Hello world!") button.SetTooltipMarkup("Say Hello World to everybody!") button.Clicked(func() { messagedialog := gtk.NewMessageDialog( button.GetTopLevelAsWindow(), gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Hello!") messagedialog.Response(func() { messagedialog.Destroy() }) messagedialog.Run() }) vbox.PackStart(button, false, false, 0) window.Add(vbox) window.SetSizeRequest(300, 50) window.ShowAll() gtk.Main() }
func initWebView() *webkit.WebView { gtk.Init(nil) webview := webkit.NewWebView() webview.Connect("load-error", func() { fmt.Printf("Load Error: %s\n", webview.GetUri()) }) webview.Connect("onload-event", func() { fmt.Printf("Onload Event: %s\n", webview.GetUri()) }) webview.Connect("resource-load-finished", func(wv interface{}) { fmt.Printf("Resource Load Finished: %v\n", wv) }) webview.Connect("load-committed", func() { //entry.SetText(webview.GetUri()) fmt.Printf("Load Committed: %s\n", webview.GetUri()) }) webview.Connect("load-finished", func() { //entry.SetText(webview.GetUri()) fmt.Printf("Load Finished: %s\n", webview.GetUri()) //time.Sleep(time.Second) title := webview.GetTitle() webview.ExecuteScript("document.title=document.documentElement.innerHTML") str := webview.GetTitle() webview.ExecuteScript("document.title=" + title) fmt.Printf("Html: %s\n", str) gtk.MainQuit() }) webview.LoadHtmlString(HTML_STRING, ".") gtk.Main() return webview }
func main() { gtk.Init(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.Connect("delete-event", func() { println("Delete-event occured\n") }) window.Connect("destroy", func() { gtk.MainQuit() }) button := gtk.ButtonWithLabel("Hello, World") button.Clicked(func() { println("Hello, World\n") }) button.Clicked(func() { gtk.MainQuit() }) window.Add(button) window.ShowAll() gtk.Main() }
func main() { gtk.Init(&os.Args) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle("GTK Icon View") window.Connect("destroy", gtk.MainQuit) swin := gtk.NewScrolledWindow(nil, nil) store := gtk.NewListStore(gdkpixbuf.GetType(), glib.G_TYPE_STRING) iconview := gtk.NewIconViewWithModel(store) iconview.SetPixbufColumn(0) iconview.SetTextColumn(1) swin.Add(iconview) gtk.StockListIDs().ForEach(func(d unsafe.Pointer, v interface{}) { id := glib.GPtrToString(d) var iter gtk.TreeIter store.Append(&iter) store.Set(&iter, gtk.NewImage().RenderIcon(id, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf, id) }) window.Add(swin) window.SetSizeRequest(500, 200) window.ShowAll() gtk.Main() }
func main() { gtk.Init(&os.Args) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle("GTK Notebook") window.Connect("destroy", gtk.MainQuit) notebook := gtk.NewNotebook() for n := 1; n <= 10; n++ { page := gtk.NewFrame("demo" + strconv.Itoa(n)) notebook.AppendPage(page, gtk.NewLabel("demo"+strconv.Itoa(n))) vbox := gtk.NewHBox(false, 1) prev := gtk.NewButtonWithLabel("go prev") prev.Clicked(func() { notebook.PrevPage() }) vbox.Add(prev) next := gtk.NewButtonWithLabel("go next") next.Clicked(func() { notebook.NextPage() }) vbox.Add(next) page.Add(vbox) } window.Add(notebook) window.SetSizeRequest(400, 200) window.ShowAll() gtk.Main() }
func main() { gtk.Init(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("GTK Stock Icons") window.Connect("destroy", gtk.MainQuit) swin := gtk.ScrolledWindow(nil, nil) store := gtk.ListStore(glib.G_TYPE_STRING, glib.G_TYPE_BOOL, gdkpixbuf.GetGdkPixbufType()) treeview := gtk.TreeView() swin.Add(treeview) treeview.SetModel(store.ToTreeModel()) treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("name", gtk.CellRendererText(), "text", 0)) treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("check", gtk.CellRendererToggle(), "active", 1)) treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("icon", gtk.CellRendererPixbuf(), "pixbuf", 2)) n := 0 gtk.GtkStockListIDs().ForEach(func(d interface{}, v interface{}) { id := glib.GPtrToString(d) var iter gtk.GtkTreeIter store.Append(&iter) store.Set(&iter, id, (n == 1), gtk.Image().RenderIcon(id, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf) n = 1 - n }) window.Add(swin) window.SetSizeRequest(400, 200) window.ShowAll() gtk.Main() }
func showLogin() { window := gtk.Window(gtk.GTK_WINDOW_POPUP) window.Connect("destroy", gtk.MainQuit) window.SetSizeRequest() window.ShowAll() gtk.Main() }
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() }
func main() { mc := memcache.New("127.0.0.1:11211") gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle("memcachedclient") window.Connect("destroy", gtk.MainQuit) vbox := gtk.NewVBox(false, 1) swin := gtk.NewScrolledWindow(nil, nil) textview := gtk.NewTextView() textview.SetEditable(false) textview.SetCursorVisible(false) textview.ModifyFontEasy("monospace 12") swin.Add(textview) vbox.Add(swin) buffer := textview.GetBuffer() input := gtk.NewEntry() input.SetEditable(true) vbox.PackEnd(input, false, false, 0) tag := buffer.CreateTag("red", map[string]string{"foreground": "#FF0000"}) input.Connect("activate", func() { var iter gtk.TextIter tokens := strings.SplitN(input.GetText(), " ", 3) if len(tokens) == 2 && strings.ToUpper(tokens[0]) == "GET" { if t, err := mc.Get(tokens[1]); err == nil { buffer.GetEndIter(&iter) buffer.Insert(&iter, string(t.Value)+"\n") } else { buffer.InsertWithTag(&iter, err.Error()+"\n", tag) } input.SetText("") } else if len(tokens) == 3 && strings.ToUpper(tokens[0]) == "SET" { if err := mc.Set( &memcache.Item{ Key: tokens[1], Value: []byte(tokens[2]), }); err == nil { buffer.GetEndIter(&iter) buffer.InsertWithTag(&iter, "OK\n", tag) } else { buffer.InsertWithTag(&iter, err.Error()+"\n", tag) } input.SetText("") } }) input.GrabFocus() window.Add(vbox) window.SetSizeRequest(300, 500) window.ShowAll() gtk.Main() }
func main() { gtk.Init(nil) gdk.ThreadsInit() MainGui.buildSplash() MainGui.buildGUI() MainGui.SplashWindow.ShowAll() go unlinked_main() gtk.Main() }
func main() { if false == init_args() { return } load_options() defer save_options() gtk.Init(nil) init_tabby() gtk.Main() }
func main() { gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetPosition(gtk.WIN_POS_CENTER) window.SetTitle("Hello world!") window.SetIconName("Hello go!") window.Connect("destroy", gtk.MainQuit) window.SetSizeRequest(800, 800) window.ShowAll() gtk.Main() }
func main() { gtk.Init(nil) window := CreateWindow() window.SetPosition(gtk.WIN_POS_CENTER) window.Connect("destroy", func(ctx *glib.CallbackContext) { fmt.Println("destroy pending...") gtk.MainQuit() }, "foo") window.ShowAll() gtk.Main() }
func GetGuiController() <-chan *GuiController { controler := make(chan *GuiController, 1) go func() { gtk.Init(nil) controler <- CreateGuiController() gtk.Main() }() return controler }
func main() { FreeConsole() gtk.Init(nil) screenHeight := gdk.ScreenHeight() screenWidth := gdk.ScreenWidth() window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle("mgc") window.SetIconName("gtk-about") window.Connect("destroy", func() { gtk.MainQuit() }) vbox := gtk.NewVBox(false, 0) menubar := gtk.NewMenuBar() vbox.PackStart(menubar, false, false, 0) menu := gtk.NewMenuItemWithMnemonic("_File") menubar.Append(menu) submenu := gtk.NewMenu() menu.SetSubmenu(submenu) menuitem := gtk.NewMenuItemWithMnemonic("E_xit") menuitem.Connect("activate", func() { gtk.MainQuit() }) submenu.Append(menuitem) hpaned := gtk.NewHPaned() leftFrame := gtk.NewFrame("") rightFrame := gtk.NewFrame("") leftLabel := gtk.NewLabel("Left") rightLabel := gtk.NewLabel("Right") leftFrame.Add(leftLabel) rightFrame.Add(rightLabel) hpaned.Pack1(leftFrame, true, false) hpaned.Pack2(rightFrame, true, false) vbox.Add(hpaned) window.Add(vbox) window.SetSizeRequest(screenWidth/4*3, screenHeight/4*3) window.ShowAll() gtk.Main() }
func main() { gtk.Init(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("SourceView") window.Connect("destroy", gtk.MainQuit) swin := gtk.ScrolledWindow(nil, nil) swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC) swin.SetShadowType(gtk.GTK_SHADOW_IN) sourcebuffer := gsv.SourceBufferWithLanguage(gsv.SourceLanguageManagerGetDefault().GetLanguage("cpp")) sourceview := gsv.SourceViewWithBuffer(sourcebuffer) var start gtk.GtkTextIter sourcebuffer.GetStartIter(&start) sourcebuffer.BeginNotUndoableAction() sourcebuffer.Insert(&start, `#include <iostream> template<class T> struct foo_base { T operator+(T const &rhs) const { T tmp(static_cast<T const &>(*this)); tmp += rhs; return tmp; } }; class foo : public foo_base<foo> { private: int v; public: foo(int v) : v(v) {} foo &operator+=(foo const &rhs){ this->v += rhs.v; return *this; } operator int() { return v; } }; int main(void) { foo a(1), b(2); a += b; std::cout << (int)a << std::endl; } `) sourcebuffer.EndNotUndoableAction() swin.Add(sourceview) window.Add(swin) window.SetSizeRequest(400, 300) window.ShowAll() gtk.Main() }
func main() { gtk.Init(nil) win := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) win.SetTitle("Goodbye, World!") win.SetSizeRequest(300, 200) win.Connect("destroy", gtk.MainQuit) button := gtk.ButtonWithLabel("Goodbye, World!") win.Add(button) button.Connect("clicked", gtk.MainQuit) win.ShowAll() gtk.Main() }
func main() { gtk.Init(&os.Args) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle("GTK DrawingArea") window.Connect("destroy", gtk.MainQuit) vbox := gtk.NewVBox(true, 0) vbox.SetBorderWidth(5) targets := []gtk.TargetEntry{ {"text/uri-list", 0, 0}, {"STRING", 0, 1}, {"text/plain", 0, 2}, } dest := gtk.NewLabel("drop me file") dest.DragDestSet( gtk.DEST_DEFAULT_MOTION| gtk.DEST_DEFAULT_HIGHLIGHT| gtk.DEST_DEFAULT_DROP, targets, gdk.ACTION_COPY) dest.DragDestAddUriTargets() dest.Connect("drag-data-received", func(ctx *glib.CallbackContext) { sdata := gtk.SelectionDataFromNative(unsafe.Pointer(ctx.Args(3))) if sdata != nil { a := (*[2000]uint8)(sdata.GetData()) files := strings.Split(string(a[0:sdata.GetLength()-1]), "\n") for i := range files { filename, _, _ := glib.FilenameFromUri(files[i]) files[i] = filename } dialog := gtk.NewMessageDialog( window, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, strings.Join(files, "\n")) dialog.SetTitle("D&D") dialog.Response(func() { dialog.Destroy() }) dialog.Run() } }) vbox.Add(dest) window.Add(vbox) window.SetSizeRequest(300, 100) window.ShowAll() gtk.Main() }
func main() { gtk.Init(&os.Args) builder := gtk.Builder() builder.AddFromFile("hello.ui") builder.ConnectSignals(nil) obj := builder.GetObject("window1") window := gtk.WidgetFromObject(obj) window.Show() window.Connect("destroy", gtk.MainQuit) gtk.Main() }
func main() { gdk.ThreadsInit() if false == init_args() { return } load_options() defer save_options() gdk.ThreadsEnter() gtk.Init(nil) init_tabby() gtk.Main() }
func main() { glib.ThreadInit(nil) gdk.ThreadsInit() gdk.ThreadsEnter() gtk.Init(nil) gui := new(GUI) gui.Init() gui.Show() gtk.Main() gdk.ThreadsLeave() }
func mwain() { flag.Parse() gtk.Init(nil) webkit.InitWebKit() go gtk.Main() http.Handle("/grab", http.HandlerFunc(doGrab)) err := http.ListenAndServe(*addr, nil) if err != nil { log.Fatal("ListenAndServe:", err) } }
func main() { gtk.Init(&os.Args) window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) window.SetTitle("GTK Folder View") window.Connect("destroy", gtk.MainQuit) swin := gtk.NewScrolledWindow(nil, nil) store := gtk.NewTreeStore(gdkpixbuf.GetGdkPixbufType(), glib.G_TYPE_STRING) treeview := gtk.NewTreeView() swin.Add(treeview) treeview.SetModel(store.ToTreeModel()) treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("pixbuf", gtk.NewCellRendererPixbuf(), "pixbuf", 0)) treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("text", gtk.NewCellRendererText(), "text", 1)) for n := 1; n <= 10; n++ { var iter1, iter2, iter3 gtk.TreeIter store.Append(&iter1, nil) store.Set(&iter1, gtk.NewImage().RenderIcon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "Folder"+strconv.Itoa(n)) store.Append(&iter2, &iter1) store.Set(&iter2, gtk.NewImage().RenderIcon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "SubFolder"+strconv.Itoa(n)) store.Append(&iter3, &iter2) store.Set(&iter3, gtk.NewImage().RenderIcon(gtk.STOCK_FILE, gtk.ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "File"+strconv.Itoa(n)) } treeview.Connect("row_activated", func() { var path *gtk.TreePath var column *gtk.TreeViewColumn treeview.GetCursor(&path, &column) mes := "TreePath is: " + path.String() dialog := gtk.NewMessageDialog( treeview.GetTopLevelAsWindow(), gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, mes) dialog.SetTitle("TreePath") dialog.Response(func() { dialog.Destroy() }) dialog.Run() }) window.Add(swin) window.SetSizeRequest(400, 200) window.ShowAll() 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() { gtk.Init(&os.Args) // TODO: we currently assume that number of batteries at startup // never can grow (but can shrink). icons := getIcons() d, err := time.ParseDuration("20s") if err != nil { log.Fatalf("bad duration: %v\n", err) } for i := 0; i < len(icons); i++ { go poll(d, i, icons[i]) } log.Printf("Calling gtk.Main()..") gtk.Main() }