Beispiel #1
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("GTK Notebook")
	window.Connect("destroy", gtk.MainQuit)

	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 prev")
		prev.Clicked(func() {
			notebook.PrevPage()
		})
		vbox.Add(prev)

		next := gtk.ButtonWithLabel("go next")
		next.Clicked(func() {
			notebook.NextPage()
		})
		vbox.Add(next)

		page.Add(vbox)
	}

	window.Add(notebook)
	window.SetSizeRequest(400, 200)
	window.ShowAll()

	gtk.Main()
}
Beispiel #2
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("Alignment")
	window.Connect("destroy", gtk.MainQuit)

	notebook := gtk.Notebook()
	window.Add(notebook)

	align := gtk.Alignment(0.5, 0.5, 0.5, 0.5)
	notebook.AppendPage(align, gtk.Label("Alignment"))

	button := gtk.ButtonWithLabel("Hello World!")
	align.Add(button)

	fixed := gtk.Fixed()
	notebook.AppendPage(fixed, gtk.Label("Fixed"))

	button2 := gtk.ButtonWithLabel("Pulse")
	fixed.Put(button2, 30, 30)

	progress := gtk.ProgressBar()
	fixed.Put(progress, 30, 70)

	button.Connect("clicked", func() {
		progress.SetFraction(0.1 + 0.9*progress.GetFraction()) //easter egg
	})
	button2.Connect("clicked", func() {
		progress.Pulse()
	})

	window.ShowAll()
	window.SetSizeRequest(200, 200)

	gtk.Main()
}
Beispiel #3
0
func Gui() {
	//--------------------------------------------------------
	// Setting up the GTK-Foo
	//--------------------------------------------------------
	gdk.ThreadsInit()
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("Zwitscher!")
	window.Connect("destroy", func() {
		gtk.MainQuit()
	})

	vbox := gtk.VBox(false, 1)
	notebook := gtk.Notebook()

	//--------------------------------------------------------
	// Home View
	//--------------------------------------------------------
	vboxHome := gtk.VBox(false, 1)
	scrolledWinHome := gtk.ScrolledWindow(nil, nil)
	//Disable hscrollbar, enable vscrollbar
	scrolledWinHome.SetPolicy(gtk.GTK_POLICY_NEVER, gtk.GTK_POLICY_ALWAYS)
	vboxHome.Add(scrolledWinHome)
	vboxScrolledWinHome := gtk.VBox(false, 1)
	scrolledWinHome.AddWithViewPort(vboxScrolledWinHome)

	tweetwidgets := []*gtk.GtkFrame{}
	buttonUpdateTimeline := gtk.ButtonWithLabel("Update Timeline")
	buttonUpdateTimeline.Clicked(func() {
		var tweet gotter.Tweet
		tweets, err := gotter.GetTweets(accounts.Credentials, "https://api.twitter.com/1/statuses/home_timeline.json", map[string]string{})
		if err != nil {
			println("failed to get tweets:", err.String())
			return
		}
		for i := len(tweets) - 1; i >= 0; i-- {
			tweet = tweets[i]
			id, _ := strconv.Atoi64(tweet.Identifier)
			if accounts.Maxreadid < id {
				if len(tweetwidgets) > 20 {
					tweetwidgets[0].Destroy()
					tweetwidgets = tweetwidgets[1:]
				}
				tweetwidget := TweetWidget(tweet)
				vboxScrolledWinHome.PackEnd(tweetwidget, false, false, 0)
				tweetwidget.ShowAll()
				tweetwidgets = append(tweetwidgets, tweetwidget)
				accounts.Maxreadid = id
			}
		}
	})
	vboxHome.PackEnd(buttonUpdateTimeline, false, false, 0)
	notebook.AppendPage(vboxHome, gtk.Label("Home"))

	//--------------------------------------------------------
	// Mentions View
	//--------------------------------------------------------
	scrolledwin := gtk.ScrolledWindow(nil, nil)
	notebook.AppendPage(scrolledwin, gtk.Label("Mentions"))

	//--------------------------------------------------------
	// Messages View
	//--------------------------------------------------------
	scrolledwin = gtk.ScrolledWindow(nil, nil)
	notebook.AppendPage(scrolledwin, gtk.Label("Messages"))

	vbox.Add(notebook)

	//--------------------------------------------------------
	// Fild for Tweets
	//--------------------------------------------------------
	hbox := gtk.HBox(false, 1)

	dir, _ := filepath.Split(os.Args[0])
	imagefile := filepath.Join(dir, "Awesome Smiley Original.jpg")
	image := gtk.ImageFromFile(imagefile)
	hbox.PackStart(image, false, false, 0)

	buttonZwitscher := gtk.ButtonWithLabel("Zwitscher!")
	newTweetTextField := gtk.Entry()
	charCounterLabel := gtk.Label("140")

	buttonZwitscher.SetTooltipMarkup("Tweet")

	buttonZwitscher.Clicked(func() {
		charCounterLabel.SetLabel("140")
		SendTweet(newTweetTextField.GetText())
		newTweetTextField.SetText("")
	})

	newTweetTextField.Connect("key-release-event", func() {
		length := utf8.RuneCountInString(newTweetTextField.GetText())
		charCounterLabel.SetLabel((string)(strconv.Itoa(140 - length)))
	})

	newTweetTextField.Connect("activate", func() {
		if newTweetTextField.GetText() != "" { //pressed enter, and text is not empty
			charCounterLabel.SetLabel("140")
			SendTweet(newTweetTextField.GetText())
			newTweetTextField.SetText("")
		}
	})
	hbox.PackStartDefaults(newTweetTextField)
	hbox.PackStart(charCounterLabel, false, false, 0)
	hbox.PackEnd(buttonZwitscher, false, false, 0)

	vbox.PackEnd(hbox, false, false, 0)

	//--------------------------------------------------------
	// Event
	//--------------------------------------------------------
	window.Add(vbox)
	window.SetSizeRequest(400, 550)
	window.ShowAll()

	gdk.ThreadsEnter()
	gtk.Main()
	gdk.ThreadsLeave()
}