Beispiel #1
0
func main() {
	ir := gothic.NewInterpreter(`
		ttk::style configure My.TFrame -background #000000
		ttk::frame .frame -width 100 -height 30 -relief sunken -style My.TFrame

		ttk::scale .scaleR -from 0 -to 255 -length 200 -command {scaleUpdate 0}
		ttk::scale .scaleG -from 0 -to 255 -length 200 -command {scaleUpdate 1}
		ttk::scale .scaleB -from 0 -to 255 -length 200 -command {scaleUpdate 2}

		pack .frame -fill both -expand true
		pack .scaleR .scaleG .scaleB -fill both
	`)

	var RGB [3]int
	ir.RegisterCommand("scaleUpdate", func(idx int, x float64) {
		if RGB[idx] == int(x) {
			return
		}
		RGB[idx] = int(x)
		ir.Eval(`ttk::style configure My.TFrame -background `+
			`#%{%02X}%{%02X}%{%02X}`, RGB[0], RGB[1], RGB[2])
	})

	<-ir.Done
}
Beispiel #2
0
func main() {
	ir := gothic.NewInterpreter(`
		pack [ttk::progressbar .bar1] -padx 20 -pady 20
		pack [ttk::progressbar .bar2] -padx 20 -pady 20
	`)

	go func() {
		i := 0
		inc := -1
		for {
			if i > 99 || i < 1 {
				inc = -inc
			}
			i += inc
			time.Sleep(5e7)
			ir.Eval(`.bar1 configure -value %{}`, i)
		}
	}()

	go func() {
		i := 0
		inc := -1

		for {
			if i > 99 || i < 1 {
				inc = -inc
			}
			i += inc
			time.Sleep(1e8)
			ir.Eval(`.bar2 configure -value %{}`, i)
		}
	}()

	<-ir.Done
}
Beispiel #3
0
func main() {
	ir := gothic.NewInterpreter(init_script)
	go proc(ir, "1")
	go proc(ir, "2")
	go proc(ir, "3")
	<-ir.Done
}
Beispiel #4
0
func main() {
	ir := gothic.NewInterpreter(init_script)
	ir.RegisterCommand("calculate", func() {
		var f float64
		ir.EvalAs(&f, "set feet")
		ir.Eval("set meters %{%.3f}", f*0.3048)
	})

	<-ir.Done
}
Beispiel #5
0
func main() {
	ir := tk.NewInterpreter(`
		namespace eval go {}
		ttk::entry .e -textvariable go::etext
		trace add variable go::etext write go::onchange
		pack .e -fill x -expand true
	`)

	ir.RegisterCommand("go::onchange", func() {
		var s string
		ir.EvalAs(&s, "set go::etext")
		fmt.Println(s)
	})
	<-ir.Done
}
Beispiel #6
0
func main() {
	ir := gothic.NewInterpreter(`
		ttk::button .b1 -text "Button 1" -command {dispatcher <- button1}
		ttk::button .b2 -text "Button 2" -command {dispatcher <- button2}
		ttk::button .b3 -text "Button 3" -command {dispatcher <- button3}
		pack .b1 .b2 .b3
	`)

	c := make(chan string)
	go dispatcher(c)

	ir.RegisterCommand("dispatcher", func(_, arg string) {
		c <- arg
	})

	<-ir.Done
}
Beispiel #7
0
func main() {
	ir := gothic.NewInterpreter(`
set lastOp {}
set calcText 0
wm title . "GoCalculator"

ttk::frame .f
ttk::entry .f.lastop -textvariable lastOp -justify center -state readonly -width 3
ttk::entry .f.entry -textvariable calcText -justify right -state readonly

grid .f.lastop .f.entry -sticky we
grid columnconfigure .f 1 -weight 1

ttk::button .0 -text 0 -command { go::AppendNum 0 }
ttk::button .1 -text 1 -command { go::AppendNum 1 }
ttk::button .2 -text 2 -command { go::AppendNum 2 }
ttk::button .3 -text 3 -command { go::AppendNum 3 }
ttk::button .4 -text 4 -command { go::AppendNum 4 }
ttk::button .5 -text 5 -command { go::AppendNum 5 }
ttk::button .6 -text 6 -command { go::AppendNum 6 }
ttk::button .7 -text 7 -command { go::AppendNum 7 }
ttk::button .8 -text 8 -command { go::AppendNum 8 }
ttk::button .9 -text 9 -command { go::AppendNum 9 }
ttk::button .pm    -text +/- -command go::PlusMinus
ttk::button .clear -text C -command go::ClearAll
ttk::button .eq    -text = -command { go::ApplyOp = }
ttk::button .plus  -text + -command { go::ApplyOp + }
ttk::button .minus -text - -command { go::ApplyOp - }
ttk::button .mul   -text * -command { go::ApplyOp * }
ttk::button .div   -text / -command { go::ApplyOp / }

grid .f -   -      .div   -sticky nwes
grid .7 .8  .9     .mul   -sticky nwes
grid .4 .5  .6     .minus -sticky nwes
grid .1 .2  .3     .plus  -sticky nwes
grid .0 .pm .clear .eq    -sticky nwes

grid configure .f -sticky we

foreach w [winfo children .] {grid configure $w -padx 3 -pady 3}

foreach i {1 2 3 4} { grid rowconfigure . $i -weight 1 }
foreach i {0 1 2 3} { grid columnconfigure . $i -weight 1 }

bind . 0             { go::AppendNum 0 }
bind . <Insert>      { go::AppendNum 0 }
bind . 1             { go::AppendNum 1 }
bind . <End>         { go::AppendNum 1 }
bind . 2             { go::AppendNum 2 }
bind . <Down>        { go::AppendNum 2 }
bind . 3             { go::AppendNum 3 }
bind . <Next>        { go::AppendNum 3 }
bind . 4             { go::AppendNum 4 }
bind . <Left>        { go::AppendNum 4 }
bind . 5             { go::AppendNum 5 }
bind . <Clear>       { go::AppendNum 5 }
bind . 6             { go::AppendNum 6 }
bind . <Right>       { go::AppendNum 6 }
bind . 7             { go::AppendNum 7 }
bind . <Home>        { go::AppendNum 7 }
bind . 8             { go::AppendNum 8 }
bind . <Up>          { go::AppendNum 8 }
bind . 9             { go::AppendNum 9 }
bind . <Prior>       { go::AppendNum 9 }
bind . +             { go::ApplyOp + }
bind . <KP_Add>      { go::ApplyOp + }
bind . -             { go::ApplyOp - }
bind . <KP_Subtract> { go::ApplyOp - }
bind . *             { go::ApplyOp * }
bind . <KP_Multiply> { go::ApplyOp * }
bind . /             { go::ApplyOp / }
bind . <KP_Divide>   { go::ApplyOp / }
bind . <Return>      { go::ApplyOp = }
bind . <KP_Enter>    { go::ApplyOp = }
bind . <BackSpace>   { go::ClearAll }
	`)
	ir.RegisterCommands("go", &calc{
		Interpreter: ir,
		afterOp:     true,
	})
	<-ir.Done
}
Beispiel #8
0
func main() {
	ir := gothic.NewInterpreter(initGUI)
	<-ir.Done
}