cloud-control-panel/test3/main.go

117 lines
2.2 KiB
Go

package main
import "os"
import "log"
import "time"
import "os/signal"
import "github.com/davecgh/go-spew/spew"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
import "git.wit.com/wit/cloud-control-panel/splash"
// import "git.wit.com/wit/cloud-control-panel/account1"
// import "git.wit.com/wit/cloud-control-panel/account2"
var atest chan int
func main() {
/*
ui.Main(splash.ShowSplash)
ui.Main(account1.AddAccountWindow)
ui.Main(account2.AddAccountWindow)
ui.Main(addAccountWindow)
ui.Main(showSplash)
*/
go ui.Main(setupUI)
beautifulAndFacinatingChannel()
// ui.Main(testFor)
}
func setupUI() {
mainwin := ui.NewWindow("gui-example1", 640, 480, true)
mainwin.OnClosing(func(*ui.Window) bool {
ui.Quit()
os.Exit(0)
return true
})
ui.OnShouldQuit(func() bool {
mainwin.Destroy()
test := 4
atest <- test
return true
})
tab := ui.NewTab()
mainwin.SetChild(tab)
mainwin.SetMargined(true)
mainwin.Show()
vbox := splash.ShowSplashBox(nil, atest)
tab.Append("WIT Splash", vbox)
tab.SetMargined(0, true)
}
func somefunc(testing os.Signal) {
// return 1
}
type Newish struct {
A <-chan int
r string
}
//
// this is a facinating code snippet that I wanted to leave here because it is
// so interesting. Complements to the gorilla websocket example developers
//
func beautifulAndFacinatingChannel() {
done := make(chan struct{})
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
ticker := time.NewTicker(time.Second * 1)
// atest := make(chan int, 1)
atest = make(chan int)
newthing := &Newish{
A: atest,
r: "something",
}
defer ticker.Stop()
defer close(done)
for {
select {
case <-done:
log.Println("case <-done is EMPTY?")
return
case t := <-ticker.C:
log.Println("test NewTicker()", t.String())
spew.Dump(ticker)
case j := <-atest:
log.Println("GOT HERE!!!! test func() j=", j)
close(done)
case <-interrupt:
log.Println("interrupt")
newthing.r = "four"
spew.Dump(newthing)
// could do final things here when kill or ctrl-c
select {
case <-done:
log.Println("case <-done is EMPTY?")
case <-time.After(time.Second):
log.Println("case <-second timer fired again")
}
return
}
}
}