Posted to tcl by hardkorebob at Wed Aug 05 20:09:24 GMT 2026view pretty
source ytcl.tcl
set BG {bg="#bbb"}
set TEXT_PACK {expand=1,side="left",fill="both",padx=0,pady=0}
set CLI_PACK {expand=0,fill="x",padx=2,pady=2}
set TEXT_PROP {self,wrap="none",undo=True,highlightbackground="#bbb",bg="#bbb",fg="#000",font=("VictorMono",14),relief="flat",padx=5,pady=5,blockcursor=True,insertbackground="red",highlightcolor="#bbb",cursor="cross",spacing2=5,spacing3=5,selectbackground="#444",selectforeground="white"}
set CLI_PROP {self,textvariable=self.theCmd,highlightbackground="#bbb",bg="#aaa",fg="#000",font=("VictorMono",16),relief="flat",highlightcolor="#bbb",cursor="heart",selectbackground="#444",selectforeground="white"}
set STATS_PROP {self,textvariable=self.insPos,relief="flat",bg="#bbb",fg="#000",font=("VictorMono",14)}
set STATS_PACK {expand=0,fill="none",padx=5,pady=2,anchor="nw"}
set PYTXT_PROP {self,height="2",textvariable=self.pyTxt,relief="flat",bg="#bbb",fg="#000",font=("VictorMono",14)}
set PYTXT_PACK {expand=0,fill="none",padx=5,pady=2,anchor="nw"}
set PBP {self,mode="determinate",orient="horizontal",length="1000",style="TProgressbar"}
bang
imp subprocess
frm math *
frm tkinter Tk,Entry,Text,Frame,Label,StringVar
frm tkinter.ttk Progressbar,Style
cl App Tk
+
df s __init__
+
fc l {super().__init__}
fc s configure $BG
vf s main MainWin self
fc s main.pack $TEXT_PACK
fc s main.bind_all {"<Control-t>", self.newFrame}
fc s main.bind_all {"<Control-T>", self.delFrame}
-
de s newFrame
+
vf s sec MainWin self
fc s sec.pack $TEXT_PACK
fc s main.goCli
-
de s delFrame
+
fc s sec.destroy
-
-
cl MainWin Frame
+
df s __init__ parent
+
fc l {super().__init__} parent
va s master parent
fc s configure $BG
vf s theCmd StringVar
vf s insPos StringVar
vf s pyTxt StringVar
vf s py_label Label $PYTXT_PROP
fc s py_label.pack $PYTXT_PACK
vf s pos_label Label $STATS_PROP
fc s pos_label.pack $STATS_PACK
vf s cli_entry Entry $CLI_PROP
fc s cli_entry.pack $CLI_PACK
vf s total_pb Progressbar $PBP
fc s total_pb.pack $CLI_PACK
vf s main_text Text $TEXT_PROP
fc s main_text.pack $TEXT_PACK
vf s style Style self
bd s main_text {
<Escape> goCli
<Tab> indent
<Key> autoComplete
}
bd s cli_entry {
<Up> lineUp
<Down> lineDown
<Escape> clearCmd
<F5> runPy
<Return> mainSend
<Shift-Return> newLine
<Control-Return> showPy
<Control-j> mainfontSize
<Control-o> openFile
<Control-O> openSelf
<Control-s> saveFile
<Control-l> clearText
<Control-f> findWord
<Control-n> newFile
}
fc s style.configure {"TProgressbar",thickness=5}
fc s main_text.config {yscrollcommand=self.trackScroll}
fc s main_text.tag_configure {"currline", background="#aaa"}
fc s main_text.tag_configure {"found", background="#ddd"}
fc s newFile
fc s cli_entry.focus
-
de s newFile
+
va s file_name {"empty"}
fc s clearCmd
fc s clearText
-
df s subProc w,cmd
+
ytr
+
vf l output subprocess.run {cmd,shell=True,executable="/bin/bash",stdout=subprocess.PIPE,stderr=subprocess.PIPE,text=True}
ff l {w == "main"}
+
ff l output.returncode {== 0}
+
fc s main_text.insert {"insert",f"\n{output.stdout}\n"}
-
el
+
fc s clearText
fc s main_text.insert {"insert",output.stderr}
-
-
ef l {w == "sec"}
+
fc s master.sec.main_text.insert {"1.0",output.stdout}
-
el
+
fc s pyTxt.set {output.stdout}
-
-
exc
+
fc s main_text.insert {"1.0",str(e)}
-
-
de s showPy
+
fc s subProc {"sec", f"tclsh {self.file_name}"}
-
de s runPy
+
fc s main_text.mark_set {"insert","end"}
fc s subProc {"main",f"tclsh {self.file_name} | python3"}
fc s main_text.mark_set {"insert","1.0"}
-
de s goCli
+
fc s cli_entry.focus
fc s seeLine
-
de s clearText
+
fc s main_text.delete {"1.0", "end-1c"}
fc s countWords
-
de s clearCmd
+
fc s theCmd.set "''"
fc s main_text.tag_remove {"found","1.0","end"}
-
de s newLine
+
fc s main_text.insert {"insert", f"\n"}
fc s clearCmd
fc s countWords
-
de s getLine
+
vf k line main_text.get {"insert linestart","insert lineend"}
rt line
-
de s delLine
+
vf k line main_text.delete {"insert linestart","insert lineend"}
-
de s highlightLine
+
fc s main_text.tag_remove {"currline","1.0","end"}
fc s main_text.tag_add {"currline","insert linestart","insert lineend"}
-
de s checkLine
+
vf k curline getLine
fc s theCmd.set {f"{curline}"}
fc s highlightLine
-
de s seeLine
+
fc s main_text.see {"insert"}
fc s countWords
-
de s lineUp
+
vf k currline main_text.mark_set {"insert", "insert - 1 line"}
fc s checkLine
fc s seeLine
-
de s lineDown
+
vf k line main_text.mark_set {"insert", "insert + 1 line"}
fc s checkLine
fc s seeLine
-
de s mainSend
+
vf k cmd theCmd.get
fc s delLine
ff l {cmd[:2] == "s "}
+
vf l c {cmd[2:].strip}
fc s subProc {"main",f"{c}"}
fc s main_text.mark_set {"insert","1.0"}
fc s seeLine
-
ef l {cmd[:2] == "e "}
+
vf l c {cmd[2:].strip}
ytr
+
vf l expr eval c
fc s main_text.insert {"insert",f"\n{expr}\n"}
fc s main_text.mark_set {"insert","1.0"}
fc s seeLine
-
exc
+
fc s main_text.insert {"insert",f"\n{e}\n"}
fc s main_text.mark_set {"insert","1.0"}
fc s seeLine
-
-
el
+
fc s main_text.insert {"insert", cmd}
fc s seeLine
-
rt {"break"}
-
de s openIt
+
wi a open {file_name,"r"} file
+
vf l data file.read
fc l file.close
-
fc s clearText
fc s main_text.insert {"1.0",data}
fc s main_text.mark_set {"insert","1.0"}
fc s countWords
-
de s openFile
+
vf t file_name theCmd.get
ff s {file_name == ""}
+
fc s pyTxt.set {"can't open empty!"}
ps
-
fc s clearCmd
fc s openIt
-
de s openSelf
+
va s file_name {"newed"}
fc s openIt
-
de s saveFile
+
ff s file_name {== "empty"}
+
vf t file_name theCmd.get
fc s clearCmd
-
vf k data main_text.get {"1.0","end-1c"}
wi a open {file_name,"w"} file
+
fc l file.write data
fc l file.close
-
fc s countWords
fc s pyTxt.set {"saved"}
-
de s seePy
+
vf k data getLine
va l f {".tmp"}
wi l open {f,"w"} file
+
fc l file.write {f"source ytcl.tcl\n{data}\n"}
fc l file.close
-
fc s subProc {"l",f"tclsh {f}"}
-
df s trackScroll {top,bottom}
+
fc s total_pb.configure {maximum=100}
vf l bot_perc float {bottom} {* 100}
va s {total_pb['value']} bot_perc
-
de s mainfontSize
+
vf k sz theCmd.get
vf l fsz int sz
fc s main_text.configure {font=("VictorMono",fsz)}
fc s clearCmd
-
de s findWord
+
vf k word theCmd.get
ff l word {== ""}
+
fc s pyTxt.set {"empty"}
-
el
+
va l si {"1.0"}
va l tot 0
fc s main_text.tag_remove {"found","1.0","end"}
wh True
+
vf k si main_text.search {word, si, "end"}
ff l not si
+
br
-
va l ei {f"{si}+{len(word)}c"}
fc s main_text.tag_add {"found",si,ei}
va l si ei
ac l tot 1
-
fc s pyTxt.set {f"{tot} found: {word}"}
-
-
de s countWords
+
vf t ins_pos main_text.index {"insert"}
vf k data main_text.get {"1.0","end"}
vf l words_counted data.split
vf l lines_counted data.split {"\n"}
vf l lns len lines_counted
vf l wrds len words_counted
fc s insPos.set {f"{self.ins_pos} {self.file_name} : {wrds} | {lns-1}"}
fc s seePy
fc s total_pb.configure {maximum=lns}
vf k spltpos ins_pos.split {'.'}
vf l inspos int {spltpos[0]}
va s {total_pb['value']} inspos
-
de s indent
+
vf k cursor_pos main_text.index {"insert"}
fc s main_text.insert {cursor_pos, f"+\n\n-"}
fc s main_text.mark_set {"insert", f"{cursor_pos} + 1 line"}
rt {"break"}
-
de s autoComplete
+
vf k cursor_pos main_text.index {"insert"}
ff - {event.char == "'"}
+
fc s main_text.insert {cursor_pos, "'"}
-
ef - {event.char == "<"}
+
fc s main_text.insert {cursor_pos, ">"}
fc s main_text.mark_set {"insert", cursor_pos}
-
ef - {event.char == "("}
+
fc s main_text.insert {cursor_pos, ")"}
fc s main_text.mark_set {"insert", cursor_pos}
-
ef - "event.char == \"\{\""
+
fc s main_text.insert "cursor_pos, \"}\""
fc s main_text.mark_set {"insert", cursor_pos}
-
ef - {event.char == "["}
+
fc s main_text.insert {cursor_pos, "]"}
fc s main_text.mark_set {"insert", cursor_pos}
-
ef - {event.char == '\"'}
+
fc s main_text.insert {cursor_pos, '\"'}
fc s main_text.mark_set {"insert", cursor_pos}
-
-
mn App tclyed