예제 #1
0
파일: demo.go 프로젝트: norisatir/go-gtk3
func main() {
	gtk3.Init()

	var infoBuf, sourceBuf *gtk3.TextBuffer

	window := gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
	window.SetTitle("Gtk+ Code Demos")
	window.Connect("destroy", gtk3.MainQuit)

	hbox := gtk3.NewHBox(0)
	window.Add(hbox)

	// Create tree
	tree := CreateTree()
	hbox.PackStart(tree, false, false, 0)

	notebook := gtk3.NewNotebook()
	hbox.PackStart(notebook, true, true, 0)

	notebook.AppendPage(CreateText(&infoBuf, false), gtk3.NewLabelWithMnemonic("_Info"))

	infoBuf.CreateTag("title", gtk3.P{"font": "Sans 18"})

	notebook.AppendPage(CreateText(&sourceBuf, true), gtk3.NewLabelWithMnemonic("_Source"))

	sourceBuf.CreateTag("comment", gtk3.P{"foreground": "DodgerBlue"})
	window.SetDefaultSize(600, 400)
	window.ShowAll()

	gtk3.Main()
}
예제 #2
0
파일: dialog.go 프로젝트: jkeys089/go-gtk3
func interactiveDialog(w *gtk3.Window, entry1, entry2 *gtk3.Entry) {
	dialog := gtk3.NewDialogWithButtons("Interactive Dialog",
		w,
		gtk3.GtkDialogFlags.MODAL|gtk3.GtkDialogFlags.DESTROY_WITH_PARENT,
		gtk3.B{{gtk3.GtkStock.OK, gtk3.GtkResponse.OK}, {"_Non-stock Button", gtk3.GtkResponse.CANCEL}})

	content_area := dialog.GetContentArea().(*gtk3.Box)

	hbox := gtk3.NewHBox(8)
	hbox.SetBorderWidth(uint(8))
	content_area.PackStart(hbox, false, false, 0)

	stock := gtk3.NewImageFromStock(gtk3.GtkStock.DIALOG_QUESTION, gtk3.GtkIconSize.DIALOG)
	hbox.PackStart(stock, false, false, 0)

	table := gtk3.NewGrid()
	table.SetRowSpacing(4)
	table.SetColumnSpacing(4)
	hbox.PackStart(table, true, true, 0)

	label := gtk3.NewLabelWithMnemonic("_Entry 1")
	table.Attach(label, 0, 0, 1, 1)

	local_entry1 := gtk3.NewEntry()
	local_entry1.SetText(entry1.GetText())
	table.Attach(local_entry1, 1, 0, 1, 1)
	label.SetMnemonicWidget(local_entry1)

	label = gtk3.NewLabelWithMnemonic("E_ntry 2")
	table.Attach(label, 0, 1, 1, 1)

	local_entry2 := gtk3.NewEntry()
	local_entry2.SetText(entry2.GetText())
	table.Attach(local_entry2, 1, 1, 1, 1)
	label.SetMnemonicWidget(local_entry2)

	hbox.ShowAll()
	response := dialog.Run()

	if response == gtk3.GtkResponse.OK {
		entry1.SetText(local_entry1.GetText())
		entry2.SetText(local_entry2.GetText())
	}

	dialog.Destroy()
}
예제 #3
0
파일: dialog.go 프로젝트: jkeys089/go-gtk3
func DoDialog(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())
		window.SetTitle("Dialogs")
		window.Connect("destroy", func() { window.Destroy(); window = nil })
		window.SetBorderWidth(8)

		frame := gtk3.NewFrame("Dialogs")
		window.Add(frame)

		vbox := gtk3.NewVBox(8)
		vbox.SetBorderWidth(8)
		frame.Add(vbox)

		// Standard message dialog
		hbox := gtk3.NewHBox(8)
		vbox.PackStart(hbox, false, false, 0)

		button := gtk3.NewButtonWithMnemonic("_Message Dialog")
		button.Connect("clicked", dialogClickedClosure(window))
		hbox.PackStart(button, false, false, 0)

		vbox.PackStart(gtk3.NewHSeparator(), false, false, 0)

		// Interactive dialog
		hbox = gtk3.NewHBox(8)
		vbox.PackStart(hbox, false, false, 0)
		vbox2 := gtk3.NewVBox(0)

		button = gtk3.NewButtonWithMnemonic("_Interactive Dialog")
		hbox.PackStart(vbox2, false, false, 0)
		vbox2.PackStart(button, false, false, 0)

		table := gtk3.NewGrid()
		table.SetRowSpacing(4)
		table.SetColumnSpacing(4)
		hbox.PackStart(table, false, false, 0)

		label := gtk3.NewLabelWithMnemonic("_Entry 1")
		table.Attach(label, 0, 0, 1, 1)

		entry1 := gtk3.NewEntry()
		table.Attach(entry1, 1, 0, 1, 1)
		label.SetMnemonicWidget(entry1)

		label = gtk3.NewLabelWithMnemonic("E_ntry 2")
		table.Attach(label, 0, 1, 1, 1)

		entry2 := gtk3.NewEntry()
		table.Attach(entry2, 1, 1, 1, 1)
		label.SetMnemonicWidget(entry2)

		button.Connect("clicked", interactiveDialog, window, entry1, entry2)
	}

	if !window.GetVisible() {
		window.ShowAll()
	} else {
		window.Destroy()
		window = nil
		return nil
	}
	return window
}