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}
112 while {[regexp {^\-} [set arg [lindex $argv $ai]]]} {
114 switch -exact -- $arg {
116 --pirate { glset pirate [string totitle [nextarg]] }
117 --ocean { glset ocean [string totitle [nextarg]] }
118 --clipboard-file { load-clipboard-file [nextarg] }
119 --local-html-dir { lappend scraper --local-html-dir=[nextarg] }
120 --notes { glset notes_loc [nextarg] }
121 --debug { incr debug }
122 default { badusage "unknown option $arg" }
125 set argv [lrange $argv $ai end]
126 if {[llength $argv]} { badusage "non-option args not allowed" }
129 proc argdefaults {} {
130 global ocean notes_loc pirate scraper
131 if {![info exists ocean] || ![info exists pirate]} {
132 set cmd {./yarrg --find-window-only --quiet}
133 if {[info exists ocean]} { lappend cmd --ocean $ocean }
134 if {[info exists pirate]} { lappend cmd --pirate $pirate }
135 manyset [split [eval exec $cmd] " "] ocean pirate
137 lappend scraper $ocean
141 #---------- loading and parsing the vessel notes ----------
144 global notes_loc notes_data
145 if {[regexp {^\w+\:} $notes_loc]} {
147 debug "FETCHING NOTES $notes_loc"
148 set req [::http::geturl $notes_loc]
149 switch -glob [::http::status $req].[::http::ncode $req] {
151 ok.* { error "retrieving vessel-notes: [::http::code $req]" }
152 * { error "Retrieving vessel-notes: [::http::error $req]" }
154 set newdata [::http::data $req]
157 debug "READING NOTES $notes_loc"
158 set vn [open $notes_loc]
159 set newdata [read $vn]
162 set notes_data $newdata
165 proc parse-notes {} {
166 global notes_data notes
167 catch { unset notes }
170 foreach l [split $notes_data "\n"] {
172 errexpect-setline $lno $l
173 set l [string trim $l]
174 if {![string length $l]} continue
175 if {[regexp {^\#} $l]} continue
176 if {![regexp -expanded \
177 {^ (\d+) (?: \s+([^=]*?) )? \s* =
179 (?: \s+ (\S+) )?)? $} \
180 $l dummy vid vname owner note]} {
181 errexpect-error "badly formatted"
183 set vname [string trim $vname]
184 if {[info exists notes($vid)]} {
185 errexpect-error "duplicate vesselid $vid"
187 set notes($vid) [list $lno $vname $owner $note]
191 proc note-info {lno vid name island description} {
193 lappend note_infos [list $lno $vid $name $island $description]
196 proc display-note-infos {} {
197 global note_infos note_missings notes
199 set nmissing [llength $note_missings]
200 debug "display-note-infos $nmissing [array size notes]"
202 if {[llength $note_infos]} {
203 set tiny "[llength $note_infos] warning(s)"
204 } elseif {$nmissing && [array size notes]} {
205 set tiny "$nmissing missing"
212 foreach info $note_infos {
213 manyset $info lno vid name island description
214 append infodata "vessel"
215 append infodata " $vid"
216 if {[string length $name]} { append infodata " $name" }
217 if {[string length $island]} { append infodata " ($island)" }
218 append infodata ": " $description "\n"
222 if {[string length $infodata]} { append infodata "\n" }
223 append infodata "$nmissing vessel(s) not mentioned in notes:\n"
225 foreach info [lsort $note_missings] {
226 manyset $info island name vid
227 if {[string compare $island $last_island]} {
228 append infodata "# $island:\n"
229 set last_island $island
231 append infodata [format "%-9d %-29s =\n" $vid $name]
235 parser-control-failed-core .cp.ctrl.notes notes \
238 "[llength $note_infos] warning(s);\
239 $nmissing vessel(s) missing" \
240 "Full description of warnings and missing vessels:" \
244 #---------- vessel properties ----------
246 proc vesselclasses-init {} {
247 global vc_game2code vc_code2abbrev vc_code2full vc_codes
252 longship dm ls Longship
253 baghlah em bg Baghlah
254 merchbrig fm mb {Merchant Brig}
255 warbrig gm wb {War Brig}
257 merchgal jm mg {Merchant Galleon}
258 warfrig im wf {War Frigate}
259 grandfrig km gf {Grand Frigate}
262 foreach {game code abbrev full} $vcl {
263 lappend vc_codes $code
264 set vc_game2code($game) $code
265 set vc_code2abbrev($code) $abbrev
266 set vc_code2full($code) $full
271 foreach a {battle borrow dot} {
272 foreach b {ours dot query} {
273 load-icon-combine $a $b
278 proc load-icon {icon} {
279 image create bitmap icon/$icon -file icons/$icon.xbm
282 proc load-icon-combine {args} {
284 set delim "pnmcat -lr "
286 append cmd $delim " <(xbmtopbm icons/$icon.xbm)"
287 set delim " <(pbmmake -white 1 1)"
289 append cmd " | pbmtoxbm"
290 debug "load-icon-combine $cmd"
291 image create bitmap icon/[join $args +] -data [exec bash -c $cmd]
294 proc code-lockown2icon {lockown} {
295 manyset [split $lockown ""] lock notown
297 lindex {battle borrow dot} $lock
299 lindex {ours dot query} $notown
303 proc canvas-horiz-stack {xvar xoff y bind type args} {
305 upvar 1 canvas canvas
306 set id [eval $canvas create $type [expr {$x+$xoff}] $y $args]
307 set bbox [$canvas bbox $id]
308 set x [lindex $bbox 2]
309 $canvas bind $id <ButtonPress> $bind
313 proc code2canvas {code canvas x yvar qty qtylen bind} {
314 global vc_code2abbrev
317 manyset [split $code _] inport class subclass lockown xabbrev
321 set imy [expr {$y+2}]
323 if {!$inport} { incr qtylen -1 }
324 if {$qtylen<=0} { set qtylen {} }
325 set qty [format "%${qtylen}s" $qty]
327 set qtyid [canvas-horiz-stack stackx 0 $y $bind \
328 text -anchor nw -font fixed -text $qty]
331 canvas-horiz-stack stackx 0 $imy $bind \
332 image -anchor nw -image icon/atsea
336 canvas-horiz-stack stackx -1 $imy $bind \
337 image -anchor nw -image icon/$vc_code2abbrev($class)
339 if {[string length $subclass]} {
340 canvas-horiz-stack stackx 0 $y $bind \
341 text -anchor nw -font fixed -text \
346 canvas-horiz-stack stackx 0 $imy $bind \
347 image -anchor nw -image [code-lockown2icon $lockown]
350 if {[string length $xabbrev]} {
351 canvas-horiz-stack stackx 0 $y $bind \
352 text -anchor nw -font fixed -text \
356 set bbox [$canvas bbox $qtyid]
357 set ny [lindex $bbox 3]
358 set bid [$canvas create rectangle \
363 $canvas lower $bid $qtyid
365 $canvas bind $bid <ButtonPress> $bind
368 proc show-report-decode {code} {
371 manyset [split $code _] inport classcode subclass lockown xabbrev
372 manyset [split $lockown ""] lock notown
374 report-set inport [lindex {{At Sea} {In port}} $inport]
375 report-set class $vc_code2full($classcode)
377 switch -exact $subclass {
378 {} { report-set subclass {Ordinary} }
379 F { report-set subclass {"Frost class"} }
380 default { report-set subclass "Subclass \"$subclass\"" }
383 report-set lock [lindex {
384 {Battle ready} {Unlocked} {Locked}
387 switch -exact $notown {
388 0 { report-set own "Yours" }
389 1 { report-set own "Other pirate's" }
390 2 { report-set own "Owner unknown" }
391 default { report-set own "?? $notown" }
394 if {[string length $xabbrev]} {
395 report-set xabbrev "Notes flags: $xabbrev"
397 report-set xabbrev "No flags in notes"
401 #---------- filtering ----------
405 proc filter-values/size {} { global vc_codes; return $vc_codes }
406 proc filter-icon/size {code} {
407 upvar #0 vc_code2abbrev($code) abb
410 proc filter-default/size {code} { return 1 }
411 proc filter-says-yes/size {codel} {
412 set sizecode [lindex $codel 1]
413 upvar #0 filter_size($sizecode) yes
417 proc filter-values/lockown {} {
420 lappend vals "$lv$ov"
425 proc filter-icon/lockown {lockown} { return [code-lockown2icon $lockown] }
426 proc filter-default/lockown {lockown} {
427 return [regexp {^[01]|^2[^1]} $lockown]
429 proc filter-says-yes/lockown {codel} {
430 set lockown [lindex $codel 3]
431 upvar #0 filter_lockown($lockown) yes
435 proc filter-validate/xabbre {re} {
439 regsub {^.*:\s*} $emsg {} emsg
440 regsub {^.*(.{30})$} $emsg {\1} emsg
445 proc filter-says-yes/xabbre {codel} {
447 set xabbrev [lindex $codel 4]
448 return [regexp -- $filter_xabbre $xabbrev]
451 proc filter-tickbox-flip {fil} {
452 upvar #0 filter_$fil vars
453 set values [filter-values/$fil]
454 foreach val $values {
455 set vars($val) [expr {!$vars($val)}]
460 proc make-tickbox-filter {fil label rows inrow} {
461 upvar #0 filter_$fil vars
462 set fw [make-filter tickbox $fil $label frame]
463 set values [filter-values/$fil]
464 set nvalues [llength $values]
466 set inrow [expr {($nvalues + $rows) / $rows}]
468 set noicons [catch { info args filter-icon/$fil }]
469 for {set ix 0} {$ix < $nvalues} {incr ix} {
470 set val [lindex $values $ix]
471 set vars($val) [filter-default/$fil $val]
472 checkbutton $fw.$ix -variable filter_${fil}($val) \
473 -font fixed -command redraw-needed
475 $fw.$ix configure -image [filter-icon/$fil $val] -height 16
477 $fw.$ix configure -text [filter-map/$fil $val]
479 grid configure $fw.$ix -sticky sw \
480 -row [expr {$ix / $inrow}] \
481 -column [expr {$ix % $inrow}]
483 button $fw.invert -text flip -command [list filter-tickbox-flip $fil] \
485 grid configure $fw.invert -sticky se \
486 -row [expr {$rows-1}] \
487 -column [expr {$inrow-1}]
490 proc entry-filter-changed {fw fil n1 n2 op} {
492 upvar #0 filter_$fil realvar
493 upvar #0 filterentered_$fil entryvar
494 global def_background
495 debug "entry-filter-changed $fw $fil $entryvar"
497 set error [filter-validate/$fil $entryvar]
498 if {[string length $error]} {
499 $fw.error configure -text $error -foreground white -background red
501 $fw.error configure -text { } -background $def_background
502 set realvar $entryvar
506 puts stderr "FILTER CHECK ERROR $emsg $errorInfo"
510 proc make-entry-filter {fil label def} {
511 global filterentered_$fil
512 upvar #0 filter_$fil realvar
514 set fw [make-filter entry $fil $label frame]
515 entry $fw.entry -textvariable filterentered_$fil
517 glset def_background [$fw.error cget -background]
518 trace add variable filterentered_$fil write \
519 [list entry-filter-changed $fw $fil]
520 pack $fw.entry $fw.error -side top -anchor w
523 proc make-filter {kind fil label ekind} {
525 label .filter.lab_$fil -text $label -justify left
528 set nfilters [llength $filters]
529 grid configure .filter.lab_$fil -row $nfilters -column 0 -sticky nw -pady 4
530 grid configure .filter.$fil -row $nfilters -column 1 -sticky w -pady 3
534 proc make-filters {} {
535 make-tickbox-filter size Size 2 0
536 make-tickbox-filter lockown "Lock/\nowner" 2 6
537 make-entry-filter xabbre "Flags\n regexp" {}
540 proc filterstyle-changed {n1 n2 op} {
542 debug "filterstyle-changed $filterstyle"
546 proc filters-say-yes {code} {
547 global filters filterstyle
548 debug "filters-say-yes $code"
549 set codel [split $code _]
550 set lockown [lindex $codel 3]
551 switch -exact $filterstyle {
553 1 { return [filter-default/lockown $lockown] }
554 2 { return [regexp {^.0} $lockown] }
556 default { error $filterstyle }
559 foreach fil $filters {
560 if {![filter-says-yes/$fil $codel]} { return 0 }
565 #---------- loading and parsing the clipboard (vessel locations) ----------
568 global pirate notes_used note_missings newnotes
572 lappend codel [errexpect-arrayget-boolean vi inPort]
574 set gameclass [errexpect-arrayget vi vesselClass]
575 upvar #0 vc_game2code($gameclass) class
576 if {![info exists class]} { errexpect-error "unexpected vesselClass"}
579 set subclass [errexpect-arrayget vi vesselSubclass]
580 switch -exact $subclass {
581 null { lappend codel {} }
582 icy { lappend codel F }
583 default { lappend codel ($subclass) }
586 switch -exact [errexpect-arrayget vi isLocked]/[ \
587 errexpect-arrayget vi isBattleReady] {
588 true/false { set lock 2 }
589 false/false { set lock 1 }
590 false/true { set lock 0 }
591 default { errexpect-error "unexpected isLocked/isBattleReady" }
594 set vid [errexpect-arrayget vi vesselId]
595 upvar #0 notes($vid) note
596 set realname [errexpect-arrayget vi vesselName]
597 set island [errexpect-arrayget vi islandName]
601 if {[info exists note]} {
602 manyset $note lno notename owner xabbrev
603 if {[string compare -nocase $realname $notename]} {
604 note-info $lno $vid $realname $island \
605 "notes say name is $notename"
607 if {[string length $owner]} {
608 if {![string compare $owner $pirate]} {
616 append abbrev $xabbrev
617 set notes_used($vid) 1
621 lappend note_missings [list $island $realname $vid]
624 lappend codel "$lock$notown" $xabbrev
625 lappend newnotes [list $vid $realname $owner $xabbrev]
626 set kk "$island [join $codel _]"
627 upvar #0 found($kk) k
628 lappend k [list $vid $realname]
630 debug "CODED $kk $vid $realname"
634 proc parse-clipboard {} {
635 global clipboard found notes notes_used newnotes
637 catch { unset found }
638 catch { unset notes_used }
640 glset note_missings {}
644 set itemre { (\w+) = ([^=]*) }
645 set manyitemre "^\\\[ $itemre ( (?: ,\\ $itemre)* ) \\]\$"
649 foreach l [split $clipboard "\n"] {
651 errexpect-setline $lno $l
652 if {![string length $l]} continue
655 if {![regexp -expanded $manyitemre $l dummy \
656 thiskey thisval rhs]} {
657 errexpect-error "badly formatted"
659 set vi($thiskey) $thisval
660 if {![string length $rhs]} break
661 regsub {^, } $rhs {} rhs
667 if {[llength $newnotes]} {
668 foreach vid [lsort [array names notes]] {
669 if {![info exists notes_used($vid)]} {
670 manyset $notes($vid) lno notename
671 note-info $lno $vid $notename {} \
672 "vessel in notes no longer found"
678 proc load-clipboard-file {fn} {
680 glset clipboard [read $f]
685 #---------- loading and parsing the chart ----------
689 debug "FETCHING CHART"
690 set chart [eval exec $scraper [list | perl -we {
695 yppedia_chart_parse(\*STDIN, (new IO::File ">/dev/null"),
696 sub { sprintf "%d %d", @_; },
697 sub { printf "archlabel %d %d %s\n", @_; },
698 sub { printf "island %s %s\n", @_; },
699 sub { printf "league %s %s %s.\n", @_; },
700 sub { printf STDERR "warning: %s: incomprehensible: %s", @_; }
702 STDOUT->error and die $!;
711 return [expr {$c * $scale}]
714 proc chart-got/archlabel {args} { }
715 proc chart-got/island {x y args} {
716 # debug "ISLE $x $y $args"
717 global canvas isleloc
718 set isleloc($args) [list $x $y]
720 # $canvas create oval \
721 # [expr {[coord $x] - $sz}] [expr {[coord $y] - $sz}] \
722 # [expr {[coord $x] + $sz}] [expr {[coord $y] + $sz}] \
724 $canvas create text [coord $x] [coord $y] \
725 -text $args -anchor s
727 proc chart-got/league {x1 y1 x2 y2 kind} {
728 # debug "LEAGUE $x1 $y1 $x2 $y2 $kind"
730 set l [$canvas create line \
731 [coord $x1] [coord $y1] \
732 [coord $x2] [coord $y2]]
733 if {![string compare $kind .]} {
734 $canvas itemconfigure $l -dash .
738 proc redraw-needed {} {
740 debug "REDRAW NEEDED"
741 if {[info exists redraw_after]} return
742 set redraw_after [after 250 draw]
746 global chart found isleloc canvas redraw_after islandnames
748 catch { after cancel $redraw_after }
749 catch { unset redraw_after }
753 foreach l [split $chart "\n"] {
754 # debug "CHART-GOT $l"
755 set proc [lindex $l 0]
756 eval chart-got/$proc [lrange $l 1 end]
760 set lastislandname {}
761 foreach key [lsort [array names found]] {
762 set c [llength $found($key)]
763 # debug "SHOWING $key $c"
764 regexp {^(.*) (\S+)$} $key dummy islandname code
766 if {![filters-say-yes $code]} continue
768 if {[string compare $lastislandname $islandname]} {
769 manyset $isleloc($islandname) x y
772 set lastislandname $islandname
773 lappend islandnames $islandname
777 if {$c > 1} { set qty [format %d $c] } else { set qty {} }
778 code2canvas $code $canvas $x y $qty 2 \
779 [list show-report $islandname $code]
783 panner::updatecanvas-bbox .cp.ctrl.pan
789 #---------- parser error reporting ----------
791 proc parser-control-create {w base invokebuttontext etl_title} {
793 button $w.do -text $invokebuttontext -command invoke_$base -pady 3
795 frame $w.resframe -width 120 -height 32
796 button $w.resframe.res -text {} -anchor nw \
797 -padx 1 -pady 1 -borderwidth 0 -justify left
798 glset deffont_$base [$w.resframe.res cget -font]
799 place $w.resframe.res -relx 0.5 -y 0 -anchor n
802 pack $w.resframe -side top -expand y -fill both
807 wm title $eb "where-vessels - $etl_title"
808 wm protocol $eb WM_DELETE_WINDOW [list wm withdraw $eb]
810 label $eb.title -text $etl_title
811 pack $eb.title -side top
813 button $eb.close -text Close -command [list wm withdraw $eb]
814 pack $eb.close -side bottom
816 frame $eb.emsg -bd 2 -relief groove
817 label $eb.emsg.lab -anchor nw -text "Error:"
818 text $eb.emsg.text -height 1
819 pack $eb.emsg.text -side bottom -fill x
820 pack $eb.emsg.lab -side left
822 pack $eb.emsg -side top -pady 2 -fill x
824 frame $eb.text -bd 2 -relief groove
825 pack $eb.text -side bottom -pady 2 -fill both -expand y
827 label $eb.text.lab -anchor nw
829 text $eb.text.text -width 85 \
830 -xscrollcommand [list $eb.text.xscroll set] \
831 -yscrollcommand [list $eb.text.yscroll set]
832 $eb.text.text tag configure error \
833 -background red -foreground white
835 scrollbar $eb.text.xscroll -orient horizontal \
836 -command [list $eb.text.text xview]
837 scrollbar $eb.text.yscroll -orient vertical \
838 -command [list $eb.text.text yview]
840 grid configure $eb.text.lab -row 0 -column 0 -sticky w -columnspan 2
841 grid configure $eb.text.text -row 1 -column 0 -sticky news
842 grid configure $eb.text.yscroll -sticky ns -row 1 -column 1
843 grid configure $eb.text.xscroll -sticky ew -row 2 -column 0
844 grid rowconfigure $eb.text 0 -weight 0
845 grid rowconfigure $eb.text 1 -weight 1
846 grid rowconfigure $eb.text 2 -weight 0
847 grid columnconfigure $eb.text 0 -weight 1
848 grid columnconfigure $eb.text 1 -weight 0
851 proc parser-control-ok-core {w base background show} {
852 debug "parser-control-ok-core $w $base $background $show"
853 upvar #0 deffont_$base deffont
854 $w.resframe.res configure \
855 -background $background -disabledforeground black -font $deffont \
856 -state disabled -command {} \
859 proc parser-control-ok {w base show} {
860 parser-control-ok-core $w $base green $show
862 proc parser-control-none {w base show} {
863 parser-control-ok-core $w $base blue $show
865 proc parser-control-failed-core {w base foreground background smallfont
866 tiny summary fulldesc fulldata} {
867 debug "parser-control-failed-core $w $base $summary $fulldesc"
868 upvar #0 deffont_$base deffont
871 $eb.emsg.text delete 0.0 end
872 $eb.emsg.text insert end $summary
874 $eb.text.lab configure -text $fulldesc
875 $eb.text.text delete 0.0 end
876 $eb.text.text insert end $fulldata
878 regsub -all {.{18}} $tiny "&\n" ewrap
886 $w.resframe.res configure \
887 -background $background -foreground $foreground -font $font \
888 -state normal -command [list wm deiconify $eb] \
892 proc parser-control-failed-expected {w base emsg lno ei fulldesc newdata} {
895 set line [lindex [split $ei "\n"] 0]
896 debug "parser-control-failed-expected: $w $base: $lno: $emsg\n $line"
898 parser-control-failed-core $w $base \
900 "err: [string trim $emsg]: \"$line\"" \
901 "at line $lno: $emsg" \
904 $eb.text.text tag add error $lno.0 $lno.end
905 $eb.text.text see $lno.0
907 proc parser-control-failed-unexpected {w base emsg ei} {
909 parser-control-failed-core $w $base \
911 $emsg $emsg "Details and stack trace:" $ei
914 proc reparse {base varname old fulldesc okshow noneshow parse ok} {
915 upvar #0 $varname var
916 manyset [errexpect-catch {
918 if {[string length [string trim $var]]} {
919 parser-control-ok .cp.ctrl.$base $base $okshow
921 parser-control-none .cp.ctrl.$base $base $noneshow
923 }] failed emsg lno ei
925 parser-control-failed-expected .cp.ctrl.$base $base \
926 $emsg $lno $ei $fulldesc $var
934 #---------- island names selection etc. ----------
936 proc islandnames-update {} {
938 .islands.count configure -text [format "ships at %d island(s)" \
939 [llength $islandnames]]
942 proc islandnames-select {} {
943 .islands.clip configure -relief sunken -state disabled
944 selection own -command islandnames-deselect .islands.clip
946 proc islandnames-deselect {} {
947 .islands.clip configure -relief raised -state normal
950 proc islandnames-handler {offset maxchars} {
952 return [string range [join $islandnames ", "] \
953 $offset [expr {$offset+$maxchars-1}]]
956 #---------- main user interface ----------
958 proc widgets-setup {} {
959 global canvas debug pirate ocean filterstyle
961 wm geometry . 1024x600
962 wm title . "where-vessels - $pirate on the $ocean ocean"
966 frame .f -border 1 -relief groove
969 pack $canvas -expand 1 -fill both
970 pack .f -expand 1 -fill both -side left
972 #----- control panels and filter -----
975 frame .filter -relief groove -bd 2 -padx 1
976 frame .islands -pady 2
977 pack .cp .filter .islands -side top
980 trace add variable filterstyle write filterstyle-changed
983 label .filter.title.title -text Show
984 pack .filter.title.title -side left
985 for {set fing 0} {$fing < 4} {incr fing} {
986 radiobutton .filter.title.f$fing \
987 -variable filterstyle -value $fing \
988 -text [lindex {All Useable Mine These:} $fing]
989 pack .filter.title.f$fing -side left
992 grid configure .filter.title -row 0 -column 0 -columnspan 2
994 #----- control panel -----
997 pack .cp.ctrl -side left -anchor n
999 debug "BBOX [$canvas bbox all]"
1001 panner::canvas-scroll-bbox .f.c
1002 panner::create .cp.ctrl.pan .f.c 120 120 $debug
1004 pack .cp.ctrl.pan -side top -pady 0 -padx 5
1006 pack .cp.ctrl.zoom -side top
1008 button .cp.ctrl.zoom.out -text - -font {Courier 16} -command {zoom /2} -pady 0
1009 button .cp.ctrl.zoom.in -text + -font {Courier 16} -command {zoom *2} -pady 0
1010 pack .cp.ctrl.zoom.out .cp.ctrl.zoom.in -side left
1012 parser-control-create .cp.ctrl.acquire \
1014 "Clipboard parsing error" \
1016 pack .cp.ctrl.acquire -side top -pady 2
1018 parser-control-create .cp.ctrl.notes \
1019 notes "Reload notes" \
1020 "Vessel notes loading report" \
1022 pack .cp.ctrl.notes -side top -pady 2
1024 #----- island name count and copy -----
1026 label .islands.count
1027 button .islands.clip -text "copy island names" -pady 2 -padx 2 \
1028 -command islandnames-select
1029 selection handle .islands.clip islandnames-handler
1030 pack .islands.count .islands.clip -side left
1032 #----- decoding etc. report -----
1035 pack .cp.report -side left -anchor n
1037 label .cp.report.island -text { }
1039 canvas .cp.report.abbrev -width 1 -height 15
1041 frame .cp.report.code
1042 label .cp.report.code.lab -text Code:
1043 glset report_code { }
1044 entry .cp.report.code.code -state readonly \
1045 -textvariable report_code -width 15
1046 pack .cp.report.code.lab .cp.report.code.code -side left
1047 frame .cp.report.details -bd 2 -relief groove -padx 2 -pady 2
1049 listbox .cp.report.list -height 5
1051 pack .cp.report.island .cp.report.abbrev .cp.report.details \
1052 .cp.report.list -side top
1053 #pack .cp.report.code -side top
1054 pack configure .cp.report.details -fill x
1056 foreach sw {inport class subclass lock own xabbrev} {
1057 label .cp.report.details.$sw -text { }
1058 pack .cp.report.details.$sw -side top -anchor w
1062 proc report-set {sw val} { .cp.report.details.$sw configure -text $val }
1064 proc show-report {islandname code} {
1065 .cp.report.island configure -text $islandname
1067 .cp.report.abbrev delete all
1069 code2canvas $code .cp.report.abbrev 5 y {} 0 {}
1070 manyset [.cp.report.abbrev bbox all] minx dummy maxx dummy
1071 .cp.report.abbrev configure -width [expr {$maxx-$minx+4}]
1073 glset report_code $code
1074 show-report-decode $code
1076 set kk "$islandname $code"
1077 upvar #0 found($kk) k
1079 .cp.report.list delete 0 end
1082 manyset $entry vid name
1083 .cp.report.list insert end $name
1087 proc zoom {extail} {
1089 set nscale [expr "\$scale $extail"]
1090 debug "ZOOM $scale $nscale"
1091 if {$nscale < 1 || $nscale > 200} return
1096 proc invoke_acquire {} {
1097 global clipboard errorInfo
1101 set clipboard [clipboard get]
1103 parser-control-failed-unexpected .cp.ctrl.acquire acquire \
1104 $emsg "fetching clipboard:\n\n$errorInfo"
1109 clipboard $old "Clipboard contents:" { acquired ok } { no vessels } {
1117 proc invoke_notes {} {
1118 global notes_data errorInfo notes_loc
1124 parser-control-failed-unexpected .cp.ctrl.notes notes \
1125 $emsg "loading $notes_loc:\n\n$errorInfo"
1130 notes_data $old "Vessel notes:" "loaded ok" { no notes } {
1139 #---------- main program ----------
1144 httpclientsetup where-vessels
1150 if {[catch { parse-clipboard } emsg]} {
1151 puts stderr "$emsg\n$errorInfo"
1154 after idle invoke_notes