working transforms from a list
This commit is contained in:
parent
32accf3982
commit
52e8103b92
|
@ -1,5 +1,25 @@
|
||||||
#!/usr/bin/env wish
|
#!/usr/bin/env wish
|
||||||
|
|
||||||
|
set active_transform 0
|
||||||
|
|
||||||
|
proc oneline {text} {
|
||||||
|
return [regsub -all \n+ $text " "]
|
||||||
|
}
|
||||||
|
|
||||||
|
proc wordcount {text} {
|
||||||
|
set lines [expr [llength [split $text \n]] - 1]
|
||||||
|
set words [llength [regexp -all -inline {\S+} $text]]
|
||||||
|
set len [string length $text]
|
||||||
|
|
||||||
|
lappend out $lines
|
||||||
|
lappend out $words
|
||||||
|
lappend out $len
|
||||||
|
return $out
|
||||||
|
}
|
||||||
|
|
||||||
|
lappend transforms [list {One line} oneline]
|
||||||
|
lappend transforms [list {Line/Word/Char} wordcount]
|
||||||
|
|
||||||
wm geometry . 750x650
|
wm geometry . 750x650
|
||||||
wm title . "Text Tools"
|
wm title . "Text Tools"
|
||||||
|
|
||||||
|
@ -7,8 +27,10 @@ text .content
|
||||||
text .output
|
text .output
|
||||||
listbox .transform
|
listbox .transform
|
||||||
|
|
||||||
.transform insert end {One line}
|
foreach {elem} $transforms {
|
||||||
.transform insert end Line/Word/Char
|
.transform insert end [lindex $elem 0]
|
||||||
|
}
|
||||||
|
.transform selection set $active_transform
|
||||||
|
|
||||||
grid .transform -row 1 -column 1 -rowspan 2
|
grid .transform -row 1 -column 1 -rowspan 2
|
||||||
grid .content -row 1 -column 2
|
grid .content -row 1 -column 2
|
||||||
|
@ -16,23 +38,23 @@ grid .output -row 2 -column 2
|
||||||
|
|
||||||
focus .content
|
focus .content
|
||||||
|
|
||||||
proc wordcount {} {
|
proc update_output {} {
|
||||||
|
global active_transform
|
||||||
|
global transforms
|
||||||
|
|
||||||
set text [.content get 1.0 end]
|
set text [.content get 1.0 end]
|
||||||
|
|
||||||
set lines [expr [llength [split $text \n]] - 1]
|
set tf [lindex $transforms $active_transform]
|
||||||
set words [llength [regexp -all -inline {\S+} $text]]
|
set out [[lindex $tf 1] $text]
|
||||||
set len [string length $text]
|
|
||||||
|
|
||||||
lappend out $lines
|
|
||||||
lappend out $words
|
|
||||||
lappend out $len
|
|
||||||
.output replace 1.0 end $out
|
.output replace 1.0 end $out
|
||||||
}
|
}
|
||||||
|
|
||||||
bind .content <KeyRelease> wordcount
|
bind .content <KeyRelease> update_output
|
||||||
|
|
||||||
proc select_transform {} {
|
proc select_transform {args} {
|
||||||
puts {transform selected}
|
global active_transform
|
||||||
|
set active_transform [.transform curselection]
|
||||||
|
update_output
|
||||||
}
|
}
|
||||||
|
|
||||||
bind .transform <Button-1> select_transform
|
bind .transform <Button-1> select_transform
|
||||||
|
|
Loading…
Reference in a new issue