Example #1
0
func main() {
	ir, err := gothic.NewInterpreter()
	if err != nil {
		panic(err)
	}

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

	ir.Eval(`
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
pack .scaleR .scaleG .scaleB
	`)
	ir.MainLoop()
}
Example #2
0
func main() {
	ir, err := gothic.NewInterpreter()
	if err != nil {
		panic(err)
	}

	feet := ir.NewStringVar("feet")
	meters := ir.NewStringVar("meters")
	ir.RegisterCallback("calculate", func() {
		f, _ := strconv.Atof64(feet.Get())
		meters.Set(strconv.Ftoa64(f*0.3048, 'f', 3))
	})

	ir.Eval(`
wm title . "Feet to Meters"
grid [ttk::frame .c -padding "3 3 12 12"] -column 0 -row 0 -sticky nwes
grid columnconfigure . 0 -weight 1; grid rowconfigure . 0 -weight 1

grid [ttk::entry .c.feet -width 7 -textvariable feet] -column 2 -row 1 -sticky we
grid [ttk::label .c.meters -textvariable meters] -column 2 -row 2 -sticky we
grid [ttk::button .c.calc -text "Calculate" -command calculate] -column 3 -row 3 -sticky w

grid [ttk::label .c.flbl -text "feet"] -column 3 -row 1 -sticky w
grid [ttk::label .c.islbl -text "is equivalent to"] -column 1 -row 2 -sticky e
grid [ttk::label .c.mlbl -text "meters"] -column 3 -row 2 -sticky w

foreach w [winfo children .c] {grid configure $w -padx 5 -pady 5}
focus .c.feet
bind . <Return> {calculate}
	`)
	ir.MainLoop()
}
Example #3
0
func main() {
	ir := gothic.NewInterpreter(`
wm title . "Feet to Meters"
grid [ttk::frame .c -padding "3 3 12 12"] -column 0 -row 0 -sticky nwes
grid columnconfigure . 0 -weight 1; grid rowconfigure . 0 -weight 1

grid [ttk::entry .c.feet -width 7 -textvariable feet] -column 2 -row 1 -sticky we
grid [ttk::label .c.meters -textvariable meters] -column 2 -row 2 -sticky we
grid [ttk::button .c.calc -text "Calculate" -command calculate] -column 3 -row 3 -sticky w

grid [ttk::label .c.flbl -text "feet"] -column 3 -row 1 -sticky w
grid [ttk::label .c.islbl -text "is equivalent to"] -column 1 -row 2 -sticky e
grid [ttk::label .c.mlbl -text "meters"] -column 3 -row 2 -sticky w

foreach w [winfo children .c] {grid configure $w -padx 5 -pady 5}
focus .c.feet
bind . <Return> {calculate}
	`)

	ir.RegisterCommand("calculate", func() {
		var f float64
		ir.EvalAs(&f, "set feet")
		ir.Eval("set meters ", strconv.FormatFloat(f*0.3048, 'f', 3, 64))
	})

	<-ir.Done
}
Example #4
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
}
Example #5
0
func main() {
	ir := gothic.NewInterpreter(init_script)
	go proc(ir, "1")
	go proc(ir, "2")
	go proc(ir, "3")
	<-ir.Done
}
Example #6
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
}
Example #7
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
}
Example #8
0
func main() {
	ir := gothic.NewInterpreter(`
foreach n {1 2 3} row {0 1 2} {
	ttk::button .b$n -text "Start $n" -command "proc$n <- 0" -state disabled -width 10
	grid .b$n -column 0 -row $row -padx 2 -pady 2 -sticky nwse
	grid [ttk::progressbar .p$n] -column 1 -row $row -padx 2 -pady 2 -sticky nwse
	grid rowconfigure . $row -weight 1
}
foreach col {0 1} { grid columnconfigure . $col -weight 1 }
	`)
	go proc(ir, "1")
	go proc(ir, "2")
	go proc(ir, "3")
	<-ir.Done
}
Example #9
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
}
Example #10
0
func main() {
	ir, err := gothic.NewInterpreter()
	if err != nil {
		panic(err)
	}

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

	ir.RegisterChannel("dispatcher", c)
	ir.Eval(`ttk::button .b1 -text "Button 1" -command {dispatcher <- button1}`)
	ir.Eval(`ttk::button .b2 -text "Button 2" -command {dispatcher <- button2}`)
	ir.Eval(`ttk::button .b3 -text "Button 3" -command {dispatcher <- button3}`)
	ir.Eval(`pack .b1 .b2 .b3`)
	ir.MainLoop()
}
Example #11
0
func main() {
	img := loadPNG("background.png")
	ir, err := gothic.NewInterpreter()
	if err != nil {
		panic(err)
	}

	ir.UploadImage("bg", img)
	ir.Eval(`
canvas .c -width 640 -height 480 -highlightthickness 0
.c create image 0 0 -anchor nw -image bg -tags mybg
.c lower mybg
pack .c -expand true
	`)
	ir.MainLoop()
}
Example #12
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
}
Example #13
0
func main() {
	ir := gothic.NewInterpreter(init_code)
	ir.RegisterCommand("gocovsel", func() {
		gocov_selection(ir)
	})
	ir.RegisterCommand("gocovtest", func() {
		gocov_update(ir)
	})
	ir.ErrorFilter(func(err error) error {
		if err != nil {
			ir.Eval("tk_messageBox -title Error -icon error -message ",
				strconv.Quote(err.Error()))
		}
		return err
	})
	gocov_test(ir)
	<-ir.Done
}
Example #14
0
File: main.go Project: nsf/gocovgui
func main() {
	g := go_part{
		sort_by:    "coverage",
		sort_order: "desc",
	}
	g.find_gocov()
	g.Interpreter = gothic.NewInterpreter("wm withdraw .")
	g.RegisterCommands("go", &g)
	g.ErrorFilter(func(err error) error {
		if err != nil {
			g.Eval("tk_messageBox -title Error -icon error -message %{%q}", err)
		}
		return err
	})

	if g.gocov_path == "" {
		// oops, still haven't found the gocov tool, let's show
		// a nice gui with various choices
		g.not_found()
	} else {
		g.main()
	}
	<-g.Done
}
Example #15
0
func main() {
	ir, err := gothic.NewInterpreter()
	if err != nil {
		panic(err)
	}

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

	ir.Eval(`
pack [ttk::progressbar .bar] -padx 20 -pady 20
	`)
	ir.MainLoop()
}
Example #16
0
func main() {
	ir, err := gothic.NewInterpreter()
	if err != nil {
		panic(err)
	}

	lastOpVar := ir.NewStringVar("lastOp")
	calcTextVar := ir.NewStringVar("calcText")
	calcTextVar.Set("0")

	ir.RegisterCallback("appendNum", func(n string) {
		if afterOp {
			afterOp = false
			calcTextVar.Set("")
		}
		calcTextVar.Set(calcTextVar.Get() + n)
	})

	ir.RegisterCallback("applyOp", func(op string) {
		if afterOp && lastOp != "=" {
			return
		}
		applyOp(op, calcTextVar)
		lastOpVar.Set(lastOp)
	})

	ir.RegisterCallback("clearAll", func() {
		args[0] = nil
		args[1] = nil
		afterOp = true
		lastOp = ""
		lastOpVar.Set("")
		calcTextVar.Set("0")
	})

	ir.RegisterCallback("plusMinus", func() {
		text := calcTextVar.Get()
		if len(text) == 0 || text[0] == '0' {
			return
		}

		if text[0] == '-' {
			calcTextVar.Set(text[1:])
		} else {
			calcTextVar.Set("-" + text)
		}
	})

	ir.Eval(`
wm title . "GoCalculator"
grid [ttk::frame .f] -column 0 -row 0 -columnspan 3 -sticky we
grid [ttk::entry .f.lastop -textvariable lastOp -justify center -state readonly -width 3] -column 0 -row 0 -sticky we
grid [ttk::entry .f.entry -textvariable calcText -justify right -state readonly] -column 1 -row 0 -sticky we
grid columnconfigure .f 0 -weight 0
grid columnconfigure .f 1 -weight 1
grid [ttk::button .0 -text 0 -command { appendNum 0 }] -column 0 -row 4 -sticky nwes
grid [ttk::button .1 -text 1 -command { appendNum 1 }] -column 0 -row 3 -sticky nwes
grid [ttk::button .2 -text 2 -command { appendNum 2 }] -column 1 -row 3 -sticky nwes
grid [ttk::button .3 -text 3 -command { appendNum 3 }] -column 2 -row 3 -sticky nwes
grid [ttk::button .4 -text 4 -command { appendNum 4 }] -column 0 -row 2 -sticky nwes
grid [ttk::button .5 -text 5 -command { appendNum 5 }] -column 1 -row 2 -sticky nwes
grid [ttk::button .6 -text 6 -command { appendNum 6 }] -column 2 -row 2 -sticky nwes
grid [ttk::button .7 -text 7 -command { appendNum 7 }] -column 0 -row 1 -sticky nwes
grid [ttk::button .8 -text 8 -command { appendNum 8 }] -column 1 -row 1 -sticky nwes
grid [ttk::button .9 -text 9 -command { appendNum 9 }] -column 2 -row 1 -sticky nwes
grid [ttk::button .pm    -text +/- -command plusMinus]   -column 1 -row 4 -sticky nwes
grid [ttk::button .clear -text C -command clearAll]      -column 2 -row 4 -sticky nwes
grid [ttk::button .eq    -text = -command { applyOp = }] -column 3 -row 4 -sticky nwes
grid [ttk::button .plus  -text + -command { applyOp + }] -column 3 -row 3 -sticky nwes
grid [ttk::button .minus -text - -command { applyOp - }] -column 3 -row 2 -sticky nwes
grid [ttk::button .mul   -text * -command { applyOp * }] -column 3 -row 1 -sticky nwes
grid [ttk::button .div   -text / -command { applyOp / }] -column 3 -row 0 -sticky nwes

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

grid rowconfigure . 0 -weight 0
grid rowconfigure . 1 -weight 1
grid rowconfigure . 2 -weight 1
grid rowconfigure . 3 -weight 1
grid rowconfigure . 4 -weight 1
grid columnconfigure . 0 -weight 1
grid columnconfigure . 1 -weight 1
grid columnconfigure . 2 -weight 1
grid columnconfigure . 3 -weight 1

bind . 0             { appendNum 0 }
bind . 1             { appendNum 1 }
bind . 2             { appendNum 2 }
bind . 3             { appendNum 3 }
bind . 4             { appendNum 4 }
bind . 5             { appendNum 5 }
bind . 6             { appendNum 6 }
bind . 7             { appendNum 7 }
bind . 8             { appendNum 8 }
bind . 9             { appendNum 9 }
bind . <KP_Insert>   { appendNum 0 }
bind . <KP_End>      { appendNum 1 }
bind . <KP_Down>     { appendNum 2 }
bind . <KP_Next>     { appendNum 3 }
bind . <KP_Left>     { appendNum 4 }
bind . <KP_Begin>    { appendNum 5 }
bind . <KP_Right>    { appendNum 6 }
bind . <KP_Home>     { appendNum 7 }
bind . <KP_Up>       { appendNum 8 }
bind . <KP_Prior>    { appendNum 9 }
bind . <KP_Add>      { applyOp + }
bind . <KP_Subtract> { applyOp - }
bind . <KP_Multiply> { applyOp * }
bind . <KP_Divide>   { applyOp / }
bind . <KP_Enter>    { applyOp = }
bind . <BackSpace>   { clearAll }
	`)
	ir.MainLoop()
}
Example #17
0
func main() {
	ir := gothic.NewInterpreter(initGUI)
	<-ir.Done
}
Example #18
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 . <KP_Insert>   { go::AppendNum 0 }
bind . 1             { go::AppendNum 1 }
bind . <KP_End>      { go::AppendNum 1 }
bind . 2             { go::AppendNum 2 }
bind . <KP_Down>     { go::AppendNum 2 }
bind . 3             { go::AppendNum 3 }
bind . <KP_Next>     { go::AppendNum 3 }
bind . 4             { go::AppendNum 4 }
bind . <KP_Left>     { go::AppendNum 4 }
bind . 5             { go::AppendNum 5 }
bind . <KP_Begin>    { go::AppendNum 5 }
bind . 6             { go::AppendNum 6 }
bind . <KP_Right>    { go::AppendNum 6 }
bind . 7             { go::AppendNum 7 }
bind . <KP_Home>     { go::AppendNum 7 }
bind . 8             { go::AppendNum 8 }
bind . <KP_Up>       { go::AppendNum 8 }
bind . 9             { go::AppendNum 9 }
bind . <KP_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
}