func main() { gtk.Init(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("GTK Stock Icons") window.Connect("destroy", func() { gtk.MainQuit() }, nil) swin := gtk.ScrolledWindow(nil, nil) store := gtk.ListStore(gtk.TYPE_STRING, gtk.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 }, 0) window.Add(swin) window.SetSizeRequest(400, 200) window.ShowAll() gtk.Main() }
func main() { gtk.Init(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("GTK Table") window.Connect("destroy", func() { gtk.MainQuit() }, nil) swin := gtk.ScrolledWindow(nil, nil) swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC) table := gtk.Table(5, 5, false) for y := uint(0); y < 5; y++ { for x := uint(0); x < 5; x++ { table.Attach(gtk.ButtonWithLabel(fmt.Sprintf("%02d:%02d", x, y)), x, x+1, y, y+1, gtk.GTK_FILL, gtk.GTK_FILL, 5, 5) } } swin.AddWithViewPort(table) window.Add(swin) window.SetDefaultSize(200, 200) window.ShowAll() gtk.Main() }
func main() { load_options() defer save_options() gtk.Init(nil) init_tabby() gtk.Main() }
func main() { gtk.Init(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("SourceView") window.Connect("destroy", func() { gtk.MainQuit() }, nil) swin := gtk.ScrolledWindow(nil, nil) swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC) swin.SetShadowType(gtk.GTK_SHADOW_IN) sourcebuffer := gtk.SourceBuffer() sourcebuffer.SetLanguage(gtk.SourceLanguageManagerGetDefault().GetLanguage("cpp")) sourceview := gtk.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(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("GTK Folder View") window.Connect("destroy", func() { gtk.MainQuit() }, nil) swin := gtk.ScrolledWindow(nil, nil) store := gtk.TreeStore(gdkpixbuf.GetGdkPixbufType(), gtk.TYPE_STRING) treeview := gtk.TreeView() swin.Add(treeview) treeview.SetModel(store.ToTreeModel()) treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("pixbuf", gtk.CellRendererPixbuf(), "pixbuf", 0)) treeview.AppendColumn(gtk.TreeViewColumnWithAttributes("text", gtk.CellRendererText(), "text", 1)) for n := 1; n <= 10; n++ { var iter1, iter2, iter3 gtk.GtkTreeIter store.Append(&iter1, nil) store.Set(&iter1, gtk.Image().RenderIcon(gtk.GTK_STOCK_DIRECTORY, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "Folder"+strconv.Itoa(n)) store.Append(&iter2, &iter1) store.Set(&iter2, gtk.Image().RenderIcon(gtk.GTK_STOCK_DIRECTORY, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "SubFolder"+strconv.Itoa(n)) store.Append(&iter3, &iter2) store.Set(&iter3, gtk.Image().RenderIcon(gtk.GTK_STOCK_FILE, gtk.GTK_ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "File"+strconv.Itoa(n)) } treeview.Connect("row_activated", func() { var path *gtk.GtkTreePath var column *gtk.GtkTreeViewColumn treeview.GetCursor(&path, &column) mes := "TreePath is: " + path.String() dialog := gtk.MessageDialog( treeview.GetTopLevelAsWindow(), gtk.GTK_DIALOG_MODAL, gtk.GTK_MESSAGE_INFO, gtk.GTK_BUTTONS_OK, mes) dialog.SetTitle("TreePath") dialog.Response(func() { dialog.Destroy() }, nil) dialog.Run() }, nil) window.Add(swin) window.SetSizeRequest(400, 200) window.ShowAll() gtk.Main() }
func render_all(rects []Rect, m int) { gtk.Init(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("GTK DrawingArea") window.Connect("destroy", func() { gtk.MainQuit() }, nil) vbox := gtk.VBox(true, 0) vbox.SetBorderWidth(5) drawingarea = gtk.DrawingArea() var pixmap *gdk.GdkPixmap drawingarea.Connect("configure-event", func() { if pixmap != nil { pixmap.Unref() } var allocation gtk.GtkAllocation drawingarea.GetAllocation(&allocation) draw = drawingarea.GetWindow().GetDrawable() pixmap = gdk.Pixmap(drawingarea.GetWindow().GetDrawable(), allocation.Width, allocation.Height, 24) gc = gdk.GC(pixmap.GetDrawable()) gc.SetRgbFgColor(gdk.Color("white")) pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1) gc.SetRgbFgColor(gdk.Color("black")) gc.SetRgbBgColor(gdk.Color("white")) }, nil) drawingarea.Connect("expose-event", func() { if pixmap != nil { drawingarea.GetWindow().GetDrawable().DrawDrawable(gc, pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1) } draw_all(rects, m) }, nil) vbox.Add(drawingarea) window.Add(vbox) window.Maximize() window.ShowAll() gtk.Main() }
func main() { callback.Init() gtk.Init(&os.Args) builder := gtk.Builder() builder.AddFromFile("hello.ui", nil) builder.ConnectSignals(nil) obj := builder.GetObject("window1") window := gtk.WidgetFromObject(obj) window.Show() window.Connect("destroy", func() { gtk.MainQuit() }, nil) gtk.Main() }
func main() { gtk.Init(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("We love Expander") window.Connect("destroy", func() { gtk.MainQuit() }, nil) vbox := gtk.VBox(true, 0) vbox.SetBorderWidth(5) expander := gtk.Expander("dan the ...") expander.Add(gtk.Label("404 contents not found")) vbox.PackStart(expander, false, false, 0) window.Add(vbox) window.ShowAll() gtk.Main() }
func main() { runtime.GOMAXPROCS(10) gdk.ThreadsInit() gdk.ThreadsEnter() gtk.Init(nil) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.Connect("destroy", func() { gtk.MainQuit() }, nil) vbox := gtk.VBox(false, 1) label1 := gtk.Label("") vbox.Add(label1) label2 := gtk.Label("") vbox.Add(label2) window.Add(vbox) window.SetSizeRequest(100, 100) window.ShowAll() syscall.Sleep(1000 * 1000 * 100) go (func() { for i := 0; i < 300000; i++ { gdk.ThreadsEnter() label1.SetLabel(strconv.Itoa(i)) gdk.ThreadsLeave() } gtk.MainQuit() })() go (func() { for i := 300000; i >= 0; i-- { gdk.ThreadsEnter() label2.SetLabel(strconv.Itoa(i)) gdk.ThreadsLeave() } gtk.MainQuit() })() gtk.Main() }
func main() { gtk.Init(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("GTK Notebook") window.Connect("destroy", func() { gtk.MainQuit() }, nil) notebook := gtk.Notebook() for n := 1; n <= 10; n++ { page := gtk.Frame("demo" + strconv.Itoa(n)) notebook.AppendPage(page, gtk.Label("demo"+strconv.Itoa(n))) vbox := gtk.HBox(false, 1) prev := gtk.ButtonWithLabel("go perv") prev.Clicked(func() { notebook.PrevPage() }, nil) vbox.Add(prev) next := gtk.ButtonWithLabel("go next") next.Clicked(func() { notebook.NextPage() }, nil) vbox.Add(next) page.Add(vbox) } window.Add(notebook) window.SetSizeRequest(400, 200) window.ShowAll() gtk.Main() }
func main() { gtk.Init(os.Args) win := gtk.NewWindow(gtk.WINDOW_TOPLEVEL) win.Connect("destroy", func() { gtk.MainQuit() }) s := fmt.Sprintf("Gtk Version %d.%d.%d", gtk.GetMajorVersion(), gtk.GetMinorVersion(), gtk.GetMicroVersion()) win.SetTitle(s) win.SetDefaultSize(100, 100) cn := gtk.ToContainer(unsafe.Pointer(win.CType())) cn.SetBorderWidth(10) // cn.SetResizeMode(gtk.RESIZE_PARENT) gr := gtk.NewGrid() cn.Add(gtk.ToWidget(unsafe.Pointer(gr.CType()))) bt := gtk.NewButtonWithLabel("Button") bt.Connect("clicked", func() { println("Hello World") }) gr.Attach(gtk.ToWidget(unsafe.Pointer(bt.CType())), 0, 0, 1, 1) bt1 := gtk.NewButtonWithLabel("Button1") bt1.Connect("clicked", print_hello) gr.Attach(gtk.ToWidget(unsafe.Pointer(bt1.CType())), 1, 0, 1, 1) bt2 := gtk.NewButtonWithLabel("Quit") bt2.Connect("clicked", gtk.MainQuit) gr.Attach(gtk.ToWidget(unsafe.Pointer(bt2.CType())), 0, 1, 2, 1) gr.SetColumnHomogeneous(true) gr.SetRowHomogeneous(true) gr.SetColumnSpacing(10) gr.SetRowSpacing(5) win.ShowAll() gtk.Main() }
func main() { gtk.Init(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("GTK DrawingArea") window.Connect("destroy", func() { gtk.MainQuit() }, nil) vbox := gtk.VBox(true, 0) vbox.SetBorderWidth(5) drawingarea := gtk.DrawingArea() var p1, p2 point var mt uint var gdkwin *gdk.GdkWindow var pixmap *gdk.GdkPixmap var gc *gdk.GdkGC p1.x = -1 p1.y = -1 drawingarea.Connect("configure-event", func() { if pixmap != nil { pixmap.Unref() } var allocation gtk.GtkAllocation drawingarea.GetAllocation(&allocation) pixmap = gdk.Pixmap(drawingarea.GetWindow().GetDrawable(), allocation.Width, allocation.Height, 24) gc = gdk.GC(pixmap.GetDrawable()) gc.SetRgbFgColor(gdk.Color("white")) pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1) gc.SetRgbFgColor(gdk.Color("black")) gc.SetRgbBgColor(gdk.Color("white")) }, nil) drawingarea.Connect("motion-notify-event", func() { if gdkwin == nil { gdkwin = drawingarea.GetWindow() } gdkwin.GetPointer(&p2.x, &p2.y, &mt) if p1.x != -1 && p2.x != -1 && (mt&gdk.GDK_BUTTON_PRESS_MASK) != 0 { pixmap.GetDrawable().DrawLine(gc, p1.x, p1.y, p2.x, p2.y) drawingarea.GetWindow().Invalidate(nil, false) } p1 = p2 }, nil) drawingarea.Connect("expose-event", func() { if pixmap != nil { drawingarea.GetWindow().GetDrawable().DrawDrawable(gc, pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1) } }, nil) drawingarea.SetEvents(gdk.GDK_POINTER_MOTION_MASK | gdk.GDK_POINTER_MOTION_HINT_MASK | gdk.GDK_BUTTON_PRESS_MASK) vbox.Add(drawingarea) window.Add(vbox) window.SetSizeRequest(400, 400) window.ShowAll() gtk.Main() }
func main() { gtk.Init(nil) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("GTK Go!") window.Connect("destroy", func(w *gtk.GtkWidget, user_data string) { println("got destroy!", user_data) gtk.MainQuit() }, "foo") //-------------------------------------------------------- // GtkVBox //-------------------------------------------------------- vbox := gtk.VBox(false, 1) //-------------------------------------------------------- // GtkMenuBar //-------------------------------------------------------- menubar := gtk.MenuBar() vbox.PackStart(menubar, false, false, 0) //-------------------------------------------------------- // GtkMenuItem //-------------------------------------------------------- filemenu := gtk.MenuItemWithMnemonic("_File") menubar.Append(filemenu) filesubmenu := gtk.Menu() filemenu.SetSubmenu(filesubmenu) exitmenuitem := gtk.MenuItemWithMnemonic("E_xit") exitmenuitem.Connect("activate", func() { gtk.MainQuit() }, nil) filesubmenu.Append(exitmenuitem) filemenu = gtk.MenuItemWithMnemonic("_Help") menubar.Append(filemenu) filesubmenu = gtk.Menu() filemenu.SetSubmenu(filesubmenu) exitmenuitem = gtk.MenuItemWithMnemonic("_About") exitmenuitem.Connect("activate", func() { dialog := gtk.AboutDialog() dialog.SetName("Go-Gtk Demo!") dialog.SetProgramName("demo") dialog.SetAuthors([]string{ "Yasuhiro Matsumoto <*****@*****.**>", "David Roundy <*****@*****.**>"}) dir, _ := path.Split(os.Args[0]) imagefile := path.Join(dir, "../../data/mattn-logo.png") pixbuf, _ := gdkpixbuf.PixbufFromFile(imagefile) dialog.SetLogo(pixbuf) dialog.SetLicense("The library is available under the same terms and conditions as the Go, the BSD style license, and the LGPL (Lesser GNU Public License). The idea is that if you can use Go (and Gtk) in a project, you should also be able to use go-gtk.") dialog.SetWrapLicense(true) dialog.Run() dialog.Destroy() }, nil) filesubmenu.Append(exitmenuitem) //-------------------------------------------------------- // GtkVPaned //-------------------------------------------------------- vpaned := gtk.VPaned() vbox.Add(vpaned) //-------------------------------------------------------- // GtkFrame //-------------------------------------------------------- frame1 := gtk.Frame("Demo") framebox1 := gtk.VBox(false, 1) frame1.Add(framebox1) frame2 := gtk.Frame("Demo") framebox2 := gtk.VBox(false, 1) frame2.Add(framebox2) vpaned.Add1(frame1) vpaned.Add2(frame2) //-------------------------------------------------------- // GtkImage //-------------------------------------------------------- dir, _ := path.Split(os.Args[0]) imagefile := path.Join(dir, "../../data/go-gtk-logo.png") label := gtk.Label("Go Binding for GTK") label.ModifyFontEasy("DejaVu Serif 15") framebox1.PackStart(label, false, true, 0) entry := gtk.Entry() entry.SetText("Hello world") framebox1.Add(entry) image := gtk.ImageFromFile(imagefile) framebox1.Add(image) //-------------------------------------------------------- // GtkScale //-------------------------------------------------------- scale := gtk.HScaleWithRange(0, 100, 1) scale.Connect("value-changed", func() { print("scale: ", int(scale.GetValue()), "\n") }, nil) framebox2.Add(scale) //-------------------------------------------------------- // GtkHBox //-------------------------------------------------------- buttons := gtk.HBox(false, 1) //-------------------------------------------------------- // GtkButton //-------------------------------------------------------- button := gtk.ButtonWithLabel("Button with label") button.Clicked(func() { print("button clicked: ", button.GetLabel(), "\n") messagedialog := gtk.MessageDialog( button.GetTopLevelAsWindow(), gtk.GTK_DIALOG_MODAL, gtk.GTK_MESSAGE_INFO, gtk.GTK_BUTTONS_OK, entry.GetText()) messagedialog.Response(func() { println("Dialog OK!") //-------------------------------------------------------- // GtkFileChooserDialog //-------------------------------------------------------- filechooserdialog := gtk.FileChooserDialog( "Choose File...", button.GetTopLevelAsWindow(), gtk.GTK_FILE_CHOOSER_ACTION_OPEN, gtk.GTK_STOCK_OK) filechooserdialog.Response(func() { println(filechooserdialog.GetFilename()) filechooserdialog.Destroy() }, nil) filechooserdialog.Run() }, nil) messagedialog.Run() messagedialog.Destroy() }, nil) buttons.Add(button) //-------------------------------------------------------- // GtkFontButton //-------------------------------------------------------- fontbutton := gtk.FontButton() fontbutton.Connect("font-set", func() { print("title: ", fontbutton.GetTitle(), "\n") print("fontname: ", fontbutton.GetFontName(), "\n") print("use_size: ", fontbutton.GetUseSize(), "\n") print("show_size: ", fontbutton.GetShowSize(), "\n") }, nil) buttons.Add(fontbutton) framebox2.PackStart(buttons, false, false, 0) buttons = gtk.HBox(false, 1) //-------------------------------------------------------- // GtkToggleButton //-------------------------------------------------------- togglebutton := gtk.ToggleButtonWithLabel("ToggleButton with label") togglebutton.Connect("toggled", func() { if togglebutton.GetActive() { togglebutton.SetLabel("ToggleButton ON!") } else { togglebutton.SetLabel("ToggleButton OFF!") } }, nil) buttons.Add(togglebutton) //-------------------------------------------------------- // GtkCheckButton //-------------------------------------------------------- checkbutton := gtk.CheckButtonWithLabel("CheckButton with label") checkbutton.Connect("toggled", func() { if checkbutton.GetActive() { checkbutton.SetLabel("CheckButton CHECKED!") } else { checkbutton.SetLabel("CheckButton UNCHECKED!") } }, nil) buttons.Add(checkbutton) //-------------------------------------------------------- // GtkRadioButton //-------------------------------------------------------- buttonbox := gtk.VBox(false, 1) radiofirst := gtk.RadioButtonWithLabel(nil, "Radio1") buttonbox.Add(radiofirst) buttonbox.Add(gtk.RadioButtonWithLabel(radiofirst.GetGroup(), "Radio2")) buttonbox.Add(gtk.RadioButtonWithLabel(radiofirst.GetGroup(), "Radio3")) buttons.Add(buttonbox) //radiobutton.SetMode(false); radiofirst.SetActive(true) framebox2.PackStart(buttons, false, false, 0) //-------------------------------------------------------- // GtkComboBoxEntry //-------------------------------------------------------- combos := gtk.HBox(false, 1) comboboxentry := gtk.ComboBoxEntryNewText() comboboxentry.AppendText("Monkey") comboboxentry.AppendText("Tiger") comboboxentry.AppendText("Elephant") comboboxentry.Connect("changed", func() { print("value: ", comboboxentry.GetActiveText(), "\n") }, nil) combos.Add(comboboxentry) //-------------------------------------------------------- // GtkComboBox //-------------------------------------------------------- combobox := gtk.ComboBoxNewText() combobox.AppendText("Peach") combobox.AppendText("Banana") combobox.AppendText("Apple") combobox.SetActive(1) combobox.Connect("changed", func() { print("value: ", combobox.GetActiveText(), "\n") }, nil) combos.Add(combobox) framebox2.PackStart(combos, false, false, 0) //-------------------------------------------------------- // GtkTextView //-------------------------------------------------------- swin := gtk.ScrolledWindow(nil, nil) swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC) swin.SetShadowType(gtk.GTK_SHADOW_IN) textview := gtk.TextView() var start, end gtk.GtkTextIter buffer := textview.GetBuffer() buffer.GetStartIter(&start) buffer.Insert(&start, "Hello ") buffer.GetEndIter(&end) buffer.Insert(&end, "World!") tag := buffer.CreateTag("bold", map[string]string{ "background": "#FF0000", "weight": "700"}) buffer.GetStartIter(&start) buffer.GetEndIter(&end) buffer.ApplyTag(tag, &start, &end) swin.Add(textview) framebox2.Add(swin) //-------------------------------------------------------- // GtkStatusbar //-------------------------------------------------------- statusbar := gtk.Statusbar() context_id := statusbar.GetContextId("go-gtk") statusbar.Push(context_id, "GTK binding for Go!") framebox2.PackStart(statusbar, false, false, 0) //-------------------------------------------------------- // Event //-------------------------------------------------------- window.Add(vbox) window.SetSizeRequest(600, 600) window.ShowAll() gtk.Main() }
func main() { gtk.Init(&os.Args) display = gtk.Entry() window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("Simple Go Calculator") window.Connect("destroy", Quit, nil) // Vertical box containing all components vbox := gtk.VBox(false, 1) // Menu bar menubar := gtk.MenuBar() vbox.PackStart(menubar, false, false, 0) // Add calculator display to vertical box display.SetCanFocus(false) // disable focus on calcuator display vbox.Add(display) // Menu items filemenu := gtk.MenuItemWithMnemonic("_File") menubar.Append(filemenu) filesubmenu := gtk.Menu() filemenu.SetSubmenu(filesubmenu) aboutmenuitem := gtk.MenuItemWithMnemonic("_About") aboutmenuitem.Connect("activate", func() { messagedialog := gtk.MessageDialog( window.GetTopLevelAsWindow(), gtk.GTK_DIALOG_MODAL, gtk.GTK_MESSAGE_INFO, gtk.GTK_BUTTONS_OK, "Simple Go Calculator") messagedialog.Response(func() {}, nil) messagedialog.Run() messagedialog.Destroy() }, nil) filesubmenu.Append(aboutmenuitem) resetmenuitem := gtk.MenuItemWithMnemonic("_Reset") resetmenuitem.Connect("activate", func() { Reset(); display.SetText("0") }, nil) filesubmenu.Append(resetmenuitem) exitmenuitem := gtk.MenuItemWithMnemonic("E_xit") exitmenuitem.Connect("activate", Quit, nil) filesubmenu.Append(exitmenuitem) // Vertical box containing all buttons buttons := gtk.VBox(false, 5) for i := 0; i < 4; i++ { hbox := gtk.HBox(false, 5) // a horizontal box for each 4 buttons for j := 0; j < 4; j++ { b := gtk.ButtonWithLabel(string(nums[i*4+j])) b.Clicked(Input(b), nil) //add click event hbox.Add(b) } buttons.Add(hbox) // add horizonatal box to vertical buttons' box } vbox.Add(buttons) window.Add(vbox) window.SetSizeRequest(250, 250) window.ShowAll() gtk.Main() }
func main() { gdk.ThreadsInit() gtk.Init(&os.Args) window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL) window.SetTitle("Twitter!") window.Connect("destroy", func() { gtk.MainQuit() }, nil) vbox := gtk.VBox(false, 1) scrolledwin := gtk.ScrolledWindow(nil, nil) textview := gtk.TextView() textview.SetEditable(false) textview.SetCursorVisible(false) scrolledwin.Add(textview) vbox.Add(scrolledwin) buffer := textview.GetBuffer() tag := buffer.CreateTag("blue", map[string]string{ "foreground": "#0000FF", "weight": "700"}) button := gtk.ButtonWithLabel("Update Timeline") button.SetTooltipMarkup("update <b>public timeline</b>") button.Clicked(func() { button.SetSensitive(false) go func() { gdk.ThreadsEnter() r, err := HttpGet("http://twitter.com/statuses/public_timeline.json") if err == nil { b := make([]byte, r.ContentLength) io.ReadFull(r.Body, b) var j interface{} json.NewDecoder(bytes.NewBuffer(b)).Decode(&j) arr := j.([]interface{}) for i := 0; i < len(arr); i++ { data := arr[i].(map[string]interface{}) icon := data["user"].(map[string]interface{})["profile_image_url"].(string) var iter gtk.GtkTextIter buffer.GetStartIter(&iter) buffer.InsertPixbuf(&iter, url2pixbuf(icon)) name := data["user"].(map[string]interface{})["screen_name"].(string) text := data["text"].(string) buffer.Insert(&iter, " ") buffer.InsertWithTag(&iter, name, tag) buffer.Insert(&iter, ":"+text+"\n") gtk.MainIteration() } } button.SetSensitive(true) gdk.ThreadsLeave() }() }, nil) vbox.PackEnd(button, false, false, 0) window.Add(vbox) window.SetSizeRequest(800, 500) window.ShowAll() gtk.Main() }