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() { 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() }