no longer crashes. seems stable. Can edit text fields
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
5dcbe40e76
commit
f1a37e410c
35
gui.go
35
gui.go
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "log"
|
import "log"
|
||||||
import "fmt"
|
// import "fmt"
|
||||||
|
|
||||||
import "github.com/gookit/config"
|
import "github.com/gookit/config"
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
|
@ -13,9 +13,19 @@ var mainwin *ui.Window
|
||||||
var maintab *ui.Tab
|
var maintab *ui.Tab
|
||||||
var tabcount int
|
var tabcount int
|
||||||
|
|
||||||
|
var jcarrButton *ui.Button
|
||||||
|
var jcarrEntry *ui.MultilineEntry
|
||||||
|
|
||||||
func buttonClick(button *ui.Button) {
|
func buttonClick(button *ui.Button) {
|
||||||
log.Println("hostname =", config.String("hostname"), button)
|
log.Println("hostname =", config.String("hostname"), button)
|
||||||
spew.Dump(button)
|
spew.Dump(button)
|
||||||
|
if (jcarrButton == button) {
|
||||||
|
log.Println("This is the jcarrButton")
|
||||||
|
cur := jcarrEntry.Text()
|
||||||
|
jcarrEntry.SetText(cur + "THIS IS A GREAT IDEA\n")
|
||||||
|
} else {
|
||||||
|
log.Println("This is NOT the jcarrButton")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hostnameButton(hostname string) ui.Control {
|
func hostnameButton(hostname string) ui.Control {
|
||||||
|
@ -26,27 +36,11 @@ func hostnameButton(hostname string) ui.Control {
|
||||||
tmpbox.Append(tmpButton, false)
|
tmpbox.Append(tmpButton, false)
|
||||||
tmpButton.OnClicked(buttonClick)
|
tmpButton.OnClicked(buttonClick)
|
||||||
|
|
||||||
|
jcarrButton = tmpButton
|
||||||
|
|
||||||
return tmpbox
|
return tmpbox
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeButtonsPage(names []string) ui.Control {
|
|
||||||
vbox := ui.NewVerticalBox()
|
|
||||||
vbox.SetPadded(true)
|
|
||||||
|
|
||||||
hbox := ui.NewHorizontalBox()
|
|
||||||
hbox.SetPadded(true)
|
|
||||||
vbox.Append(hbox, false)
|
|
||||||
|
|
||||||
for _, hostname := range names {
|
|
||||||
fmt.Println("hostname=", hostname)
|
|
||||||
vbox.Append(hostnameButton(hostname), false)
|
|
||||||
}
|
|
||||||
|
|
||||||
vbox.Append(ui.NewHorizontalSeparator(), false)
|
|
||||||
|
|
||||||
return vbox
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeGroupEntries() ui.Control {
|
func makeGroupEntries() ui.Control {
|
||||||
group := ui.NewGroup("Entries")
|
group := ui.NewGroup("Entries")
|
||||||
group.SetMargined(true)
|
group.SetMargined(true)
|
||||||
|
@ -57,10 +51,11 @@ func makeGroupEntries() ui.Control {
|
||||||
entryForm.SetPadded(true)
|
entryForm.SetPadded(true)
|
||||||
group.SetChild(entryForm)
|
group.SetChild(entryForm)
|
||||||
|
|
||||||
|
jcarrEntry = ui.NewMultilineEntry()
|
||||||
entryForm.Append("Entry", ui.NewEntry(), false)
|
entryForm.Append("Entry", ui.NewEntry(), false)
|
||||||
entryForm.Append("Password Entry", ui.NewPasswordEntry(), false)
|
entryForm.Append("Password Entry", ui.NewPasswordEntry(), false)
|
||||||
entryForm.Append("Search Entry", ui.NewSearchEntry(), false)
|
entryForm.Append("Search Entry", ui.NewSearchEntry(), false)
|
||||||
entryForm.Append("Multiline Entry", ui.NewMultilineEntry(), true)
|
entryForm.Append("Multiline Entry", jcarrEntry, true)
|
||||||
entryForm.Append("Multiline Entry No Wrap", ui.NewNonWrappingMultilineEntry(), true)
|
entryForm.Append("Multiline Entry No Wrap", ui.NewNonWrappingMultilineEntry(), true)
|
||||||
|
|
||||||
return group
|
return group
|
||||||
|
|
2
main.go
2
main.go
|
@ -87,6 +87,8 @@ func main() {
|
||||||
hostname := config.String("cloud." + account + ".hostname")
|
hostname := config.String("cloud." + account + ".hostname")
|
||||||
fmt.Println(hostname, port, proto)
|
fmt.Println(hostname, port, proto)
|
||||||
addTableTab(account, 4, hostname)
|
addTableTab(account, 4, hostname)
|
||||||
|
log.Println("Sleep for 30 seconds, then add next table")
|
||||||
|
time.Sleep(30 * 1000 * 1000 * 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
55
table.go
55
table.go
|
@ -4,6 +4,7 @@ package main
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "log"
|
import "log"
|
||||||
|
// import "os"
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
import _ "github.com/andlabs/ui/winmanifest"
|
import _ "github.com/andlabs/ui/winmanifest"
|
||||||
import "github.com/davecgh/go-spew/spew"
|
import "github.com/davecgh/go-spew/spew"
|
||||||
|
@ -17,6 +18,13 @@ type vmRowData struct {
|
||||||
disk int
|
disk int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type jwcTest struct {
|
||||||
|
part0 ui.TableColor // row background color
|
||||||
|
part1 ui.TableString // column 0 text
|
||||||
|
part2 ui.TableColor // column 0 text color
|
||||||
|
part3 ui.TableString // column 1 button text
|
||||||
|
}
|
||||||
|
|
||||||
type modelHandler struct {
|
type modelHandler struct {
|
||||||
name string
|
name string
|
||||||
rows int
|
rows int
|
||||||
|
@ -24,12 +32,29 @@ type modelHandler struct {
|
||||||
yellowRow int
|
yellowRow int
|
||||||
checkStates []int
|
checkStates []int
|
||||||
vms []vmRowData
|
vms []vmRowData
|
||||||
|
bgcolor []ui.TableColor
|
||||||
|
|
||||||
|
cellValues []jwcTest
|
||||||
|
|
||||||
columnTypes string
|
columnTypes string
|
||||||
funcColumnTypes func() []ui.TableValue
|
funcColumnTypes func() []ui.TableValue
|
||||||
scanCellValue func(*modelHandler, int, int) ui.TableValue
|
scanCellValue func(*modelHandler, int, int) ui.TableValue
|
||||||
setCellValue func(*modelHandler, *ui.TableModel, int, int, ui.TableValue)
|
setCellValue func(*modelHandler, *ui.TableModel, int, int, ui.TableValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initValues(mh *modelHandler) {
|
||||||
|
for i := 0; i < mh.rows; i++ {
|
||||||
|
log.Println("i=",i)
|
||||||
|
mh.vms[i].hostname = fmt.Sprintf("jcarrnew %d", i)
|
||||||
|
|
||||||
|
mh.cellValues[i].part0 = ui.TableColor{0.1, 0.5, 0.5, .3}
|
||||||
|
mh.cellValues[i].part1 = ui.TableString(fmt.Sprintf("fun %d", i))
|
||||||
|
mh.cellValues[i].part2 = ui.TableColor{0.5, 0.1, 0.1, .7}
|
||||||
|
mh.cellValues[i].part3 = ui.TableString(fmt.Sprintf("awesome %d", i))
|
||||||
|
}
|
||||||
|
// os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
func newModelHandler(rows int) *modelHandler {
|
func newModelHandler(rows int) *modelHandler {
|
||||||
mh := new(modelHandler)
|
mh := new(modelHandler)
|
||||||
|
|
||||||
|
@ -39,11 +64,19 @@ func newModelHandler(rows int) *modelHandler {
|
||||||
mh.scanCellValue = defaultCellValue
|
mh.scanCellValue = defaultCellValue
|
||||||
mh.setCellValue = defaultSetCellValue
|
mh.setCellValue = defaultSetCellValue
|
||||||
mh.bgcolorColumn = 0
|
mh.bgcolorColumn = 0
|
||||||
|
|
||||||
mh.checkStates = make([]int, mh.rows)
|
mh.checkStates = make([]int, mh.rows)
|
||||||
|
|
||||||
mh.vms = make([]vmRowData, mh.rows)
|
mh.vms = make([]vmRowData, mh.rows)
|
||||||
|
mh.bgcolor = make([]ui.TableColor, mh.rows)
|
||||||
|
|
||||||
|
mh.cellValues = make([]jwcTest, mh.rows)
|
||||||
|
|
||||||
mh.vms[1].hostname = "jcarr"
|
mh.vms[1].hostname = "jcarr"
|
||||||
mh.yellowRow = -1
|
mh.yellowRow = -1
|
||||||
|
|
||||||
|
initValues(mh)
|
||||||
|
|
||||||
log.Println("Called newModelhandler() with mh=", mh)
|
log.Println("Called newModelhandler() with mh=", mh)
|
||||||
spew.Dump(mh)
|
spew.Dump(mh)
|
||||||
return mh
|
return mh
|
||||||
|
@ -78,19 +111,29 @@ func makeTable(name string, rows int, row1Name string) (*ui.Table, *modelHandler
|
||||||
func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue {
|
func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue {
|
||||||
switch column {
|
switch column {
|
||||||
case 0:
|
case 0:
|
||||||
if (row % 2) == 1 {
|
return mh.cellValues[row].part0
|
||||||
return ui.TableColor{0.5, 0.5, 0.5, .1}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
case 1:
|
case 1:
|
||||||
return ui.TableString(fmt.Sprintf("jcarrgood %d", row))
|
return mh.cellValues[row].part1
|
||||||
|
case 2:
|
||||||
|
return mh.cellValues[row].part2
|
||||||
|
case 3:
|
||||||
|
return mh.cellValues[row].part3
|
||||||
}
|
}
|
||||||
return ui.TableString(fmt.Sprintf("jcarrbad %d", row))
|
return ui.TableString(fmt.Sprintf("jcarrbad %d", row))
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, value ui.TableValue) {
|
func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, value ui.TableValue) {
|
||||||
if column == 3 { // button row (?)
|
switch column {
|
||||||
|
case 0:
|
||||||
|
// mh.cellValues[row].part0 = ui.TableColor(value)
|
||||||
|
case 1:
|
||||||
|
mh.cellValues[row].part1 = value.(ui.TableString)
|
||||||
|
case 2:
|
||||||
|
// mh.cellValues[row].part2 = ui.TableColor(value)
|
||||||
|
case 3:
|
||||||
|
// mh.cellValues[row].part3 = ui.TableString(value)
|
||||||
log.Println("Button was pressed START", row, column)
|
log.Println("Button was pressed START", row, column)
|
||||||
}
|
}
|
||||||
|
log.Println("ui.TableValue=", value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue