Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions tk/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,108 @@ func (w *Canvas) YScrollIncrement() int {
return r
}

// Canvas Plot Geometry
func (w *Canvas) PlotLine(xy []Pos, options map[string]string) error {
// canvas create line x1 y1... xn yn ?option value ...? // 不闭合折线
// canvas create line 10 10 200 50 -fill red -width 3 -tags line1

var tmp1 = ""
for _,pos := range xy {
tmp1 = tmp1 + strconv.Itoa(pos.X) + " " + strconv.Itoa(pos.Y) + " "
}
var tmp2 = ""
for k,v := range options {
tmp2 = tmp2 + "-" +k+ " " + v + " "
}

return eval(fmt.Sprintf("%v create line %v%v", w.id, tmp1, tmp2))
}

func (w *Canvas) PlotRectangle(x1,y1,x2,y2 int, options map[string]string) error {
// canvas create rectangle x1 y1 x2 y2 ?option value ...? // 矩形
// canvas create rectangle 10 10 200 50 -fill red -outline blue -tags rec1

var tmp2 = ""
for k,v := range options {
tmp2 = tmp2 + "-" +k+ " " + v + " "
}

return eval(fmt.Sprintf("%v create rectangle %v %v %v %v %v", w.id, x1,y1,x2,y2, tmp2))
}


func (w *Canvas) PlotOval(x1,y1,x2,y2 int, options map[string]string) error {
// canvas create oval x1 y1 x2 y2 ?option value ...? // 矩形内切椭圆或圆
// canvas create oval 10 10 200 50 -fill red -outline blue -tags oval1

var tmp2 = ""
for k,v := range options {
tmp2 = tmp2 + "-" +k+ " " + v + " "
}

return eval(fmt.Sprintf("%v create oval %v %v %v %v %v", w.id, x1,y1,x2,y2, tmp2))
}

func (w *Canvas) PlotPolygon(xy []Pos, options map[string]string) error {
// canvas create polygon x1 y1 ... xn yn ?option value ...? // 多边形
// canvas create polygon 10 10 180 90 20 45 -fill red -width 3 -tags pol1

var tmp1 = ""
for _,pos := range xy {
tmp1 = tmp1 + strconv.Itoa(pos.X) + " " + strconv.Itoa(pos.Y) + " "
}
var tmp2 = ""
for k,v := range options {
tmp2 = tmp2 + "-" +k+ " " + v + " "
}

return eval(fmt.Sprintf("%v create polygon %v%v", w.id, tmp1, tmp2))
}


func (w *Canvas) PlotText(x1,y1 int, options map[string]string) error {
// canvas create text x y ?option value ...? // 文字
// canvas create text 100 100 -text "A wonderful story" -anchor nw -fill black -tags txt1

var tmp2 = ""
for k,v := range options {
tmp2 = tmp2 + "-" +k+ " " + v + " "
}
// v 值含有空格时使用{}, "text":"{A wonderful story}"

return eval(fmt.Sprintf("%v create text %v %v %v", w.id, x1,y1, tmp2))
}

func (w *Canvas) PlotImage(x1,y1 int, options map[string]string) error {
// canvas create image x y ?option value ...?
// canvas create image 10 10 -image myimg -anchor nw
var tmp2 = ""
for k,v := range options {
tmp2 = tmp2 + "-" +k+ " " + v + " "
}

return eval(fmt.Sprintf("%v create image %v %v %v", w.id, x1,y1, tmp2))
}


func (w *Canvas) PlotWidget(x1,y1 int, options map[string]string) error {
// canvas create window x y ?option value ...?
// canvas create window 10 10 -anchor nw -window .canvas.b
var tmp2 = ""
for k,v := range options {
tmp2 = tmp2 + "-" +k+ " " + v + " "
}

return eval(fmt.Sprintf("%v create window %v %v %v", w.id, x1,y1, tmp2))
}
// 参考:
// http://www.tcl-lang.org/man/tcl8.6/TkCmd/canvas.htm
// https://tkdocs.com/tutorial/canvas.html
// 例子:https://github.com/visualfc/atk/issues/16



// WidgetAttr
func CanvasAttrBackground(color string) *WidgetAttr {
return &WidgetAttr{"background", color}
}
Expand Down
22 changes: 22 additions & 0 deletions tk/plotchart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// package require Plotchart
// https://github.com/tcltk/tklib/blob/master/modules/plotchart/plotchart.tcl
// https://core.tcl-lang.org/tklib/doc/trunk/embedded/www/tklib/files/modules/plotchart/plotchart.html

// package require Plotchart
// canvas .c -background white -width 400 -height 200
// pack .c -fill both
// #
// # Create the plot with its x- and y-axes
// #
// set s [::Plotchart::createXYPlot .c {0.0 100.0 10.0} {0.0 100.0 20.0}]
// foreach {x y} {0.0 32.0 10.0 50.0 25.0 60.0 78.0 11.0 } {
// $s plot series1 $x $y
// }
// $s title "Data series"







51 changes: 51 additions & 0 deletions tk/theme_ttk.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,57 @@ var (
TtkTheme = &ttkTheme{}
)

func (w *BaseWidget) StyleName() string {
// ttk::button .b; winfo class .b // ==> TButton
r, _ := evalAsString(fmt.Sprintf("winfo class %v", w.id))
return r
}

func (w *BaseWidget) StyleLookUp(name, option string) string {
// ttk::style lookup style -option
// ttk::style lookup 1.TButton -font // [---> helvetica 24]
r1, _ := evalAsString(fmt.Sprintf("ttk::style lookup %v -%v", name,option))
return r1
}


func StyleConfigure(name string, options map[string]string) error {
// ttk::style configure style ?-option ?value option value...? ?
// ttk::style configure Emergency.TButton -foreground red -padding 10
// ttk::button .b -text "Hello" -style "Fun.TButton"
var tmp = ""
for k,v := range options {
tmp = tmp + "-" + k + " " + v + " "
}

return eval(fmt.Sprintf("ttk::style configure %v %v", name,tmp))
}

func StyleMap(name string, options map[string]map[string]string) error{
// ttk::style map style ?-option { statespec value... }?
// ttk::style map TRadiobutton -foreground [list !pressed blue pressed yellow] -background [list selected black !selected white]
var tmp1 = ""
var tmp2 = ""
for k1,v1 := range options {
tmp2 = "[list "
tmp1 = tmp1 + "-" + k1 + " "
for k2,v2 := range v1 {
tmp2 = tmp2 + k2 + " " + v2 + " "
}
tmp2 = tmp2 + "] "
tmp1 = tmp1 + tmp2
}
// fmt.Println(fmt.Sprintf("ttk::style map %v %v", name,tmp1))
return eval(fmt.Sprintf("ttk::style map %v %v", name,tmp1))
}

// 参考:
// https://tkdocs.com/tutorial/styles.html
// http://www.tcl-lang.org/man/tcl8.6/TkCmd/ttk_style.htm
// https://tkdocs.com/shipman/ttk-map.html
// 例子:https://github.com/visualfc/atk/issues/17


func init() {
registerInit(func() {
ttk_theme_list, _ = evalAsStringList("ttk::themes")
Expand Down
27 changes: 27 additions & 0 deletions tk/tooltip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// a simple tooltip

// 参考:http://tmml.sourceforge.net/doc/tcllib/tooltip.html

// 例子:widget.Tooltip("This is a widget")

package tk

import "fmt"

var isPackReqTip = false // 保证 "package require tooltip" 只进行一次

func (w *BaseWidget) Tooltip(tip string) error {

// ::tooltip::tooltip pathName ? option arg ? message
// tooltip::tooltip .l "This is a label widget"
if !isPackReqTip {

_ = eval(fmt.Sprintf("package require tooltip"))
// fmt.Printf("package require tooltip ok ? %v\n", ok)
}
// s1 := fmt.Sprintf("tooltip::tooltip %v {%v}", w.id, tip)
// fmt.Printf("s1 is %v\n",s1)
return eval(fmt.Sprintf("tooltip::tooltip %v {%v}", w.id, tip))
}