2 # show your vessels on a map
4 # This is part of ypp-sc-tools, a set of third-party tools for assisting
5 # players of Yohoho Puzzle Pirates.
7 # Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
23 # are used without permission. This program is not endorsed or
24 # sponsored by Three Rings.
32 #---------- general utilities ----------
37 if {$debug} { puts "DEBUG $m" }
41 puts stderr "where-vessels: bad usage: $m"
50 #---------- expecting certain errors ----------
52 proc errexpect-setline {lno line} {
53 glset errexpect_lno $lno
54 glset errexpect_line $line
57 proc errexpect-error {m} {
58 global errexpect_line errexpect_lno
59 error $m "$errexpect_line\n" [list YARRG-ERREXPECT $errexpect_lno]
62 proc errexpect-arrayget {arrayvar key} {
64 upvar 1 ${arrayvar}($key) v
65 if {[info exists v]} { return $v }
66 errexpect-error "undefined $key"
69 proc errexpect-arrayget-boolean {arrayvar key} {
70 switch -exact [uplevel 1 [list errexpect-arrayget $arrayvar $key]] {
73 default { errexpect-error "unexpected $key" }
77 proc errexpect-catch {code} {
78 global errorInfo errorCode
82 debug "ERREXPECT CATCH |$rc|$rv|$errorCode|$errorInfo|"
83 if {$rc==1 && ![string compare YARRG-ERREXPECT [lindex $errorCode 0]]} {
84 return [list 1 $rv [lindex $errorCode 1] $errorInfo]
88 return -code $rc -errorinfo $errorInfo -errorcode $errorCode $rv
92 #---------- argument parsing ----------
96 if {$ai >= [llength $argv]} {
97 badusage "option [lindex $argv [expr {$ai-1}]] needs a value"
99 set v [lindex $argv $ai]
104 set notes_loc vessel-notes
105 set scraper {./yppedia-ocean-scraper --chart}
106 set info_cache _vessel-info-cache
107 set info_source rsync.yarrg.chiark.net::yarrg/vessel-info
114 while {[regexp {^\-} [set arg [lindex $argv $ai]]]} {
116 switch -exact -- $arg {
118 --pirate { glset pirate [string totitle [nextarg]] }
119 --ocean { glset ocean [string totitle [nextarg]] }
120 --clipboard-file { load-clipboard-file [nextarg] }
121 --local-html-dir { lappend scraper --local-html-dir=[nextarg] }
122 --notes { glset notes_loc [nextarg] }
123 --vessel-info-source { glset info_source [nextarg] }
124 --debug { incr debug }
125 default { badusage "unknown option $arg" }
128 set argv [lrange $argv $ai end]
129 if {[llength $argv]} { badusage "non-option args not allowed" }
132 proc argdefaults {} {
133 global ocean notes_loc pirate scraper
134 if {![info exists ocean] || ![info exists pirate]} {
135 set cmd {./yarrg --find-window-only --quiet}
136 if {[info exists ocean]} { lappend cmd --ocean $ocean }
137 if {[info exists pirate]} { lappend cmd --pirate $pirate }
138 manyset [split [eval exec $cmd] " "] ocean pirate
139 if {![llength $ocean] || ![llength $pirate]} {
140 error "$ocean $pirate ?"
143 lappend scraper $ocean
147 #---------- loading and parsing the vessel notes ----------
150 global notes_loc notes_data
151 if {[regexp {^\w+\:} $notes_loc]} {
153 debug "FETCHING NOTES $notes_loc"
154 set req [::http::geturl $notes_loc]
155 switch -glob [::http::status $req].[::http::ncode $req] {
157 ok.* { error "retrieving vessel-notes: [::http::code $req]" }
158 * { error "Retrieving vessel-notes: [::http::error $req]" }
160 set newdata [::http::data $req]
163 debug "READING NOTES $notes_loc"
164 set vn [open $notes_loc]
165 set newdata [read $vn]
168 set notes_data $newdata
171 proc parse-notes {} {
172 global notes_data notes
173 catch { unset notes }
176 foreach l [split $notes_data "\n"] {
178 errexpect-setline $lno $l
179 set l [string trim $l]
180 if {![string length $l]} continue
181 if {[regexp {^\#} $l]} continue
182 if {![regexp -expanded \
183 {^ (\d+) (?: \s+([^=]*?) )? \s* =
185 (?: \s+ (\S+) )?)? $} \
186 $l dummy vid vname owner note]} {
187 errexpect-error "badly formatted"
189 set vname [string trim $vname]
190 if {[info exists notes($vid)]} {
191 errexpect-error "duplicate vesselid $vid"
193 set notes($vid) [list $lno $vname $owner $note]
197 proc note-info {lno vid name island description} {
199 lappend note_infos [list $lno $vid $name $island $description]
202 proc display-note-infos {} {
203 global note_infos note_missings notes
205 set nmissing [llength $note_missings]
206 debug "display-note-infos $nmissing [array size notes]"
208 if {[llength $note_infos]} {
209 set tiny "[llength $note_infos] warning(s)"
210 } elseif {$nmissing && [array size notes]} {
211 set tiny "$nmissing missing"
218 foreach info $note_infos {
219 manyset $info lno vid name island description
220 append infodata "vessel"
221 append infodata " $vid"
222 if {[string length $name]} { append infodata " $name" }
223 if {[string length $island]} { append infodata " ($island)" }
224 append infodata ": " $description "\n"
228 if {[string length $infodata]} { append infodata "\n" }
229 append infodata "$nmissing vessel(s) not mentioned in notes:\n"
231 foreach info [lsort $note_missings] {
232 manyset $info island name vid
233 if {[string compare $island $last_island]} {
234 append infodata "# $island:\n"
235 set last_island $island
237 append infodata [format "%-9d %-29s =\n" $vid $name]
241 parser-control-failed-core .cp.ctrl.notes notes \
244 "[llength $note_infos] warning(s);\
245 $nmissing vessel(s) missing" \
246 "Full description of warnings and missing vessels:" \
250 #---------- vessel properties ----------
252 proc info-cache-update {} {
253 global info_source info_cache
254 file mkdir $info_cache
255 exec sh -c "cp -u icons/* $info_cache/."
257 if {[string length $info_source]} {
260 --exclude=*~ --exclude=*.bak --exclude=.* --exclude=*.tmp \
261 $info_source/ $info_cache 2>@ stderr]
262 debug "INFO-CACHE $cmdl"
266 set f [open $info_cache/vessel-info]
267 glset vessel_class_data [read $f]
271 proc vesselclasses-init {} {
272 global vc_game2code vc_code2abbrev vc_code2full vc_codes
274 global vessel_class_data
275 manyset $vessel_class_data classinfos subclassinfos
278 foreach {game code abbrev full} $classinfos {
279 if {![regexp {^[a-z][a-z]$} $code code]} { error "bad code" }
280 if {![regexp {^[a-z][a-z]$} $abbrev abbrev]} { error "bad abbrev" }
281 lappend vc_codes $code
282 set vc_game2code($game) $code
283 set vc_code2abbrev($code) $abbrev
284 set vc_code2full($code) $full
288 global vsc_code2report
290 set vsc_game2code(null) {}
291 set vsc_code2report() Ordinary
292 set vsc_code2report(!) "Special/L.E."
293 foreach {game code full} $subclassinfos {
294 if {![regexp {^[A-Z]$} $code code]} { error "bad code" }
295 set vsc_game2code($game) $code
296 set vsc_code2report($code) $full
300 foreach a {battle borrow dot} {
301 foreach b {ours dot query} {
302 load-icon-combine $a $b
307 proc load-icon {icon} {
309 image create bitmap icon/$icon -file $info_cache/$icon.xbm
312 proc load-icon-combine {args} {
315 set delim "pnmcat -lr "
317 append cmd $delim " <(xbmtopbm $info_cache/$icon.xbm)"
318 set delim " <(pbmmake -white 1 1)"
320 append cmd " | pbmtoxbm"
321 debug "load-icon-combine $cmd"
322 image create bitmap icon/[join $args +] -data [exec bash -c $cmd]
325 proc code-lockown2icon {lockown} {
326 manyset [split $lockown ""] lock notown
328 lindex {battle borrow dot} $lock
330 lindex {ours dot query} $notown
334 proc canvas-horiz-stack {xvar xoff y bind type args} {
336 upvar 1 canvas canvas
337 set id [eval $canvas create $type [expr {$x+$xoff}] $y $args]
338 set bbox [$canvas bbox $id]
339 set x [lindex $bbox 2]
340 $canvas bind $id <ButtonPress> $bind
344 proc code2canvas {code canvas x yvar qty qtylen bind} {
345 global vc_code2abbrev
348 manyset [split $code _] inport class subclass lockown xabbrev
352 set imy [expr {$y+2}]
354 if {!$inport} { incr qtylen -1 }
355 if {$qtylen<=0} { set qtylen {} }
356 set qty [format "%${qtylen}s" $qty]
358 set qtyid [canvas-horiz-stack stackx 0 $y $bind \
359 text -anchor nw -font fixed -text $qty]
362 canvas-horiz-stack stackx 0 $imy $bind \
363 image -anchor nw -image icon/atsea
367 upvar #0 vc_code2abbrev($class) vcabb
368 if {![info exists vcabb]} {
370 image create bitmap icon/$vcabb -data \
371 [exec pbmtext -builtin fixed $class | pnminvert | pnmcrop >t.pnm]
373 canvas-horiz-stack stackx -1 $imy $bind \
374 image -anchor nw -image icon/$vcabb
376 if {[string length $subclass]} {
377 canvas-horiz-stack stackx 0 $y $bind \
378 text -anchor nw -font fixed -text \
383 canvas-horiz-stack stackx 0 $imy $bind \
384 image -anchor nw -image [code-lockown2icon $lockown]
387 if {[string length $xabbrev]} {
388 canvas-horiz-stack stackx 0 $y $bind \
389 text -anchor nw -font fixed -text \
393 set bbox [$canvas bbox $qtyid]
394 set ny [lindex $bbox 3]
395 set bid [$canvas create rectangle \
400 $canvas lower $bid $qtyid
402 $canvas bind $bid <ButtonPress> $bind
405 proc show-report-decode {code} {
408 manyset [split $code _] inport classcode subclass lockown xabbrev
409 manyset [split $lockown ""] lock notown
411 report-set inport [lindex {{At Sea} {In port}} $inport]
412 report-set class $vc_code2full($classcode)
414 upvar #0 vsc_code2report($subclass) subclass_report
415 if {[info exists subclass_report]} {
416 report-set subclass $subclass_report
418 report-set subclass "Subclass \"$subclass\""
421 report-set lock [lindex {
422 {Battle ready} {Unlocked} {Locked}
425 switch -exact $notown {
426 0 { report-set own "Yours" }
427 1 { report-set own "Other pirate's" }
428 2 { report-set own "Owner unknown" }
429 default { report-set own "?? $notown" }
432 if {[string length $xabbrev]} {
433 report-set xabbrev "Notes flags: $xabbrev"
435 report-set xabbrev "No flags in notes"
439 #---------- smashing ----------
443 proc smash-code {code} {
444 manyset [split $code _] inport class subclass lockown xabbrev
446 global smash_subclass
447 if {$smash_subclass && [string length $subclass]} {
451 return [join [list $inport $class $subclass $lockown $xabbrev] _]
454 #---------- filtering ----------
458 proc filter-values/size {} { global vc_codes; return $vc_codes }
459 proc filter-icon/size {code} {
460 upvar #0 vc_code2abbrev($code) abb
463 proc filter-default/size {code} { return 1 }
464 proc filter-says-yes/size {codel} {
465 set sizecode [lindex $codel 1]
466 upvar #0 filter_size($sizecode) yes
470 proc filter-values/lockown {} {
473 lappend vals "$lv$ov"
478 proc filter-icon/lockown {lockown} { return [code-lockown2icon $lockown] }
479 proc filter-default/lockown {lockown} {
480 return [regexp {^[01]|^2[^1]} $lockown]
482 proc filter-says-yes/lockown {codel} {
483 set lockown [lindex $codel 3]
484 upvar #0 filter_lockown($lockown) yes
488 proc filter-validate/xabbre {re} {
492 regsub {^.*:\s*} $emsg {} emsg
493 regsub {^.*(.{30})$} $emsg {\1} emsg
498 proc filter-says-yes/xabbre {codel} {
500 set xabbrev [lindex $codel 4]
501 return [regexp -- $filter_xabbre $xabbrev]
504 proc filter-tickbox-flip {fil} {
505 upvar #0 filter_$fil vars
506 set values [filter-values/$fil]
507 foreach val $values {
508 set vars($val) [expr {!$vars($val)}]
513 proc make-tickbox-filter {fil label rows inrow} {
514 upvar #0 filter_$fil vars
515 set fw [make-filter tickbox $fil $label frame]
516 set values [filter-values/$fil]
517 set nvalues [llength $values]
519 set inrow [expr {($nvalues + $rows) / $rows}]
521 set noicons [catch { info args filter-icon/$fil }]
522 for {set ix 0} {$ix < $nvalues} {incr ix} {
523 set val [lindex $values $ix]
524 set vars($val) [filter-default/$fil $val]
525 checkbutton $fw.$ix -variable filter_${fil}($val) \
526 -font fixed -command redraw-needed
528 $fw.$ix configure -image [filter-icon/$fil $val] -height 16
530 $fw.$ix configure -text [filter-map/$fil $val]
532 grid configure $fw.$ix -sticky sw \
533 -row [expr {$ix / $inrow}] \
534 -column [expr {$ix % $inrow}]
536 button $fw.invert -text flip -command [list filter-tickbox-flip $fil] \
538 grid configure $fw.invert -sticky se \
539 -row [expr {$rows-1}] \
540 -column [expr {$inrow-1}]
543 proc entry-filter-changed {fw fil n1 n2 op} {
545 upvar #0 filter_$fil realvar
546 upvar #0 filterentered_$fil entryvar
547 global def_background
548 debug "entry-filter-changed $fw $fil $entryvar"
550 set error [filter-validate/$fil $entryvar]
551 if {[string length $error]} {
552 $fw.error configure -text $error -foreground white -background red
554 $fw.error configure -text { } -background $def_background
555 set realvar $entryvar
559 puts stderr "FILTER CHECK ERROR $emsg $errorInfo"
563 proc make-entry-filter {fil label def} {
564 global filterentered_$fil
565 upvar #0 filter_$fil realvar
567 set fw [make-filter entry $fil $label frame]
568 entry $fw.entry -textvariable filterentered_$fil
570 glset def_background [$fw.error cget -background]
571 trace add variable filterentered_$fil write \
572 [list entry-filter-changed $fw $fil]
573 pack $fw.entry $fw.error -side top -anchor w
576 proc make-filter {kind fil label ekind} {
578 label .filter.lab_$fil -text $label -justify left
581 set nfilters [llength $filters]
582 grid configure .filter.lab_$fil -row $nfilters -column 0 -sticky nw -pady 4
583 grid configure .filter.$fil -row $nfilters -column 1 -sticky w -pady 3
587 proc make-filters {} {
588 make-tickbox-filter size Size 2 0
589 make-tickbox-filter lockown "Lock/\nowner" 2 6
590 make-entry-filter xabbre "Flags\n regexp" {}
593 proc filterstyle-changed {n1 n2 op} {
595 debug "filterstyle-changed $filterstyle"
599 proc filters-say-yes {code} {
600 global filters filterstyle
601 debug "filters-say-yes $code"
602 set codel [split $code _]
603 set lockown [lindex $codel 3]
604 switch -exact $filterstyle {
606 1 { return [filter-default/lockown $lockown] }
607 2 { return [regexp {^.0} $lockown] }
609 default { error $filterstyle }
612 foreach fil $filters {
613 if {![filter-says-yes/$fil $codel]} { return 0 }
618 #---------- loading and parsing the clipboard (vessel locations) ----------
621 global pirate notes_used note_missings newnotes
625 lappend codel [errexpect-arrayget-boolean vi inPort]
627 set gameclass [errexpect-arrayget vi vesselClass]
628 upvar #0 vc_game2code($gameclass) class
629 if {![info exists class]} {
630 set class "($gameclass)"
631 upvar #0 vc_code2abbrev($class) vcabb
633 set data [exec pbmtext -builtin fixed " $gameclass " \
634 | pnminvert | pnmcrop | pbmtoxbm]
635 debug "INVENTED ICON $vcabb $data"
636 image create bitmap icon/$vcabb -data $data
639 set vc_code2full($class) "Type \"$gameclass\""
643 set gamesubclass [errexpect-arrayget vi vesselSubclass]
644 upvar #0 vsc_game2code($gamesubclass) subclass
645 if {[info exists subclass]} {
646 lappend codel $subclass
648 lappend codel ($gamesubclass)
651 switch -exact [errexpect-arrayget vi isLocked]/[ \
652 errexpect-arrayget vi isBattleReady] {
653 true/false { set lock 2 }
654 false/false { set lock 1 }
655 false/true { set lock 0 }
656 default { errexpect-error "unexpected isLocked/isBattleReady" }
659 set vid [errexpect-arrayget vi vesselId]
660 upvar #0 notes($vid) note
661 set realname [errexpect-arrayget vi vesselName]
662 set island [errexpect-arrayget vi islandName]
666 if {[info exists note]} {
667 manyset $note lno notename owner xabbrev
668 if {[string compare -nocase $realname $notename]} {
669 note-info $lno $vid $realname $island \
670 "notes say name is $notename"
672 if {[string length $owner]} {
673 if {![string compare $owner $pirate]} {
681 append abbrev $xabbrev
682 set notes_used($vid) 1
686 lappend note_missings [list $island $realname $vid]
689 lappend codel "$lock$notown" $xabbrev
690 lappend newnotes [list $vid $realname $owner $xabbrev]
691 set kk "$island [join $codel _]"
692 upvar #0 found($kk) k
693 lappend k [list $vid $realname $owner]
695 debug "CODED $kk $vid $realname"
699 proc parse-clipboard {} {
700 global clipboard found notes notes_used newnotes
702 catch { unset found }
703 catch { unset notes_used }
705 glset note_missings {}
709 set itemre { (\w+) = ([^=]*) }
710 set manyitemre "^\\\[ $itemre ( (?: ,\\ $itemre)* ) \\]\$"
714 foreach l [split $clipboard "\n"] {
716 errexpect-setline $lno $l
717 if {![string length $l]} continue
720 if {![regexp -expanded $manyitemre $l dummy \
721 thiskey thisval rhs]} {
722 errexpect-error "badly formatted"
724 set vi($thiskey) $thisval
725 if {![string length $rhs]} break
726 regsub {^, } $rhs {} rhs
732 if {[llength $newnotes]} {
733 foreach vid [lsort [array names notes]] {
734 if {![info exists notes_used($vid)]} {
735 manyset $notes($vid) lno notename
736 note-info $lno $vid $notename {} \
737 "vessel in notes no longer found"
743 proc load-clipboard-file {fn} {
745 glset clipboard [read $f]
750 #---------- loading and parsing the chart ----------
754 debug "FETCHING CHART"
755 set chart [eval exec $scraper [list | perl -we {
760 yppedia_chart_parse(\*STDIN, (new IO::File ">/dev/null"),
761 sub { sprintf "%d %d", @_; },
762 sub { printf "archlabel %d %d %s\n", @_; },
763 sub { printf "island %s {%s} %s\n", @_; },
764 sub { printf "league %s %s %s.\n", @_; },
765 sub { printf STDERR "warning: %s: incomprehensible: %s", @_; }
767 STDOUT->error and die $!;
776 return [expr {$c * $scale}]
779 proc chart-got/archlabel {args} { }
780 proc chart-got/island {x y isle sizecol} {
781 debug "ISLE $x $y $isle $sizecol"
782 global canvas isleloc
783 set isleloc($isle) [list $x $y]
785 # $canvas create oval \
786 # [expr {[coord $x] - $sz}] [expr {[coord $y] - $sz}] \
787 # [expr {[coord $x] + $sz}] [expr {[coord $y] + $sz}] \
790 if {[string match *_col $sizecol]} { set colour black }
791 $canvas create text [coord $x] [coord $y] \
792 -text $isle -anchor s -fill $colour
794 proc chart-got/league {x1 y1 x2 y2 kind} {
795 # debug "LEAGUE $x1 $y1 $x2 $y2 $kind"
797 set l [$canvas create line \
798 [coord $x1] [coord $y1] \
799 [coord $x2] [coord $y2]]
800 if {![string compare $kind .]} {
801 $canvas itemconfigure $l -dash .
805 proc redraw-needed {} {
807 debug "REDRAW NEEDED"
808 if {[info exists redraw_after]} return
809 set redraw_after [after 250 draw]
813 global chart found isleloc canvas redraw_after islandnames smfound
815 catch { after cancel $redraw_after }
816 catch { unset redraw_after }
820 foreach l [split $chart "\n"] {
821 # debug "CHART-GOT $l"
822 set proc [lindex $l 0]
823 eval chart-got/$proc [lrange $l 1 end]
826 catch { unset smfound }
827 foreach key [lsort [array names found]] {
828 regexp {^(.*) (\S+)$} $key dummy islandname code
829 set smcode [smash-code $code]
830 debug "smashed $code => $smcode"
831 set smkey "$islandname $smcode"
832 foreach vessel $found($key) { lappend smfound($smkey) $vessel }
836 set lastislandname {}
837 foreach smkey [lsort [array names smfound]] {
838 set c [llength $smfound($smkey)]
839 # debug "SHOWING $smkey $c"
840 regexp {^(.*) (\S+)$} $smkey dummy islandname code
842 if {![filters-say-yes $code]} continue
844 if {[string compare $lastislandname $islandname]} {
845 manyset $isleloc($islandname) x y
848 set lastislandname $islandname
849 lappend islandnames $islandname
853 if {$c > 1} { set qty [format %d $c] } else { set qty {} }
854 code2canvas $code $canvas $x y $qty 2 \
855 [list show-report $islandname $code]
859 panner::updatecanvas-bbox .cp.ctrl.pan
865 #---------- parser error reporting ----------
867 proc parser-control-create {w base invokebuttontext etl_title} {
869 button $w.do -text $invokebuttontext -command invoke_$base -pady 3
871 frame $w.resframe -width 120 -height 32
872 button $w.resframe.res -text {} -anchor nw \
873 -padx 1 -pady 1 -borderwidth 0 -justify left
874 glset deffont_$base [$w.resframe.res cget -font]
875 place $w.resframe.res -relx 0.5 -y 0 -anchor n
878 pack $w.resframe -side top -expand y -fill both
883 wm title $eb "where-vessels - $etl_title"
884 wm protocol $eb WM_DELETE_WINDOW [list wm withdraw $eb]
886 label $eb.title -text $etl_title
887 pack $eb.title -side top
889 button $eb.close -text Close -command [list wm withdraw $eb]
890 pack $eb.close -side bottom
892 frame $eb.emsg -bd 2 -relief groove
893 label $eb.emsg.lab -anchor nw -text "Error:"
894 text $eb.emsg.text -height 1
895 pack $eb.emsg.text -side bottom -fill x
896 pack $eb.emsg.lab -side left
898 pack $eb.emsg -side top -pady 2 -fill x
900 frame $eb.text -bd 2 -relief groove
901 pack $eb.text -side bottom -pady 2 -fill both -expand y
903 label $eb.text.lab -anchor nw
905 text $eb.text.text -width 85 \
906 -xscrollcommand [list $eb.text.xscroll set] \
907 -yscrollcommand [list $eb.text.yscroll set]
908 $eb.text.text tag configure error \
909 -background red -foreground white
911 scrollbar $eb.text.xscroll -orient horizontal \
912 -command [list $eb.text.text xview]
913 scrollbar $eb.text.yscroll -orient vertical \
914 -command [list $eb.text.text yview]
916 grid configure $eb.text.lab -row 0 -column 0 -sticky w -columnspan 2
917 grid configure $eb.text.text -row 1 -column 0 -sticky news
918 grid configure $eb.text.yscroll -sticky ns -row 1 -column 1
919 grid configure $eb.text.xscroll -sticky ew -row 2 -column 0
920 grid rowconfigure $eb.text 0 -weight 0
921 grid rowconfigure $eb.text 1 -weight 1
922 grid rowconfigure $eb.text 2 -weight 0
923 grid columnconfigure $eb.text 0 -weight 1
924 grid columnconfigure $eb.text 1 -weight 0
927 proc parser-control-ok-core {w base background show} {
928 debug "parser-control-ok-core $w $base $background $show"
929 upvar #0 deffont_$base deffont
930 $w.resframe.res configure \
931 -background $background -disabledforeground black -font $deffont \
932 -state disabled -command {} \
935 proc parser-control-ok {w base show} {
936 parser-control-ok-core $w $base green $show
938 proc parser-control-none {w base show} {
939 parser-control-ok-core $w $base blue $show
941 proc parser-control-failed-core {w base foreground background smallfont
942 tiny summary fulldesc fulldata} {
943 debug "parser-control-failed-core $w $base $summary $fulldesc"
944 upvar #0 deffont_$base deffont
947 $eb.emsg.text delete 0.0 end
948 $eb.emsg.text insert end $summary
950 $eb.text.lab configure -text $fulldesc
951 $eb.text.text delete 0.0 end
952 $eb.text.text insert end $fulldata
954 regsub -all {.{18}} $tiny "&\n" ewrap
962 $w.resframe.res configure \
963 -background $background -foreground $foreground -font $font \
964 -state normal -command [list wm deiconify $eb] \
968 proc parser-control-failed-expected {w base emsg lno ei fulldesc newdata} {
971 set line [lindex [split $ei "\n"] 0]
972 debug "parser-control-failed-expected: $w $base: $lno: $emsg\n $line"
974 parser-control-failed-core $w $base \
976 "err: [string trim $emsg]: \"$line\"" \
977 "at line $lno: $emsg" \
980 $eb.text.text tag add error $lno.0 $lno.end
981 $eb.text.text see $lno.0
983 proc parser-control-failed-unexpected {w base emsg ei} {
985 parser-control-failed-core $w $base \
987 $emsg $emsg "Details and stack trace:" $ei
990 proc reparse {base varname old fulldesc okshow noneshow parse ok} {
991 upvar #0 $varname var
992 manyset [errexpect-catch {
994 if {[string length [string trim $var]]} {
995 parser-control-ok .cp.ctrl.$base $base $okshow
997 parser-control-none .cp.ctrl.$base $base $noneshow
999 }] failed emsg lno ei
1001 parser-control-failed-expected .cp.ctrl.$base $base \
1002 $emsg $lno $ei $fulldesc $var
1010 #---------- island names selection etc. ----------
1012 proc islandnames-update {} {
1014 .islands.count configure -text [format "ships at %d island(s)" \
1015 [llength $islandnames]]
1018 proc islandnames-select {} {
1019 .islands.clip configure -relief sunken -state disabled
1020 selection own -command islandnames-deselect .islands.clip
1022 proc islandnames-deselect {} {
1023 .islands.clip configure -relief raised -state normal
1026 proc islandnames-handler {offset maxchars} {
1028 return [string range [join $islandnames ", "] \
1029 $offset [expr {$offset+$maxchars-1}]]
1032 #---------- main user interface ----------
1034 proc widgets-setup {} {
1035 global canvas debug pirate ocean filterstyle
1037 wm geometry . 1024x600
1038 wm title . "where-vessels - $pirate on the $ocean ocean"
1042 frame .f -border 1 -relief groove
1045 pack $canvas -expand 1 -fill both
1046 pack .f -expand 1 -fill both -side left
1048 #----- control panels and filter -----
1051 frame .smash -relief groove -bd 2 -padx 1
1052 frame .filter -relief groove -bd 2 -padx 1
1053 frame .islands -pady 2
1054 pack .cp .smash .filter .islands -side top
1056 label .smash.title -text Smash
1057 pack .smash.title -side left
1059 checkbutton .smash.subclass -text Subclass \
1060 -variable smash_subclass -command redraw-needed
1061 pack .smash.subclass -side left
1064 trace add variable filterstyle write filterstyle-changed
1067 label .filter.title.title -text Show
1068 pack .filter.title.title -side left
1069 for {set fing 0} {$fing < 4} {incr fing} {
1070 radiobutton .filter.title.f$fing \
1071 -variable filterstyle -value $fing \
1072 -text [lindex {All Useable Mine These:} $fing]
1073 pack .filter.title.f$fing -side left
1076 grid configure .filter.title -row 0 -column 0 -columnspan 2
1078 #----- control panel -----
1081 pack .cp.ctrl -side left -anchor n
1083 debug "BBOX [$canvas bbox all]"
1085 panner::canvas-scroll-bbox .f.c
1086 panner::create .cp.ctrl.pan .f.c 120 120 $debug
1088 pack .cp.ctrl.pan -side top -pady 0 -padx 5
1090 pack .cp.ctrl.zoom -side top
1092 button .cp.ctrl.zoom.out -text - -font {Courier 16} -command {zoom /2} -pady 0
1093 button .cp.ctrl.zoom.in -text + -font {Courier 16} -command {zoom *2} -pady 0
1094 pack .cp.ctrl.zoom.out .cp.ctrl.zoom.in -side left
1096 parser-control-create .cp.ctrl.acquire \
1098 "Clipboard parsing error" \
1100 pack .cp.ctrl.acquire -side top -pady 2
1102 parser-control-create .cp.ctrl.notes \
1103 notes "Reload notes" \
1104 "Vessel notes loading report" \
1106 pack .cp.ctrl.notes -side top -pady 2
1108 #----- island name count and copy -----
1110 label .islands.count
1111 button .islands.clip -text "copy island names" -pady 2 -padx 2 \
1112 -command islandnames-select
1113 selection handle .islands.clip islandnames-handler
1114 pack .islands.count .islands.clip -side left
1116 #----- decoding etc. report -----
1119 pack .cp.report -side left -anchor n
1121 label .cp.report.island -text { }
1123 canvas .cp.report.abbrev -width 1 -height 15
1125 frame .cp.report.code
1126 label .cp.report.code.lab -text Code:
1127 glset report_code { }
1128 entry .cp.report.code.code -state readonly \
1129 -textvariable report_code -width 15
1130 pack .cp.report.code.lab .cp.report.code.code -side left
1131 frame .cp.report.details -bd 2 -relief groove -padx 2 -pady 2
1133 listbox .cp.report.list -height 5
1135 pack .cp.report.island .cp.report.abbrev .cp.report.details \
1136 .cp.report.list -side top
1137 #pack .cp.report.code -side top
1138 pack configure .cp.report.details -fill x
1140 foreach sw {inport class subclass lock own xabbrev} {
1141 label .cp.report.details.$sw -text { }
1142 pack .cp.report.details.$sw -side top -anchor w
1146 proc report-set {sw val} { .cp.report.details.$sw configure -text $val }
1148 proc show-report {islandname code} {
1149 .cp.report.island configure -text $islandname
1151 .cp.report.abbrev delete all
1153 code2canvas $code .cp.report.abbrev 5 y {} 0 {}
1154 manyset [.cp.report.abbrev bbox all] minx dummy maxx dummy
1155 .cp.report.abbrev configure -width [expr {$maxx-$minx+4}]
1157 glset report_code $code
1158 show-report-decode $code
1160 set kk "$islandname $code"
1161 upvar #0 smfound($kk) k
1163 .cp.report.list delete 0 end
1166 manyset $entry vid name owner
1167 lappend owned($owner) $name
1170 foreach owner [lsort [array names owned]] {
1171 if {[string length $owner]} {
1172 set owndesc "$owner's"
1174 set owndesc "Owner unknown"
1176 .cp.report.list insert end "$owndesc:"
1177 foreach name $owned($owner) {
1178 .cp.report.list insert end " $name"
1183 proc zoom {extail} {
1185 set nscale [expr "\$scale $extail"]
1186 debug "ZOOM $scale $nscale"
1187 if {$nscale < 1 || $nscale > 200} return
1192 proc invoke_acquire {} {
1193 global clipboard errorInfo
1197 set clipboard [clipboard get]
1199 parser-control-failed-unexpected .cp.ctrl.acquire acquire \
1200 $emsg "fetching clipboard:\n\n$errorInfo"
1205 clipboard $old "Clipboard contents:" { acquired ok } { no vessels } {
1213 proc invoke_notes {} {
1214 global notes_data errorInfo notes_loc
1220 parser-control-failed-unexpected .cp.ctrl.notes notes \
1221 $emsg "loading $notes_loc:\n\n$errorInfo"
1226 notes_data $old "Vessel notes:" "loaded ok" { no notes } {
1235 #---------- main program ----------
1239 httpclientsetup where-vessels
1247 if {[catch { parse-clipboard } emsg]} {
1248 puts stderr "$emsg\n$errorInfo"
1251 after idle invoke_notes
1255 # rsync -r --exclude=\*~ yarrg/icons/. ijackson@chiark.greenend.org.uk:/home/ftp/users/ijackson/yarrg/vessel-info/.