#!/usr/bin/env wish set txtheight 10 set imgx 250 set imgy 250 set pad 5 set use_boilerplate 1 if {[llength $argv]} { if {[string match [lindex $argv 0] {-small}]} { set txtheight 5 set imgx 250 set imgy 150 set pad 0 set argv [lreplace $argv 0 0] } } set files $argv proc get {} { global file ;# set by .mid.picker option menu global txtheight imgx imgy pad use_boilerplate exec djpeg $file | pnmscale -xysize $imgx $imgy > /tmp/foo.ppm catch {image delete img} image create photo img -file /tmp/foo.ppm .picture.l configure -image img set comment [string trim [exec rdjpgcom $file] \n] # # hack for xv: regsub -- {CREATOR: XV.*Smoothing = [0-9]*} $comment {} comment # hack for USB key camera: regsub -- {^ Corp } $comment {} comment ### ### To fix errors in existing comments, use something like the ### following: ### regsub -- {\(c\) 2002} $comment {(c) 2003} comment .comment.t delete 1.0 end .comment.t insert 1.0 $comment if $use_boilerplate { set bp [string trim [.plate.t get 1.0 end] \n] if {[string last $bp $comment] == -1} { # no match - $bp is not in $comment set pos [.comment.t index end-1c] .comment.t insert end "$bp" .comment.t mark set insert $pos } } focus .comment.t } proc put {} { global file ;# set by .mid.picker option menu global txtheight imgx imgy pad set comment [.comment.t get 1.0 end] catch {file delete ${file}.new} catch {file delete ${file}.old} exec wrjpgcom -replace $file << $comment > ${file}.new file rename -- $file ${file}.old file rename -- ${file}.new $file } proc clockwise {} { global file ;# set by .mid.picker option menu catch {file delete ${file}.new} catch {file delete ${file}.old} exec jpegtran -rotate 90 < $file > $file.new file rename -- $file ${file}.old file rename -- ${file}.new $file get } proc widdershins {} { global file ;# set by .mid.picker option menu catch {file delete ${file}.new} catch {file delete ${file}.old} exec jpegtran -rotate 270 < $file > $file.new file rename -- $file ${file}.old file rename -- ${file}.new $file get } proc save_next {} { global file ;# set by .mid.picker option menu global files ;# from arguments put set index [lsearch -exact $files $file] if {$index == -1} { error "$file not found in list $files" exit 1 } if {$index == [llength $files] - 1} { tk_dialog .notice Notice "Already at last file in list." {} 0 OK } else { set file [lindex $files [expr $index + 1]] get } } proc save_prev {} { global file ;# set by .mid.picker option menu global files ;# from arguments put set index [lsearch -exact $files $file] if {$index == -1} { error "$file not found in list $files" exit 1 } if {$index == 0} { tk_dialog .notice Notice "Already at first file in list." {} 0 OK } else { set file [lindex $files [expr $index - 1]] get } } ###################################################################### # set geometry here to avoid resizing frame .picture -width [expr $imgx + $pad] -height [expr $imgy + $pad] label .picture.l place .picture.l -in .picture -relx 0.5 -rely 0.5 -anchor c frame .mid label .mid.l -text "File:" set menu [eval tk_optionMenu .mid.picker file $files] frame .mid.top button .mid.top.get -text Revert -command get button .mid.top.put -text Save -command put button .mid.top.widdershins -text 270° -command widdershins button .mid.top.clockwise -text 90° -command clockwise button .mid.top.quit -text Quit -command {exit 0} frame .mid.bottom button .mid.bottom.prev -text "Save; Back" -command save_prev button .mid.bottom.next -text "Save; Next" -command save_next pack \ .mid.top.get .mid.top.put \ .mid.top.widdershins \ .mid.top.clockwise \ .mid.top.quit \ -side left pack \ .mid.bottom.prev .mid.bottom.next \ -side left pack \ .mid.l \ .mid.picker \ -side left pack \ .mid.top \ -side top pack \ .mid.bottom \ -side top frame .comment label .comment.l -text "Comment:" -anchor w text .comment.t -width 80 -height $txtheight -font {lucidatypewriter -10} pack .comment.l .comment.t -side top -fill x frame .scratch label .scratch.l -text "Scratchpad:" -anchor w text .scratch.t -width 80 -height $txtheight -font {lucidatypewriter -8} pack .scratch.l .scratch.t -side top -fill x frame .plate checkbutton .plate.l -text "Boilerplate:" -variable use_boilerplate -anchor w text .plate.t -width 80 -height $txtheight -font {lucidatypewriter -8} pack .plate.l .plate.t -side top -fill x pack .picture .mid .comment .scratch .plate -side top -fill x set numentries [$menu index last] if {$numentries > 15} { for {set i 10} {$i < $numentries} {incr i 10} { $menu entryconfigure $i -columnbreak 1 } } ###################################################################### update idletasks if {[file exists ~/.jpgboilerplate]} { set f [open ~/.jpgboilerplate r] set bp [read $f] close $f .plate.t delete 1.0 end .plate.t insert end $bp } trace variable file w {get ;#} get