Beispiel #1
0
func main() {
	gtk.Init(nil)
	clipboard := gtk.NewClipboardGetForDisplay(
		gdk.DisplayGetDefault(),
		gdk.SELECTION_CLIPBOARD)
	fmt.Println(clipboard.WaitForText())
	clipboard.SetText("helloworld")
	gtk.MainIterationDo(true)
	clipboard.Store()
	gtk.MainIterationDo(true)
}
Beispiel #2
0
func main() {
	gtk.Init(nil)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("Clock")
	vbox := gtk.VBox(false, 1)
	label := gtk.Label("")
	vbox.Add(label)
	window.Add(vbox)
	window.SetDefaultSize(300, 20)
	window.ShowAll()

	timer, _ := uv.TimerInit(nil)
	timer.Start(func(h *uv.Handle, status int) {
		label.SetLabel(fmt.Sprintf("%v", time.Now()))
	}, 1000, 1000)

	idle, _ := uv.IdleInit(nil)
	idle.Start(func(h *uv.Handle, status int) {
		gtk.MainIterationDo(false)
	})

	window.Connect("destroy", func() {
		timer.Close(nil)
		idle.Close(nil)
	})

	uv.DefaultLoop().Run()
}
Beispiel #3
0
func display(t *tweet, buffer *gtk.TextBuffer, tag *gtk.TextTag) {
	var iter gtk.TextIter
	pixbufbytes, resp := readURL(t.User.ProfileImageUrl)
	buffer.GetStartIter(&iter)
	if resp != nil {
		buffer.InsertPixbuf(&iter, bytes2pixbuf(pixbufbytes, resp.Header.Get("Content-Type")))
	}
	buffer.Insert(&iter, " ")
	buffer.InsertWithTag(&iter, t.User.ScreenName, tag)
	buffer.Insert(&iter, ":"+t.Text+"\n")
	gtk.MainIterationDo(false)
}
Beispiel #4
0
func main() {
	gdk.ThreadsInit()
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("Twitter!")
	window.Connect("destroy", gtk.MainQuit)

	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() {
		go func() {
			gdk.ThreadsEnter()
			button.SetSensitive(false)
			gdk.ThreadsLeave()
			r, err := http.Get("http://twitter.com/statuses/public_timeline.json")
			if err == nil {
				var b []byte
				if r.ContentLength == -1 {
					b, err = ioutil.ReadAll(r.Body)
				} else {
					b = make([]byte, r.ContentLength)
					_, err = io.ReadFull(r.Body, b)
				}
				if err != nil {
					println(err.String())
					return
				}
				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
					gdk.ThreadsEnter()
					buffer.GetStartIter(&iter)
					buffer.InsertPixbuf(&iter, url2pixbuf(icon))
					gdk.ThreadsLeave()
					name := data["user"].(map[string]interface{})["screen_name"].(string)
					text := data["text"].(string)
					gdk.ThreadsEnter()
					buffer.Insert(&iter, " ")
					buffer.InsertWithTag(&iter, name, tag)
					buffer.Insert(&iter, ":"+text+"\n")
					gtk.MainIterationDo(false)
					gdk.ThreadsLeave()
				}
			}
			button.SetSensitive(true)
		}()
	})
	vbox.PackEnd(button, false, false, 0)

	window.Add(vbox)
	window.SetSizeRequest(800, 500)
	window.ShowAll()
	gdk.ThreadsEnter()
	gtk.Main()
	gdk.ThreadsLeave()
}
Beispiel #5
0
func main() {
	gtk.Init(&os.Args)
	gdk.ThreadsInit()
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("Twitter!")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(false, 1)

	scrolledwin := gtk.NewScrolledWindow(nil, nil)
	textview := gtk.NewTextView()
	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.NewButtonWithLabel("Update Timeline")
	button.SetTooltipMarkup("update <b>public timeline</b>")
	button.Clicked(func() {
		b, err := ioutil.ReadFile("settings.json")
		if err != nil {
			fmt.Println(`"settings.json" not found: `, err)
			return
		}
		var config map[string]string
		err = json.Unmarshal(b, &config)
		if err != nil {
			fmt.Println(`can't read "settings.json": `, err)
			return
		}
		client := &oauth.Client{
			Credentials: oauth.Credentials{
				config["ClientToken"], config["ClientSecret"]}}
		cred := &oauth.Credentials{
			config["AccessToken"], config["AccessSecret"]}

		gdk.ThreadsEnter()
		button.SetSensitive(false)
		gdk.ThreadsLeave()
		go func() {
			ts, err := twitterstream.Open(client, cred,
				"https://stream.twitter.com/1/statuses/filter.json",
				url.Values{"track": {"picplz,instagr"}})
			if err != nil {
				println(err.Error())
				return
			}
			for ts.Err() == nil {
				t := tweet{}
				if err := ts.UnmarshalNext(&t); err != nil {
					fmt.Println("error reading tweet: ", err)
					continue
				}
				var iter gtk.TextIter
				pixbufbytes, resp := readURL(t.User.ProfileImageUrl)
				gdk.ThreadsEnter()
				buffer.GetStartIter(&iter)
				if resp != nil {
					buffer.InsertPixbuf(&iter, bytes2pixbuf(pixbufbytes, resp.Header.Get("Content-Type")))
				}
				gdk.ThreadsLeave()
				gdk.ThreadsEnter()
				buffer.Insert(&iter, " ")
				buffer.InsertWithTag(&iter, t.User.ScreenName, tag)
				buffer.Insert(&iter, ":"+t.Text+"\n")
				gtk.MainIterationDo(false)
				gdk.ThreadsLeave()
			}
		}()
	})
	vbox.PackEnd(button, false, false, 0)

	window.Add(vbox)
	window.SetSizeRequest(800, 500)
	window.ShowAll()
	gdk.ThreadsEnter()
	gtk.Main()
	gdk.ThreadsLeave()
}
Beispiel #6
0
func main() {
	b, err := ioutil.ReadFile("settings.json")
	if err != nil {
		fmt.Println(`"settings.json" not found: `, err)
		return
	}
	var config map[string]string
	err = json.Unmarshal(b, &config)
	if err != nil {
		fmt.Println(`can't read "settings.json": `, err)
		return
	}
	client := &oauth.Client{Credentials: oauth.Credentials{config["ClientToken"], config["ClientSecret"]}}
	cred := &oauth.Credentials{config["AccessToken"], config["AccessSecret"]}

	runtime.LockOSThread()
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("Twitter!")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(false, 1)

	scrolledwin := gtk.NewScrolledWindow(nil, nil)
	textview := gtk.NewTextView()
	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"})

	hbox := gtk.NewHBox(false, 1)
	vbox.PackEnd(hbox, false, true, 5)

	label := gtk.NewLabel("Tweet")
	hbox.PackStart(label, false, false, 5)
	text := gtk.NewEntry()
	hbox.PackEnd(text, true, true, 5)

	text.Connect("activate", func() {
		t := text.GetText()
		text.SetText("")
		post(client, cred, t)
	})

	window.Add(vbox)
	window.SetSizeRequest(800, 500)
	window.ShowAll()

	var mutex sync.Mutex

	go func() {
		show(client, cred, func(t *tweet) {
			mutex.Lock()
			display(t, buffer, tag)
			mutex.Unlock()
		})

		stream(client, cred, func(t *tweet) {
			mutex.Lock()
			display(t, buffer, tag)
			var start, end gtk.TextIter
			buffer.GetIterAtLine(&start, buffer.GetLineCount()-2)
			buffer.GetEndIter(&end)
			buffer.Delete(&start, &end)
			mutex.Unlock()
		})
	}()

	for alive {
		mutex.Lock()
		alive = gtk.MainIterationDo(false)
		mutex.Unlock()
	}
}