Tcl/Tkによるお手軽GUI(CUIを補助)
mingwでTcl/Tkがビルドできた話は前に書いたが
折角なので、一応ある程度使えるレベルにまでしてみた
まずはスクショ
メニューバー付くとちょっといい感じに
なので、シェル・コンソールから切り離されてはいない
どういうことかというと・・・・
まず、最初はshell scriput コマンド scr をコンソールから実行
scr
--------------------------------------------
echo from CUI to GUI by Tcl/Tk
./tcltk/scr.tcl
./@@@@
--------------------------------------------
./tcltk/scr.tcl がGUIの実体だけどその次に謎の@@@@を起動している
で
./tcltk/scr.tcl
-----------------------------------------
#!/mingw/bin/wish86.exe
proc cmdw {arg} {
exec echo $arg > ./@@@@
exit
}
proc cmdwl {arg} {
exec echo $arg > ./@@@@
exec echo scr >> ./@@@@
exit
}
proc cmdwl2 {arg1 arg2} {
exec echo $arg1 $arg2 > ./@@@@
exec echo scr >> ./@@@@
exit
}
proc slnmK3a {} {
exec echo cd ./Selenium > ./@@@@
exec echo echo cd ./Selenium >> ./@@@@
exec echo ./kabucom3a >> ./@@@@
exec echo echo ./kabucom3a >> ./@@@@
exec echo cd .. >> ./@@@@
exec echo scr >> ./@@@@
exit
}
wm title . "SU/CAR-ST-AP-cells"
wm iconbitmap . ./tcltk/pike32.ico
wm resizable . 0 0
image create photo stap -file ./tcltk/staps.gif
image create photo matsui -file ./tcltk/matsui_logo.gif
image create photo kabucom -file ./tcltk/logo-kabucom01.gif
image create photo firefx -file ./tcltk/firefox.gif
#button .bdl -text "DL" -command {exec cmd /C start http://k-db.com/stocks/}
#button .bpr -text "Prtr" -command {exec bash -c ./Protra/Protra.exe &}
button .bst -image stap -command {exec cmd /C start http://supercar.hatenablog.com/}
button .bmt -image matsui -command {exec cmd /C start https://www.deal.matsui.co.jp/ITS/login/MemberLogin.jsp}
button .bkc -image kabucom -command {exec cmd /C start https://s10.kabu.co.jp/_mem_bin/members/login.asp?/members/}
button .bkf -image firefx -command {exec bash -c firefox &}
button .b0 -text "Q buy" -command {cmdwl ./suQ/carbuy}
button .b1 -text "Q buy2" -command {cmdwl ./suQ/carbuy2}
button .b2 -text "R _now" -command {cmdwl ./suR/car_now}
#button .bsn -text "SlnmK3a" -command {slnmK3a}
button .b3 -text "Exit" -command {cmdw exit}
pack .b0 .b1 .b2 -side left -fill y
pack .b3 .bst .bmt .bkc .bkf -side right -fill y
menu .m -type menubar
. configure -menu .m
.m add cascade -label "Preparation" -underline 0 -menu .m.m1
menu .m.m1 -tearoff no
.m.m1 add command -label "Download" -underline 0 -command {exec cmd /C start http://k-db.com/stocks/}
.m.m1 add separator
.m.m1 add radiobutton -label "Protra" -underline 0 -command {exec bash -c ./Protra/Protra.exe &}
.m.m1 add separator
.m.m1 add command -label "Exit" -underline 0 -command {cmdw exit}
.m add cascade -label "systemQ" -underline 6 -menu .m.m2
menu .m.m2 -tearoff no
.m.m2 add command -label "Buy" -underline 0 -command {cmdwl ./suQ/carbuy}
.m.m2 add command -label "buy2" -underline 3 -command {cmdwl ./suQ/carbuy2}
.m.m2 add separator
.m.m2 add command -label "Output" -underline 0 -command {exec cmd /C start ./suQ/output/carall.txt}
.m add cascade -label "systemR" -underline 6 -menu .m.m3
menu .m.m3 -tearoff no
.m.m3 add command -label "Now" -underline 0 -command {cmdwl ./suR/car_now}
.m add cascade -label "Selenium" -underline 0 -menu .m.m4
menu .m.m4 -tearoff no
.m.m4 add command -label "Open" -underline 0 -command {exec cmd /C start ./Selenium/kabucom3a.csv}
.m.m4 add command -label "Kabucom3a" -underline 0 -command {slnmK3a}
---------------------------------------------
わかりますでしょうか?
時間のかかる処理は実行しないでechoで./@@@@にリダイレクトしているだけ
そして最後に scr を追加しそのままGUIプログラムを終了してる!
proc cmdwl {arg} {
exec echo $arg > ./@@@@
exec echo scr >> ./@@@@
exit
}
GUIプログラムは終了するけど、やるべき仕事は./@@@@に書いてあるので
最初のshell scriput コマンド scr に制御が戻った際に、./@@@@を実行してくれる
そして、./@@@@の最後にはscrが書いてあるので再びscrが起動し最初に戻る
という仕組み
トリッキーだけど結構便利なワザで、MS-DOS時代(1990年前半)に覚えた
メモリを食わないメニュープログラムが作れて重宝しました
GUI化してないコマンドはGUIを終了してコンソールからCUIで実行
GUI使いたいときはコンソールからscrとタイプすればいい
まあ、プロトタイプならありでしょ?
ユーザーは自分だけだしw