eventChannel no longer imports 'ui' directly
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
5a9544b8d2
commit
12cb01be84
|
@ -5,3 +5,7 @@ example-gui/example-gui
|
|||
example-systray/example-systray
|
||||
example-UI-table/example-UI-table
|
||||
example-dnssecsocket/example-dnssecsocket
|
||||
|
||||
test1/test1
|
||||
test2/test2
|
||||
test3/test3
|
||||
|
|
|
@ -7,12 +7,13 @@ import "os"
|
|||
import "io"
|
||||
import "bytes"
|
||||
import "strconv"
|
||||
import "image/color"
|
||||
|
||||
import "github.com/golang/protobuf/proto"
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
// import "github.com/andlabs/ui"
|
||||
// import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
import "git.wit.com/wit/gui"
|
||||
|
||||
|
@ -29,7 +30,8 @@ func processEvents() {
|
|||
log.Println("processEvents() on channel recieved a message = ", message)
|
||||
if (message.Type == pb.Event_DEMO) {
|
||||
log.Println("processEvents() do Event DEMO")
|
||||
go ui.Main(gui.SetupDemoUI)
|
||||
// figure out how to interact with the GUI here
|
||||
// go ui.Main(gui.SetupDemoUI)
|
||||
} else {
|
||||
count := countVMS(message)
|
||||
mh := addVmsTab(count)
|
||||
|
@ -62,21 +64,21 @@ func ReadReceivedData(data *pb.Event, mh *gui.TableData) {
|
|||
log.Println("ReadReceivedData() Event vms=", vms)
|
||||
for row, item := range vms {
|
||||
if (row % 2) == 1 {
|
||||
mh.Rows[row].HumanData[0].Color = ui.TableColor{0, 0, 0, .04}
|
||||
mh.Rows[row].HumanData[0].Color = color.RGBA{0, 0, 0, 42} // makes the background of each other row grey
|
||||
} else {
|
||||
mh.Rows[row].HumanData[0].Color = ui.TableColor{0, 0, 0, 0}
|
||||
mh.Rows[row].HumanData[0].Color = color.RGBA{0, 0, 0, 0}
|
||||
}
|
||||
mh.Rows[row].HumanData[1].Text = ui.TableString(item.Name)
|
||||
mh.Rows[row].HumanData[1].Color = ui.TableColor{0, 0, 0, 0}
|
||||
mh.Rows[row].HumanData[2].Text = ui.TableString(item.Hostname)
|
||||
mh.Rows[row].HumanData[2].Color = ui.TableColor{0, 0, 0, 0}
|
||||
mh.Rows[row].HumanData[3].Text = ui.TableString(fmt.Sprintf("%d",item.Cpus))
|
||||
mh.Rows[row].HumanData[3].Color = ui.TableColor{0, 0, 0, 0}
|
||||
mh.Rows[row].HumanData[4].Text = ui.TableString(fmt.Sprintf("%d",item.Memory))
|
||||
mh.Rows[row].HumanData[4].Color = ui.TableColor{0, 0, 0, 0}
|
||||
mh.Rows[row].HumanData[5].Text = ui.TableString(fmt.Sprintf("%d",item.Disk))
|
||||
mh.Rows[row].HumanData[5].Color = ui.TableColor{0, 0, 0, 0}
|
||||
mh.Rows[row].HumanData[6].Text = ui.TableString(fmt.Sprintf("Details %s",item.Name))
|
||||
mh.Rows[row].HumanData[1].Text = item.Name
|
||||
mh.Rows[row].HumanData[1].Color = color.RGBA{0, 0, 0, 0}
|
||||
mh.Rows[row].HumanData[2].Text = item.Hostname
|
||||
mh.Rows[row].HumanData[2].Color = color.RGBA{0, 0, 0, 0}
|
||||
mh.Rows[row].HumanData[3].Text = fmt.Sprintf("%d",item.Cpus)
|
||||
mh.Rows[row].HumanData[3].Color = color.RGBA{0, 0, 0, 0}
|
||||
mh.Rows[row].HumanData[4].Text = fmt.Sprintf("%d",item.Memory)
|
||||
mh.Rows[row].HumanData[4].Color = color.RGBA{0, 0, 0, 0}
|
||||
mh.Rows[row].HumanData[5].Text = fmt.Sprintf("%d",item.Disk)
|
||||
mh.Rows[row].HumanData[5].Color = color.RGBA{0, 0, 0, 0}
|
||||
mh.Rows[row].HumanData[6].Text = fmt.Sprintf("Details %s",item.Name)
|
||||
|
||||
log.Println("\titem=", item)
|
||||
log.Println("\titem.Name=", item.Name)
|
||||
|
|
|
@ -49,7 +49,7 @@ func ReadReceivedData(data *pb.Event, mh *gui.TableData) {
|
|||
log.Println("ReadReceivedData() Event vms=", vms)
|
||||
row := 0
|
||||
for _, item := range vms {
|
||||
mh.Rows[row].Cells[3].Raw = item.Name
|
||||
mh.Rows[row].HumanData[3].Text = item.Name
|
||||
log.Println(item)
|
||||
row += 1
|
||||
}
|
||||
|
|
|
@ -155,12 +155,12 @@ func setupCloudUI() {
|
|||
}
|
||||
|
||||
func addTableTab() {
|
||||
var parts []gui.InputData
|
||||
var parts []gui.TableColumnData
|
||||
|
||||
for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON", "TEXT", "BUTTON"} {
|
||||
log.Println(key, foo)
|
||||
|
||||
var b gui.InputData
|
||||
var b gui.TableColumnData
|
||||
b.CellType = foo
|
||||
b.Heading = fmt.Sprintf("heading%d", key)
|
||||
parts = append(parts, b)
|
||||
|
@ -172,12 +172,12 @@ func addTableTab() {
|
|||
}
|
||||
|
||||
func addProtobufTab() {
|
||||
var parts []gui.InputData
|
||||
var parts []gui.TableColumnData
|
||||
|
||||
for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON", "TEXT", "BUTTON"} {
|
||||
log.Println(key, foo)
|
||||
|
||||
var b gui.InputData
|
||||
var b gui.TableColumnData
|
||||
b.CellType = foo
|
||||
b.Heading = fmt.Sprintf("heading%d", key)
|
||||
parts = append(parts, b)
|
||||
|
@ -194,46 +194,46 @@ type aheader struct {
|
|||
}
|
||||
|
||||
func addVmsTab(count int) *gui.TableData {
|
||||
var parts []gui.InputData
|
||||
var parts []gui.TableColumnData
|
||||
|
||||
human := 0
|
||||
|
||||
tmp := gui.InputData{}
|
||||
tmp := gui.TableColumnData{}
|
||||
tmp.CellType = "BG"
|
||||
tmp.Heading = "background"
|
||||
tmp.Index = human
|
||||
parts = append(parts, tmp)
|
||||
human += 1
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "TEXTCOLOR"
|
||||
tmp.Heading = "name"
|
||||
tmp.Index = human
|
||||
parts = append(parts, tmp)
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "TEXTCOLOR"
|
||||
tmp.Heading = "hostname"
|
||||
tmp.Index = human
|
||||
parts = append(parts, tmp)
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "TEXTCOLOR"
|
||||
tmp.Heading = "IPv6"
|
||||
tmp.Index = human
|
||||
parts = append(parts, tmp)
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "TEXTCOLOR"
|
||||
tmp.Heading = "cpus"
|
||||
parts = append(parts, tmp)
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "TEXTCOLOR"
|
||||
tmp.Heading = "memory"
|
||||
parts = append(parts, tmp)
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "BUTTON"
|
||||
tmp.Heading = "Details"
|
||||
parts = append(parts, tmp)
|
||||
|
|
20
infoTabUI.go
20
infoTabUI.go
|
@ -99,12 +99,12 @@ func setupCloudUI() {
|
|||
}
|
||||
|
||||
func addTableTab() {
|
||||
var parts []gui.InputData
|
||||
var parts []gui.TableColumnData
|
||||
|
||||
for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON", "TEXT", "BUTTON"} {
|
||||
log.Println(key, foo)
|
||||
|
||||
var b gui.InputData
|
||||
var b gui.TableColumnData
|
||||
b.CellType = foo
|
||||
b.Heading = fmt.Sprintf("heading%d", key)
|
||||
parts = append(parts, b)
|
||||
|
@ -116,53 +116,53 @@ func addTableTab() {
|
|||
}
|
||||
|
||||
func addVmsTab(count int) *gui.TableData {
|
||||
var parts []gui.InputData
|
||||
var parts []gui.TableColumnData
|
||||
|
||||
human := 0
|
||||
|
||||
tmp := gui.InputData{}
|
||||
tmp := gui.TableColumnData{}
|
||||
tmp.CellType = "BG"
|
||||
tmp.Heading = "background"
|
||||
tmp.Index = human
|
||||
parts = append(parts, tmp)
|
||||
human += 1
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "TEXTCOLOR"
|
||||
tmp.Heading = "name"
|
||||
tmp.Index = human
|
||||
parts = append(parts, tmp)
|
||||
human += 1
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "TEXTCOLOR"
|
||||
tmp.Heading = "hostname"
|
||||
tmp.Index = human
|
||||
parts = append(parts, tmp)
|
||||
human += 1
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "TEXTCOLOR"
|
||||
tmp.Heading = "IPv6"
|
||||
tmp.Index = human
|
||||
parts = append(parts, tmp)
|
||||
human += 1
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "TEXTCOLOR"
|
||||
tmp.Heading = "cpus"
|
||||
tmp.Index = human
|
||||
parts = append(parts, tmp)
|
||||
human += 1
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "TEXTCOLOR"
|
||||
tmp.Heading = "memory"
|
||||
tmp.Index = human
|
||||
parts = append(parts, tmp)
|
||||
human += 1
|
||||
|
||||
tmp = gui.InputData{}
|
||||
tmp = gui.TableColumnData{}
|
||||
tmp.CellType = "BUTTON"
|
||||
tmp.Heading = "Details"
|
||||
tmp.Index = human
|
||||
|
|
|
@ -21,7 +21,7 @@ func makeSplashArea() *ui.Area {
|
|||
spew.Dump(fontButton.Font())
|
||||
|
||||
makeAttributedString()
|
||||
splashArea = ui.NewArea(areaHandler{})
|
||||
splashArea = ui.NewArea(myAH)
|
||||
|
||||
spew.Dump(splashArea)
|
||||
return splashArea
|
||||
|
@ -57,20 +57,25 @@ func makeAttributedString() {
|
|||
appendWithAttributes("<click or press any key>\n", ui.TextSize(10))
|
||||
}
|
||||
|
||||
type areaHandler struct{}
|
||||
type areaHandler struct{
|
||||
buttonFunc func(int, int)
|
||||
closeFunc func(int)
|
||||
}
|
||||
|
||||
func (areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
||||
var myAH areaHandler
|
||||
|
||||
func (ah areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
||||
tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
|
||||
String: attrstr,
|
||||
DefaultFont: fontButton.Font(),
|
||||
Width: p.AreaWidth,
|
||||
Align: ui.DrawTextAlign(1),
|
||||
})
|
||||
defer tl.Free()
|
||||
p.Context.Text(tl, 0, 0)
|
||||
defer tl.Free()
|
||||
}
|
||||
|
||||
func (areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
||||
func (ah areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
||||
log.Println("GOT MouseEvent()")
|
||||
spew.Dump(me)
|
||||
if (me.Down == 1) {
|
||||
|
@ -87,15 +92,15 @@ func (areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
|||
}
|
||||
}
|
||||
|
||||
func (areaHandler) MouseCrossed(a *ui.Area, left bool) {
|
||||
func (ah areaHandler) MouseCrossed(a *ui.Area, left bool) {
|
||||
log.Println("GOT MouseCrossed()")
|
||||
}
|
||||
|
||||
func (areaHandler) DragBroken(a *ui.Area) {
|
||||
func (ah areaHandler) DragBroken(a *ui.Area) {
|
||||
log.Println("GOT DragBroken()")
|
||||
}
|
||||
|
||||
func (areaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
|
||||
func (ah areaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
|
||||
log.Println("GOT KeyEvent()")
|
||||
if (ke.Key == 10) {
|
||||
log.Println("GOT ENTER")
|
||||
|
|
|
@ -32,6 +32,13 @@ func ShowSplash() {
|
|||
// This displays the window
|
||||
splashWin.Show()
|
||||
|
||||
ShowSplashBox(vbox, nil)
|
||||
}
|
||||
|
||||
func ShowSplashBox(junk *ui.Box, atest chan int) *ui.Box {
|
||||
vbox := ui.NewVerticalBox()
|
||||
vbox.SetPadded(true)
|
||||
|
||||
makeAttributedString()
|
||||
myArea := makeSplashArea()
|
||||
|
||||
|
@ -48,10 +55,16 @@ func ShowSplash() {
|
|||
vbox.Append(ui.NewLabel("Version: v0.3"), false)
|
||||
|
||||
okButton := ui.NewButton("OK")
|
||||
|
||||
okButton.OnClicked(func(*ui.Button) {
|
||||
log.Println("OK. Closing window.")
|
||||
test := 4
|
||||
atest <- test
|
||||
splashWin.Destroy()
|
||||
ui.Quit()
|
||||
})
|
||||
|
||||
vbox.Append(okButton, false)
|
||||
|
||||
return vbox
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
this eventually crashes (GTK / Linux)
|
|
@ -0,0 +1,2 @@
|
|||
run:
|
||||
go run *.go
|
|
@ -0,0 +1,116 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue