예제 #1
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()
}
예제 #2
0
func (window *GhMainWindow) build() {
	window.SetTitle("ghighlights")
	window.bindKeys()
	window.Connect("destroy", gtk.MainQuit)

	mainVBox := gtk.VBox(false, 1)

	menubar := window.buildMenuBar()
	mainVBox.PackStart(menubar, false, false, 0)

	scrolledTextViewWindow := gtk.ScrolledWindow(nil, nil)
	scrolledTextViewWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)

	textView := gtkext.TextViewWithPlaceholder("Highlight")
	textView.SetSizeRequest(600, 100)
	textView.SetWrapMode(gtk.GTK_WRAP_WORD)
	textView.SetAcceptsTab(false)
	scrolledTextViewWindow.Add(textView)

	scrolledTextViewWindow.SetSizeRequest(600, 100)
	mainVBox.Add(scrolledTextViewWindow)

	scrolledCommentTextViewWindow := gtk.ScrolledWindow(nil, nil)
	scrolledCommentTextViewWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)

	commentTextView := gtkext.TextViewWithPlaceholder("Comment")
	commentTextView.SetSizeRequest(600, 40)
	commentTextView.SetWrapMode(gtk.GTK_WRAP_WORD)
	commentTextView.SetAcceptsTab(false)
	scrolledCommentTextViewWindow.Add(commentTextView)

	scrolledCommentTextViewWindow.SetSizeRequest(600, 40)
	mainVBox.Add(scrolledCommentTextViewWindow)

	readingHBox := gtk.HBox(false, 10)
	pageNumberEntry := gtk.Entry()
	pageTotalEntry := gtk.Entry()

	readingsComboBox := gtk.ComboBoxText()
	readings := models.Readings()
	for _, reading := range readings.Items {
		readingsComboBox.AppendText(reading.Title)
	}
	readingsComboBox.SetActive(0)
	readingsComboBox.Connect("changed", func() {
		reading := readings.FindByTitle(readingsComboBox.GetActiveText())
		pageNumberEntry.SetText("0")
		pageTotalEntry.SetText(strconv.Itoa(reading.TotalPages))
	})
	align := gtk.Alignment(1, 1, 1, 0)
	align.Add(readingsComboBox)
	readingHBox.Add(align)

	pageHBox := gtk.HBox(false, 1)
	pageHBox.Add(gtk.Label("Page"))

	pageNumberEntry.SetAlignment(1)
	pageNumberEntry.SetWidthChars(4)
	pageNumberEntry.SetText("0")
	pageHBox.Add(pageNumberEntry)

	pageHBox.Add(gtk.Label("of"))

	pageTotalEntry.SetAlignment(1)
	pageTotalEntry.SetWidthChars(4)
	if len(readings.Items) > 0 {
		pageTotalEntry.SetText(strconv.Itoa(readings.Items[0].TotalPages))
	}
	pageHBox.Add(pageTotalEntry)

	pageBoxAlignment := gtk.Alignment(0, 0, 0, 0)
	pageBoxAlignment.Add(pageHBox)
	readingHBox.Add(pageBoxAlignment)
	mainVBox.Add(readingHBox)

	addHighlightButton := gtk.ButtonWithLabel("Add highlight")
	window.highlights = models.Highlights()
	addHighlightButton.Clicked(func() {
		reading := readings.FindByTitle(readingsComboBox.GetActiveText())
		readingId := reading.ReadmillId

		content := textView.GetStrippedText()

		comment := commentTextView.GetStrippedText()

		pageNumber, _ := strconv.Atoi(pageNumberEntry.GetText())
		pageTotal, _ := strconv.Atoi(pageTotalEntry.GetText())
		position := float32(pageNumber) / float32(pageTotal)

		highlight := models.GhHighlight{content, readingId, position, time.Now(), comment}
		window.highlights.Add(highlight)

		readings.UpdateTotalPages(pageTotal, reading)

		textView.DeleteText()
		commentTextView.DeleteText()
	})
	readingHBox.PackEnd(addHighlightButton, false, false, 0)

	window.Add(mainVBox)
	return
}