2013-05-10 18:58:19 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/ziutek/gdk"
|
|
|
|
"github.com/ziutek/gtk"
|
|
|
|
)
|
|
|
|
|
2013-05-10 19:26:14 +00:00
|
|
|
// this happens when the X is clicked (to close the app)
|
2013-05-10 18:58:19 +00:00
|
|
|
func cbDelete(w *gtk.Widget, ev *gdk.Event) bool {
|
|
|
|
fmt.Println("Delete")
|
2013-05-10 19:26:14 +00:00
|
|
|
defer gtk.MainQuit()
|
2013-05-10 18:58:19 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func cbDestroy(w *gtk.Widget) {
|
|
|
|
fmt.Println("Destroy")
|
|
|
|
gtk.MainQuit()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
w := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
|
|
|
w.Connect("delete-event", cbDelete, nil)
|
|
|
|
w.Connect("destroy", cbDestroy, nil)
|
|
|
|
w.SetBorderWidth(10)
|
|
|
|
w.Show()
|
|
|
|
|
2013-05-10 19:52:40 +00:00
|
|
|
vb := gtk.NewVBox(false, 0)
|
|
|
|
|
2013-05-10 19:26:14 +00:00
|
|
|
f := gtk.NewFileChooserButton("Select File", gtk.FILE_CHOOSER_ACTION_OPEN)
|
2013-05-10 19:52:40 +00:00
|
|
|
vb.PackEnd(f.AsWidget(), false, false, 0)
|
2013-05-10 19:26:14 +00:00
|
|
|
f.Show()
|
2013-05-10 18:58:19 +00:00
|
|
|
|
2013-05-10 19:26:14 +00:00
|
|
|
a := Action{"Hello World!\n"}
|
|
|
|
b := gtk.NewButtonWithLabel("Quit")
|
|
|
|
b.Connect("clicked", (*Action).Quit, &a)
|
2013-05-10 18:58:19 +00:00
|
|
|
b.ConnectNoi("clicked", (*gtk.Widget).Destroy, w.AsWidget())
|
2013-05-10 19:52:40 +00:00
|
|
|
vb.PackEnd(b.AsWidget(), false, false, 0)
|
2013-05-10 18:58:19 +00:00
|
|
|
b.Show()
|
|
|
|
|
2013-05-10 19:52:40 +00:00
|
|
|
w.Add(vb.AsWidget())
|
|
|
|
|
2013-05-10 18:58:19 +00:00
|
|
|
gtk.Main()
|
|
|
|
}
|
|
|
|
|
2013-05-10 19:26:14 +00:00
|
|
|
type Action struct {
|
2013-05-10 18:58:19 +00:00
|
|
|
s string
|
|
|
|
}
|
|
|
|
|
2013-05-10 19:26:14 +00:00
|
|
|
func (a *Action) Quit(w *gtk.Widget) {
|
2013-05-10 18:58:19 +00:00
|
|
|
fmt.Printf(a.s)
|
|
|
|
}
|