#/bin/wish # # Test wish interface functions # # /* { DEMO - Playlist file service Reads existing playlist on startup. Assumes playlists are in current working directory lilwish (Lil+libpanel) demonstration app Mar 24 2020 (c) That Guy With The Hair } */ # Search a list formatted as to retrieve items, ala associative arrays # Key can't be in a value # proc kget {list key} { set idx [indexof $list @$key] if [streq $idx {}] { return {} } inc idx 1 index $list $idx } set DemoData { @Intro { @Title {This is Title} @Text {Buttons ======= This Demonstration gives an explanation of the widgets in the library } @Form { # # label TOP.I -image [image tklogo.img] -side top -anchor NW # } @Next Pack } @Pack { Next @Next Button @Title {Pack Options} @Text { The Basic display region is divided into five regions TOP or N BOTTOM or S LEFT or WEST RIGHT or EAST } @Form { frame TOP.T -fill BOTH -side top -anchor left -expand 1 group TOP.T.t3 -side S -anchor S -fill x group TOP.T.t1 -side TOP -fill x frame TOP.T.t1.l -side LEFT label TOP.T.t1.l.l1 -text {NORTH LEFT} frame TOP.T.t1.r -side RIGHT label TOP.T.t1.r.l1 -text {NORTH RIGHT} frame TOP.T.c -anchor center -side CENTER -expand 1 label TOP.T.c.l1 -text CENTER -expand 1 -fill BOTH frame TOP.T.t3.l -side LEFT label TOP.T.t3.l.l1 -text {SOUTH LEFT} frame TOP.T.t3.r -side RIGHT label TOP.T.t3.r.l1 -text {SOUTH RIGHT} } } @Button { @Title {Buttons} @Text { Buttons can be one of three types: button - press for command activation check - Print checmark for status radio - Only on one in group } @Form { # # # frame TOP.f0 -side BOTTOM -fill x label TOP.f0.l -text {} -anchor left -fill x frame TOP.f1 -side top button TOP.f1.a -side TOP -text "Btn long name A" -fill x \ -cmd {tkcfg TOP.f0.l -text "This is a message"} button TOP.f1.b -side TOP -text "Btn B" -fill x \ -cmd {tkcfg TOP.f0.l -text "Error"} button TOP.f1.c -side TOP -text "Bnt shorter C" -fill x \ -cmd {tkcfg TOP.f0.l -text "The End"} label TOP.space -side top -text { } frame TOP.f2 -side top checkbutton TOP.f2.a -side TOP -text "Over" -anchor left checkbutton TOP.f2.b -side TOP -text "Under" -anchor left checkbutton TOP.f2.c -side TOP -text "Done" -anchor left label TOP.space2 -side top -text { } frame TOP.f3 -side top radiobutton TOP.f3.a -side TOP -text "Radio Gaga" -anchor left radiobutton TOP.f3.b -side TOP -text "Radio Googoo" -anchor left radiobutton TOP.f3.c -side TOP -text "Radio Hauraki" -anchor left # # # } @Next Text } @Text { @Title {Message Item} @Text { Text does not wrap on line feed characters, wraps at set length. -wraplen #n sets width in pixels -width #n sets minimum pixel width -height #n sets minimum pixel height } @Form { label TOP.l2 -side left -anchor top -text {Msg:} frame TOP.f1 -side top -anchor left set _txt {This is a long text line that will span multiple screen lines vertically. Width is set with '-wraplen #n' option. -width is needed if '-fill X' is not used. There is no way to insert a line space in the middle of the string.} message TOP.f1.edit1 -side left -anchor left -text $_txt -width 200 -wraplen 250 -fill both # } @Next Edit } @Edit { @Title {Text Edit Item} @Text {Multiline editbox. Performs line wrap. Can be edited. Internally uses runes. Text passed with -text is converted to runes automatically. } @Form { label TOP.f1 -text {Edit [README]} set global _EditTxt [system cat README] edit TOP.edit1 -side left -anchor left -text $_EditTxt -width 200 -height 200 -expand 1 scrollbar TOP.sb1 -side right -anchor NE -subwidget [wm id TOP.edit1] -fill Y -width 10 # frame TOP.xx -side right -anchor top -fill y # } @Next Slider } @Slider { @Title {Scrollers } @Text {Sliders. ======== Can be updated via cfg Fixed range 0 - 100 } @Form { label TOP.f1 -text {Sliders} -anchor N set global _EditTxt [system cat README] frame TOP.sliders -fill x slider TOP.sliders.s1 -side left -anchor N -width 30 -fill y label TOP.sliders.l1 -text { } -side left slider TOP.sliders.s2 -side left -anchor left -width 15 -fill y label TOP.sliders.l2 -text { } -side left slider TOP.sliders.s3 -side left -anchor S -width 40 -height 100 label TOP.sliders.l3 -text { } -side left slider TOP.sliders.s4 -side left -anchor S -width 5 -height 120 label TOP.sliders.l4 -text { } -side left slider TOP.sliders.s5 -side left -anchor S -width 50 -height 100 label TOP.sliders.l5 -text { } -side left slider TOP.sliders.s6 -side left -anchor S -width 80 -height 50 frame TOP.slidersh -fill x slider TOP.slidersh.s1 -side top -anchor N -height 30 -fill x label TOP.slidersh.l1 -text { } -side top slider TOP.slidersh.s2 -side top -anchor top -height 15 -width 80 label TOP.slidersh.l2 -text { } -side top slider TOP.slidersh.s2 -side top -anchor top -height 40 -fill x # frame TOP.xx -side right -anchor top -fill y # } @Next TheEnd @After { cfg [wm id TOP.sliders.s1] -value 50 } } @TheEnd { @Title {Thats All Folks} @Text {The End.} @Form {label TOP.loony -image [image thatsall.img]} } @Dagg {The End} } proc cleanup {txt} {repstr $txt "\t" {} } proc exec {code} { set code [repstr $code "#\n" ""] func __tmp {} "${code}" set ret [__tmp] rename __tmp return $ret } set winstack {} proc BuildForm {name} { set top .${name} if [wm exists $top] {tktoplevel $top; return} set data [kget $DemoData $name] set form [kget $data Form] frame $top -side top -anchor NW -fill BOTH frame ${top}.title -side top -anchor center -fill X label ${top}.title.txt -side top -fill x -anchor center -text [kget $data Title] frame ${top}.bot -side bottom -anchor left -fill x frame ${top}.left -side left -fill both group ${top}.right -side left -fill BOTH -expand 1 button ${top}.bot.b1 -side left -anchor left -text BACK -cmd prevFORM button ${top}.bot.b2 -side left -anchor center -text QUIT -cmd evQuit button ${top}.bot.b3 -side right -anchor right -text NEXT -cmd "nextFORM [kget $data Next]" # message ${top}.left.m1 -side top -anchor left -fill y -wraplen 200 \ # -text [cleanup [kget $data Text]] -expand 1 edit ${top}.left.m1 -width 250 -side top -anchor left -fill y -wraplen 300 \ -text [cleanup [kget $data Text]] -expand 1 func TOP {} "return .${name}.right" exec [repstr [cleanup $form] " TOP." " ${top}.right."] rename TOP tktoplevel $top tkpack $top topeval [repstr [kget $data After] " TOP." " ${top}.right."] } proc DisplayForm {name} { BuildForm $name append global winstack $name } proc prevFORM {} { set cnt [count $winstack] dec cnt 2 set top [index $winstack $cnt] inc cnt if [streq $top {}] {return} set winstack [slice $winstack 0 $cnt] tktoplevel .$top } proc nextFORM {next} { set cnt [count $winstack] dec cnt 1 set top [index $winstack $cnt] set wnext [kget [kget $DemoData $top] Next] if not [streq $wnext {}] { DisplayForm $wnext } } DisplayForm Intro eventloop