Well, this is a walkthrough on how YT is dying.
Login to view embedded media View: https://youtu.be/Ln1qbgZz_TQ package main
import (
"github.com/mattn/go-gtk/gdkpixbuf"
"github.com/mattn/go-gtk/glib"
"github.com/mattn/go-gtk/gtk"
"os"
"os/exec"
"path"
"regexp"
"sort"
"strings"
)
func uniq(strings []string) (ret []string) {
return
}
func authors() []string {
if b, err := exec.Command("git", "log").Output(); err == nil {
lines := strings.Split(string(b), "\n")
var a []string
r := regexp.MustCompile(`^Author:\s*([^ <]+).*$`)
for _, e := range lines {
ms := r.FindStringSubmatch(e)
if ms == nil {
continue
}
a = append(a, ms[1])
}
sort.Strings(a)
var p string
lines = []string{}
for _, e := range a {
if p == e {
continue
}
lines = append(lines, e)
p = e
}
return lines
}
return []string{"Yasuhiro Matsumoto "<Duke >"}
}
func main() {
var menuitem *gtk.MenuItem
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetPosition(gtk.WIN_POS_CENTER)
window.SetTitle("GTK Go!")
window.SetIconName("gtk-dialog-info")
window.Connect("destroy", func(ctx *glib.CallbackContext) {
println("got destroy!", ctx.Data().(string))
gtk.MainQuit()
}, "foo")
//--------------------------------------------------------
// GtkVBox
//--------------------------------------------------------
vbox := gtk.NewVBox(false, 1)
//--------------------------------------------------------
// GtkMenuBar
//--------------------------------------------------------
menubar := gtk.NewMenuBar()
vbox.PackStart(menubar, false, false, 0)
//--------------------------------------------------------
// GtkVPaned
//--------------------------------------------------------
vpaned := gtk.NewVPaned()
vbox.Add(vpaned)
//--------------------------------------------------------
// GtkFrame
//--------------------------------------------------------
frame1 := gtk.NewFrame("Demo")
framebox1 := gtk.NewVBox(false, 1)
frame1.Add(framebox1)
frame2 := gtk.NewFrame("Demo")
framebox2 := gtk.NewVBox(false, 1)
frame2.Add(framebox2)
vpaned.Pack1(frame1, false, false)
vpaned.Pack2(frame2, false, false)
//--------------------------------------------------------
// GtkImage
//--------------------------------------------------------
dir, _ := path.Split(os.Args[0])
imagefile := path.Join(dir, "../../data/go-gtk-logo.png")
label := gtk.NewLabel("Go Binding for GTK")
label.ModifyFontEasy("DejaVu Serif 15")
framebox1.PackStart(label, false, true, 0)
//--------------------------------------------------------
// GtkEntry
//--------------------------------------------------------
entry := gtk.NewEntry()
entry.SetText("Hello world")
framebox1.Add(entry)
image := gtk.NewImageFromFile(imagefile)
framebox1.Add(image)
//--------------------------------------------------------
// GtkScale
//--------------------------------------------------------
scale := gtk.NewHScaleWithRange(0, 100, 1)
scale.Connect("value-changed", func() {
println("scale:", int(scale.GetValue()))
})
framebox2.Add(scale)
//--------------------------------------------------------
// GtkHBox
//--------------------------------------------------------
buttons := gtk.NewHBox(false, 1)
//--------------------------------------------------------
// GtkButton
//--------------------------------------------------------
button := gtk.NewButtonWithLabel("Button with label")
button.Clicked(func() {
println("button clicked:", button.GetLabel())
messagedialog := gtk.NewMessageDialog(
button.GetTopLevelAsWindow(),
gtk.DIALOG_MODAL,
gtk.MESSAGE_INFO,
gtk.BUTTONS_OK,
entry.GetText())
messagedialog.Response(func() {
println("Dialog OK!")
//--------------------------------------------------------
// GtkFileChooserDialog
//--------------------------------------------------------
filechooserdialog := gtk.NewFileChooserDialog(
"Choose File...",
button.GetTopLevelAsWindow(),
gtk.FILE_CHOOSER_ACTION_OPEN,
gtk.STOCK_OK,
gtk.RESPONSE_ACCEPT)
filter := gtk.NewFileFilter()
filter.AddPattern("*.go")
filechooserdialog.AddFilter(filter)
filechooserdialog.Response(func() {
println(filechooserdialog.GetFilename())
filechooserdialog.Destroy()
})
filechooserdialog.Run()
messagedialog.Destroy()
})
messagedialog.Run()
})
buttons.Add(button)
//--------------------------------------------------------
// GtkFontButton
//--------------------------------------------------------
fontbutton := gtk.NewFontButton()
fontbutton.Connect("font-set", func() {
println("title:", fontbutton.GetTitle())
println("fontname:", fontbutton.GetFontName())
println("use_size:", fontbutton.GetUseSize())
println("show_size:", fontbutton.GetShowSize())
})
buttons.Add(fontbutton)
framebox2.PackStart(buttons, false, false, 0)
buttons = gtk.NewHBox(false, 1)
//--------------------------------------------------------
// GtkToggleButton
//--------------------------------------------------------
togglebutton := gtk.NewToggleButtonWithLabel("ToggleButton with label")
togglebutton.Connect("toggled", func() {
if togglebutton.GetActive() {
togglebutton.SetLabel("ToggleButton ON!")
} else {
togglebutton.SetLabel("ToggleButton OFF!")
}
})
buttons.Add(togglebutton)
//--------------------------------------------------------
// GtkCheckButton
//--------------------------------------------------------
checkbutton := gtk.NewCheckButtonWithLabel("CheckButton with label")
checkbutton.Connect("toggled", func() {
if checkbutton.GetActive() {
checkbutton.SetLabel("CheckButton CHECKED!")
} else {
checkbutton.SetLabel("CheckButton UNCHECKED!")
}
})
buttons.Add(checkbutton)
//--------------------------------------------------------
// GtkRadioButton
//--------------------------------------------------------
buttonbox := gtk.NewVBox(false, 1)
radiofirst := gtk.NewRadioButtonWithLabel(nil, "Radio1")
buttonbox.Add(radiofirst)
buttonbox.Add(gtk.NewRadioButtonWithLabel(radiofirst.GetGroup(), "Radio2"))
buttonbox.Add(gtk.NewRadioButtonWithLabel(radiofirst.GetGroup(), "Radio3"))
buttons.Add(buttonbox)
//radiobutton.SetMode(false);
radiofirst.SetActive(true)
framebox2.PackStart(buttons, false, false, 0)
//--------------------------------------------------------
// GtkVSeparator
//--------------------------------------------------------
vsep := gtk.NewVSeparator()
framebox2.PackStart(vsep, false, false, 0)