1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  | 
// This creates a simple hello world window
package main
import (
	"go.wit.com/gui"
	"go.wit.com/lib/debugger"
	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/gui/logsettings"
	"go.wit.com/log"
)
// This is the beginning of the binary tree of widgets
var myGui *gui.Node
// this is the primary window. If you close it, the program will exit
var mainWindow *gui.Node
// this is a basic window. the user can open and close it
var basicWindow *gadgets.BasicWindow
// the widget structure for both windows
var section1 *choices
var section2 *choices
func main() {
	if debugger.ArgDebug() {
		log.SetAll(true)
		log.ShowFlags()
	}
	if args.TmpLog {
		// send all log() output to a file in /tmp
		log.SetTmp()
	}
	myGui = gui.New()
	myGui.Default()
	helloworld()
	basicWindow = makebasicWindow()
	// run the debugger if triggered from the commandline
	if debugger.ArgDebug() {
		go func() {
			log.Sleep(2)
			debugger.DebugWindow()
		}()
	}
	// go will sit here until the window exits
	gui.Watchdog()
}
// This initializes the first window and some widgets
func helloworld() {
	mainWindow = myGui.NewWindow("hello world").SetProgName("BASEWIN1")
	box := mainWindow.NewBox("hbox", true)
	// box := mainWindow.Box().Vertical()
	// box := mainWindow.Box().Horizontal()
	section1 = newChoices(box)
	group := box.NewGroup("interact")
	group.NewButton("show basic window", func() {
		basicWindow.Toggle()
	})
	group.NewButton("Which Computer?", func() {
		tmp := section1.computers.String()
		log.Println("computer =", tmp)
		for i, s := range section1.computers.Strings() {
			log.Println("has option", i, s)
		}
	})
	group.NewButton("Which Color?", func() {
		tmp := section1.colors.String()
		log.Println("color =", tmp)
	})
	group.NewButton("Show apple", func() {
		apple.Show()
	})
	group.NewButton("Hide apple", func() {
		apple.Hide()
	})
	group.NewCheckbox("test checkbox").SetChecked(true)
	group.NewLabel("test label")
	gadgets.NewBasicEntry(group, "test entry")
	group.NewButton("set socks", func() {
		section1.SetSocks("blue")
		section2.SetSocks("green")
	})
	group.NewButton("show socks", func() {
		log.Info("main window socks  =", section1.socks.String())
		log.Info("basic window socks =", section2.socks.String())
	})
	group.NewButton("show animal", func() {
		log.Info("main window animal  =", section1.animal.String())
		log.Info("basic window animal =", section2.animal.String())
	})
	group = box.NewGroup("debug")
	group.NewButton("debugger", func() {
		debugger.DebugWindow()
	})
	group.NewButton("log options", func() {
		logsettings.LogWindow()
	})
}
  |