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
136 if {![llength $ocean] || ![llength $pirate]} {
137 error "$ocean $pirate ?"
140 lappend scraper $ocean
144 #---------- loading and parsing the vessel notes ----------
147 global notes_loc notes_data
148 if {[regexp {^\w+\:} $notes_loc]} {
150 debug "FETCHING NOTES $notes_loc"
151 set req [::http::geturl $notes_loc]
152 switch -glob [::http::status $req].[::http::ncode $req] {
154 ok.* { error "retrieving vessel-notes: [::http::code $req]" }
155 * { error "Retrieving vessel-notes: [::http::error $req]" }
157 set newdata [::http::data $req]
160 debug "READING NOTES $notes_loc"
161 set vn [open $notes_loc]
162 set newdata [read $vn]
165 set notes_data $newdata
168 proc parse-notes {} {
169 global notes_data notes
170 catch { unset notes }
173 foreach l [split $notes_data "\n"] {
175 errexpect-setline $lno $l
176 set l [string trim $l]
177 if {![string length $l]} continue
178 if {[regexp {^\#} $l]} continue
179 if {![regexp -expanded \
180 {^ (\d+) (?: \s+([^=]*?) )? \s* =
182 (?: \s+ (\S+) )?)? $} \
183 $l dummy vid vname owner note]} {
184 errexpect-error "badly formatted"
186 set vname [string trim $vname]
187 if {[info exists notes($vid)]} {
188 errexpect-error "duplicate vesselid $vid"
190 set notes($vid) [list $lno $vname $owner $note]
194 proc note-info {lno vid name island description} {
196 lappend note_infos [list $lno $vid $name $island $description]
199 proc display-note-infos {} {
200 global note_infos note_missings notes
202 set nmissing [llength $note_missings]
203 debug "display-note-infos $nmissing [array size notes]"
205 if {[llength $note_infos]} {
206 set tiny "[llength $note_infos] warning(s)"
207 } elseif {$nmissing && [array size notes]} {
208 set tiny "$nmissing missing"
215 foreach info $note_infos {
216 manyset $info lno vid name island description
217 append infodata "vessel"
218 append infodata " $vid"
219 if {[string length $name]} { append infodata " $name" }
220 if {[string length $island]} { append infodata " ($island)" }
221 append infodata ": " $description "\n"
225 if {[string length $infodata]} { append infodata "\n" }
226 append infodata "$nmissing vessel(s) not mentioned in notes:\n"
228 foreach info [lsort $note_missings] {
229 manyset $info island name vid
230 if {[string compare $island $last_island]} {
231 append infodata "# $island:\n"
232 set last_island $island
234 append infodata [format "%-9d %-29s =\n" $vid $name]
238 parser-control-failed-core .cp.ctrl.notes notes \
241 "[llength $note_infos] warning(s);\
242 $nmissing vessel(s) missing" \
243 "Full description of warnings and missing vessels:" \
247 #---------- vessel properties ----------
249 proc vesselclasses-init {} {
250 global vc_game2code vc_code2abbrev vc_code2full vc_codes
255 longship dm ls Longship
256 baghlah em bg Baghlah
257 merchbrig fm mb {Merchant Brig}
258 warbrig gm wb {War Brig}
260 merchgal jm mg {Merchant Galleon}
261 warfrig im wf {War Frigate}
262 grandfrig km gf {Grand Frigate}
265 foreach {game code abbrev full} $vcl {
266 lappend vc_codes $code
267 set vc_game2code($game) $code
268 set vc_code2abbrev($code) $abbrev
269 set vc_code2full($code) $full
274 foreach a {battle borrow dot} {
275 foreach b {ours dot query} {
276 load-icon-combine $a $b
281 proc load-icon {icon} {
282 image create bitmap icon/$icon -file icons/$icon.xbm
285 proc load-icon-combine {args} {
287 set delim "pnmcat -lr "
289 append cmd $delim " <(xbmtopbm icons/$icon.xbm)"
290 set delim " <(pbmmake -white 1 1)"
292 append cmd " | pbmtoxbm"
293 debug "load-icon-combine $cmd"
294 image create bitmap icon/[join $args +] -data [exec bash -c $cmd]
297 proc code-lockown2icon {lockown} {
298 manyset [split $lockown ""] lock notown
300 lindex {battle borrow dot} $lock
302 lindex {ours dot query} $notown
306 proc canvas-horiz-stack {xvar xoff y bind type args} {
308 upvar 1 canvas canvas
309 set id [eval $canvas create $type [expr {$x+$xoff}] $y $args]
310 set bbox [$canvas bbox $id]
311 set x [lindex $bbox 2]
312 $canvas bind $id <ButtonPress> $bind
316 proc code2canvas {code canvas x yvar qty qtylen bind} {
317 global vc_code2abbrev
320 manyset [split $code _] inport class subclass lockown xabbrev
324 set imy [expr {$y+2}]
326 if {!$inport} { incr qtylen -1 }
327 if {$qtylen<=0} { set qtylen {} }
328 set qty [format "%${qtylen}s" $qty]
330 set qtyid [canvas-horiz-stack stackx 0 $y $bind \
331 text -anchor nw -font fixed -text $qty]
334 canvas-horiz-stack stackx 0 $imy $bind \
335 image -anchor nw -image icon/atsea
339 canvas-horiz-stack stackx -1 $imy $bind \
340 image -anchor nw -image icon/$vc_code2abbrev($class)
342 if {[string length $subclass]} {
343 canvas-horiz-stack stackx 0 $y $bind \
344 text -anchor nw -font fixed -text \
349 canvas-horiz-stack stackx 0 $imy $bind \
350 image -anchor nw -image [code-lockown2icon $lockown]
353 if {[string length $xabbrev]} {
354 canvas-horiz-stack stackx 0 $y $bind \
355 text -anchor nw -font fixed -text \
359 set bbox [$canvas bbox $qtyid]
360 set ny [lindex $bbox 3]
361 set bid [$canvas create rectangle \
366 $canvas lower $bid $qtyid
368 $canvas bind $bid <ButtonPress> $bind
371 proc show-report-decode {code} {
374 manyset [split $code _] inport classcode subclass lockown xabbrev
375 manyset [split $lockown ""] lock notown
377 report-set inport [lindex {{At Sea} {In port}} $inport]
378 report-set class $vc_code2full($classcode)
380 switch -exact $subclass {
381 {} { report-set subclass {Ordinary} }
382 E { report-set subclass {Emerald class} }
383 F { report-set subclass {Frost class} }
384 R { report-set subclass {Rogue class} }
385 V { report-set subclass {Verdant class} }
386 default { report-set subclass "Subclass \"$subclass\"" }
389 report-set lock [lindex {
390 {Battle ready} {Unlocked} {Locked}
393 switch -exact $notown {
394 0 { report-set own "Yours" }
395 1 { report-set own "Other pirate's" }
396 2 { report-set own "Owner unknown" }
397 default { report-set own "?? $notown" }
400 if {[string length $xabbrev]} {
401 report-set xabbrev "Notes flags: $xabbrev"
403 report-set xabbrev "No flags in notes"
407 #---------- filtering ----------
411 proc filter-values/size {} { global vc_codes; return $vc_codes }
412 proc filter-icon/size {code} {
413 upvar #0 vc_code2abbrev($code) abb
416 proc filter-default/size {code} { return 1 }
417 proc filter-says-yes/size {codel} {
418 set sizecode [lindex $codel 1]
419 upvar #0 filter_size($sizecode) yes
423 proc filter-values/lockown {} {
426 lappend vals "$lv$ov"
431 proc filter-icon/lockown {lockown} { return [code-lockown2icon $lockown] }
432 proc filter-default/lockown {lockown} {
433 return [regexp {^[01]|^2[^1]} $lockown]
435 proc filter-says-yes/lockown {codel} {
436 set lockown [lindex $codel 3]
437 upvar #0 filter_lockown($lockown) yes
441 proc filter-validate/xabbre {re} {
445 regsub {^.*:\s*} $emsg {} emsg
446 regsub {^.*(.{30})$} $emsg {\1} emsg
451 proc filter-says-yes/xabbre {codel} {
453 set xabbrev [lindex $codel 4]
454 return [regexp -- $filter_xabbre $xabbrev]
457 proc filter-tickbox-flip {fil} {
458 upvar #0 filter_$fil vars
459 set values [filter-values/$fil]
460 foreach val $values {
461 set vars($val) [expr {!$vars($val)}]
466 proc make-tickbox-filter {fil label rows inrow} {
467 upvar #0 filter_$fil vars
468 set fw [make-filter tickbox $fil $label frame]
469 set values [filter-values/$fil]
470 set nvalues [llength $values]
472 set inrow [expr {($nvalues + $rows) / $rows}]
474 set noicons [catch { info args filter-icon/$fil }]
475 for {set ix 0} {$ix < $nvalues} {incr ix} {
476 set val [lindex $values $ix]
477 set vars($val) [filter-default/$fil $val]
478 checkbutton $fw.$ix -variable filter_${fil}($val) \
479 -font fixed -command redraw-needed
481 $fw.$ix configure -image [filter-icon/$fil $val] -height 16
483 $fw.$ix configure -text [filter-map/$fil $val]
485 grid configure $fw.$ix -sticky sw \
486 -row [expr {$ix / $inrow}] \
487 -column [expr {$ix % $inrow}]
489 button $fw.invert -text flip -command [list filter-tickbox-flip $fil] \
491 grid configure $fw.invert -sticky se \
492 -row [expr {$rows-1}] \
493 -column [expr {$inrow-1}]
496 proc entry-filter-changed {fw fil n1 n2 op} {
498 upvar #0 filter_$fil realvar
499 upvar #0 filterentered_$fil entryvar
500 global def_background
501 debug "entry-filter-changed $fw $fil $entryvar"
503 set error [filter-validate/$fil $entryvar]
504 if {[string length $error]} {
505 $fw.error configure -text $error -foreground white -background red
507 $fw.error configure -text { } -background $def_background
508 set realvar $entryvar
512 puts stderr "FILTER CHECK ERROR $emsg $errorInfo"
516 proc make-entry-filter {fil label def} {
517 global filterentered_$fil
518 upvar #0 filter_$fil realvar
520 set fw [make-filter entry $fil $label frame]
521 entry $fw.entry -textvariable filterentered_$fil
523 glset def_background [$fw.error cget -background]
524 trace add variable filterentered_$fil write \
525 [list entry-filter-changed $fw $fil]
526 pack $fw.entry $fw.error -side top -anchor w
529 proc make-filter {kind fil label ekind} {
531 label .filter.lab_$fil -text $label -justify left
534 set nfilters [llength $filters]
535 grid configure .filter.lab_$fil -row $nfilters -column 0 -sticky nw -pady 4
536 grid configure .filter.$fil -row $nfilters -column 1 -sticky w -pady 3
540 proc make-filters {} {
541 make-tickbox-filter size Size 2 0
542 make-tickbox-filter lockown "Lock/\nowner" 2 6
543 make-entry-filter xabbre "Flags\n regexp" {}
546 proc filterstyle-changed {n1 n2 op} {
548 debug "filterstyle-changed $filterstyle"
552 proc filters-say-yes {code} {
553 global filters filterstyle
554 debug "filters-say-yes $code"
555 set codel [split $code _]
556 set lockown [lindex $codel 3]
557 switch -exact $filterstyle {
559 1 { return [filter-default/lockown $lockown] }
560 2 { return [regexp {^.0} $lockown] }
562 default { error $filterstyle }
565 foreach fil $filters {
566 if {![filter-says-yes/$fil $codel]} { return 0 }
571 #---------- loading and parsing the clipboard (vessel locations) ----------
574 global pirate notes_used note_missings newnotes
578 lappend codel [errexpect-arrayget-boolean vi inPort]
580 set gameclass [errexpect-arrayget vi vesselClass]
581 upvar #0 vc_game2code($gameclass) class
582 if {![info exists class]} { errexpect-error "unexpected vesselClass"}
585 set subclass [errexpect-arrayget vi vesselSubclass]
586 switch -exact $subclass {
587 null { lappend codel {} }
588 celtic { lappend codel E }
589 icy { lappend codel F }
590 rogue { lappend codel R }
591 verdant { lappend codel V }
592 default { lappend codel ($subclass) }
595 switch -exact [errexpect-arrayget vi isLocked]/[ \
596 errexpect-arrayget vi isBattleReady] {
597 true/false { set lock 2 }
598 false/false { set lock 1 }
599 false/true { set lock 0 }
600 default { errexpect-error "unexpected isLocked/isBattleReady" }
603 set vid [errexpect-arrayget vi vesselId]
604 upvar #0 notes($vid) note
605 set realname [errexpect-arrayget vi vesselName]
606 set island [errexpect-arrayget vi islandName]
610 if {[info exists note]} {
611 manyset $note lno notename owner xabbrev
612 if {[string compare -nocase $realname $notename]} {
613 note-info $lno $vid $realname $island \
614 "notes say name is $notename"
616 if {[string length $owner]} {
617 if {![string compare $owner $pirate]} {
625 append abbrev $xabbrev
626 set notes_used($vid) 1
630 lappend note_missings [list $island $realname $vid]
633 lappend codel "$lock$notown" $xabbrev
634 lappend newnotes [list $vid $realname $owner $xabbrev]
635 set kk "$island [join $codel _]"
636 upvar #0 found($kk) k
637 lappend k [list $vid $realname $owner]
639 debug "CODED $kk $vid $realname"
643 proc parse-clipboard {} {
644 global clipboard found notes notes_used newnotes
646 catch { unset found }
647 catch { unset notes_used }
649 glset note_missings {}
653 set itemre { (\w+) = ([^=]*) }
654 set manyitemre "^\\\[ $itemre ( (?: ,\\ $itemre)* ) \\]\$"
658 foreach l [split $clipboard "\n"] {
660 errexpect-setline $lno $l
661 if {![string length $l]} continue
664 if {![regexp -expanded $manyitemre $l dummy \
665 thiskey thisval rhs]} {
666 errexpect-error "badly formatted"
668 set vi($thiskey) $thisval
669 if {![string length $rhs]} break
670 regsub {^, } $rhs {} rhs
676 if {[llength $newnotes]} {
677 foreach vid [lsort [array names notes]] {
678 if {![info exists notes_used($vid)]} {
679 manyset $notes($vid) lno notename
680 note-info $lno $vid $notename {} \
681 "vessel in notes no longer found"
687 proc load-clipboard-file {fn} {
689 glset clipboard [read $f]
694 #---------- loading and parsing the chart ----------
698 debug "FETCHING CHART"
699 set chart [eval exec $scraper [list | perl -we {
704 yppedia_chart_parse(\*STDIN, (new IO::File ">/dev/null"),
705 sub { sprintf "%d %d", @_; },
706 sub { printf "archlabel %d %d %s\n", @_; },
707 sub { printf "island %s %s\n", @_; },
708 sub { printf "league %s %s %s.\n", @_; },
709 sub { printf STDERR "warning: %s: incomprehensible: %s", @_; }
711 STDOUT->error and die $!;
720 return [expr {$c * $scale}]
723 proc chart-got/archlabel {args} { }
724 proc chart-got/island {x y args} {
725 # debug "ISLE $x $y $args"
726 global canvas isleloc
727 set isleloc($args) [list $x $y]
729 # $canvas create oval \
730 # [expr {[coord $x] - $sz}] [expr {[coord $y] - $sz}] \
731 # [expr {[coord $x] + $sz}] [expr {[coord $y] + $sz}] \
733 $canvas create text [coord $x] [coord $y] \
734 -text $args -anchor s
736 proc chart-got/league {x1 y1 x2 y2 kind} {
737 # debug "LEAGUE $x1 $y1 $x2 $y2 $kind"
739 set l [$canvas create line \
740 [coord $x1] [coord $y1] \
741 [coord $x2] [coord $y2]]
742 if {![string compare $kind .]} {
743 $canvas itemconfigure $l -dash .
747 proc redraw-needed {} {
749 debug "REDRAW NEEDED"
750 if {[info exists redraw_after]} return
751 set redraw_after [after 250 draw]
755 global chart found isleloc canvas redraw_after islandnames
757 catch { after cancel $redraw_after }
758 catch { unset redraw_after }
762 foreach l [split $chart "\n"] {
763 # debug "CHART-GOT $l"
764 set proc [lindex $l 0]
765 eval chart-got/$proc [lrange $l 1 end]
769 set lastislandname {}
770 foreach key [lsort [array names found]] {
771 set c [llength $found($key)]
772 # debug "SHOWING $key $c"
773 regexp {^(.*) (\S+)$} $key dummy islandname code
775 if {![filters-say-yes $code]} continue
777 if {[string compare $lastislandname $islandname]} {
778 manyset $isleloc($islandname) x y
781 set lastislandname $islandname
782 lappend islandnames $islandname
786 if {$c > 1} { set qty [format %d $c] } else { set qty {} }
787 code2canvas $code $canvas $x y $qty 2 \
788 [list show-report $islandname $code]
792 panner::updatecanvas-bbox .cp.ctrl.pan
798 #---------- parser error reporting ----------
800 proc parser-control-create {w base invokebuttontext etl_title} {
802 button $w.do -text $invokebuttontext -command invoke_$base -pady 3
804 frame $w.resframe -width 120 -height 32
805 button $w.resframe.res -text {} -anchor nw \
806 -padx 1 -pady 1 -borderwidth 0 -justify left
807 glset deffont_$base [$w.resframe.res cget -font]
808 place $w.resframe.res -relx 0.5 -y 0 -anchor n
811 pack $w.resframe -side top -expand y -fill both
816 wm title $eb "where-vessels - $etl_title"
817 wm protocol $eb WM_DELETE_WINDOW [list wm withdraw $eb]
819 label $eb.title -text $etl_title
820 pack $eb.title -side top
822 button $eb.close -text Close -command [list wm withdraw $eb]
823 pack $eb.close -side bottom
825 frame $eb.emsg -bd 2 -relief groove
826 label $eb.emsg.lab -anchor nw -text "Error:"
827 text $eb.emsg.text -height 1
828 pack $eb.emsg.text -side bottom -fill x
829 pack $eb.emsg.lab -side left
831 pack $eb.emsg -side top -pady 2 -fill x
833 frame $eb.text -bd 2 -relief groove
834 pack $eb.text -side bottom -pady 2 -fill both -expand y
836 label $eb.text.lab -anchor nw
838 text $eb.text.text -width 85 \
839 -xscrollcommand [list $eb.text.xscroll set] \
840 -yscrollcommand [list $eb.text.yscroll set]
841 $eb.text.text tag configure error \
842 -background red -foreground white
844 scrollbar $eb.text.xscroll -orient horizontal \
845 -command [list $eb.text.text xview]
846 scrollbar $eb.text.yscroll -orient vertical \
847 -command [list $eb.text.text yview]
849 grid configure $eb.text.lab -row 0 -column 0 -sticky w -columnspan 2
850 grid configure $eb.text.text -row 1 -column 0 -sticky news
851 grid configure $eb.text.yscroll -sticky ns -row 1 -column 1
852 grid configure $eb.text.xscroll -sticky ew -row 2 -column 0
853 grid rowconfigure $eb.text 0 -weight 0
854 grid rowconfigure $eb.text 1 -weight 1
855 grid rowconfigure $eb.text 2 -weight 0
856 grid columnconfigure $eb.text 0 -weight 1
857 grid columnconfigure $eb.text 1 -weight 0
860 proc parser-control-ok-core {w base background show} {
861 debug "parser-control-ok-core $w $base $background $show"
862 upvar #0 deffont_$base deffont
863 $w.resframe.res configure \
864 -background $background -disabledforeground black -font $deffont \
865 -state disabled -command {} \
868 proc parser-control-ok {w base show} {
869 parser-control-ok-core $w $base green $show
871 proc parser-control-none {w base show} {
872 parser-control-ok-core $w $base blue $show
874 proc parser-control-failed-core {w base foreground background smallfont
875 tiny summary fulldesc fulldata} {
876 debug "parser-control-failed-core $w $base $summary $fulldesc"
877 upvar #0 deffont_$base deffont
880 $eb.emsg.text delete 0.0 end
881 $eb.emsg.text insert end $summary
883 $eb.text.lab configure -text $fulldesc
884 $eb.text.text delete 0.0 end
885 $eb.text.text insert end $fulldata
887 regsub -all {.{18}} $tiny "&\n" ewrap
895 $w.resframe.res configure \
896 -background $background -foreground $foreground -font $font \
897 -state normal -command [list wm deiconify $eb] \
901 proc parser-control-failed-expected {w base emsg lno ei fulldesc newdata} {
904 set line [lindex [split $ei "\n"] 0]
905 debug "parser-control-failed-expected: $w $base: $lno: $emsg\n $line"
907 parser-control-failed-core $w $base \
909 "err: [string trim $emsg]: \"$line\"" \
910 "at line $lno: $emsg" \
913 $eb.text.text tag add error $lno.0 $lno.end
914 $eb.text.text see $lno.0
916 proc parser-control-failed-unexpected {w base emsg ei} {
918 parser-control-failed-core $w $base \
920 $emsg $emsg "Details and stack trace:" $ei
923 proc reparse {base varname old fulldesc okshow noneshow parse ok} {
924 upvar #0 $varname var
925 manyset [errexpect-catch {
927 if {[string length [string trim $var]]} {
928 parser-control-ok .cp.ctrl.$base $base $okshow
930 parser-control-none .cp.ctrl.$base $base $noneshow
932 }] failed emsg lno ei
934 parser-control-failed-expected .cp.ctrl.$base $base \
935 $emsg $lno $ei $fulldesc $var
943 #---------- island names selection etc. ----------
945 proc islandnames-update {} {
947 .islands.count configure -text [format "ships at %d island(s)" \
948 [llength $islandnames]]
951 proc islandnames-select {} {
952 .islands.clip configure -relief sunken -state disabled
953 selection own -command islandnames-deselect .islands.clip
955 proc islandnames-deselect {} {
956 .islands.clip configure -relief raised -state normal
959 proc islandnames-handler {offset maxchars} {
961 return [string range [join $islandnames ", "] \
962 $offset [expr {$offset+$maxchars-1}]]
965 #---------- main user interface ----------
967 proc widgets-setup {} {
968 global canvas debug pirate ocean filterstyle
970 wm geometry . 1024x600
971 wm title . "where-vessels - $pirate on the $ocean ocean"
975 frame .f -border 1 -relief groove
978 pack $canvas -expand 1 -fill both
979 pack .f -expand 1 -fill both -side left
981 #----- control panels and filter -----
984 frame .filter -relief groove -bd 2 -padx 1
985 frame .islands -pady 2
986 pack .cp .filter .islands -side top
989 trace add variable filterstyle write filterstyle-changed
992 label .filter.title.title -text Show
993 pack .filter.title.title -side left
994 for {set fing 0} {$fing < 4} {incr fing} {
995 radiobutton .filter.title.f$fing \
996 -variable filterstyle -value $fing \
997 -text [lindex {All Useable Mine These:} $fing]
998 pack .filter.title.f$fing -side left
1001 grid configure .filter.title -row 0 -column 0 -columnspan 2
1003 #----- control panel -----
1006 pack .cp.ctrl -side left -anchor n
1008 debug "BBOX [$canvas bbox all]"
1010 panner::canvas-scroll-bbox .f.c
1011 panner::create .cp.ctrl.pan .f.c 120 120 $debug
1013 pack .cp.ctrl.pan -side top -pady 0 -padx 5
1015 pack .cp.ctrl.zoom -side top
1017 button .cp.ctrl.zoom.out -text - -font {Courier 16} -command {zoom /2} -pady 0
1018 button .cp.ctrl.zoom.in -text + -font {Courier 16} -command {zoom *2} -pady 0
1019 pack .cp.ctrl.zoom.out .cp.ctrl.zoom.in -side left
1021 parser-control-create .cp.ctrl.acquire \
1023 "Clipboard parsing error" \
1025 pack .cp.ctrl.acquire -side top -pady 2
1027 parser-control-create .cp.ctrl.notes \
1028 notes "Reload notes" \
1029 "Vessel notes loading report" \
1031 pack .cp.ctrl.notes -side top -pady 2
1033 #----- island name count and copy -----
1035 label .islands.count
1036 button .islands.clip -text "copy island names" -pady 2 -padx 2 \
1037 -command islandnames-select
1038 selection handle .islands.clip islandnames-handler
1039 pack .islands.count .islands.clip -side left
1041 #----- decoding etc. report -----
1044 pack .cp.report -side left -anchor n
1046 label .cp.report.island -text { }
1048 canvas .cp.report.abbrev -width 1 -height 15
1050 frame .cp.report.code
1051 label .cp.report.code.lab -text Code:
1052 glset report_code { }
1053 entry .cp.report.code.code -state readonly \
1054 -textvariable report_code -width 15
1055 pack .cp.report.code.lab .cp.report.code.code -side left
1056 frame .cp.report.details -bd 2 -relief groove -padx 2 -pady 2
1058 listbox .cp.report.list -height 5
1060 pack .cp.report.island .cp.report.abbrev .cp.report.details \
1061 .cp.report.list -side top
1062 #pack .cp.report.code -side top
1063 pack configure .cp.report.details -fill x
1065 foreach sw {inport class subclass lock own xabbrev} {
1066 label .cp.report.details.$sw -text { }
1067 pack .cp.report.details.$sw -side top -anchor w
1071 proc report-set {sw val} { .cp.report.details.$sw configure -text $val }
1073 proc show-report {islandname code} {
1074 .cp.report.island configure -text $islandname
1076 .cp.report.abbrev delete all
1078 code2canvas $code .cp.report.abbrev 5 y {} 0 {}
1079 manyset [.cp.report.abbrev bbox all] minx dummy maxx dummy
1080 .cp.report.abbrev configure -width [expr {$maxx-$minx+4}]
1082 glset report_code $code
1083 show-report-decode $code
1085 set kk "$islandname $code"
1086 upvar #0 found($kk) k
1088 .cp.report.list delete 0 end
1091 manyset $entry vid name owner
1092 lappend owned($owner) $name
1095 foreach owner [lsort [array names owned]] {
1096 if {[string length $owner]} {
1097 set owndesc "$owner's"
1099 set owndesc "Owner unknown"
1101 .cp.report.list insert end "$owndesc:"
1102 foreach name $owned($owner) {
1103 .cp.report.list insert end " $name"
1108 proc zoom {extail} {
1110 set nscale [expr "\$scale $extail"]
1111 debug "ZOOM $scale $nscale"
1112 if {$nscale < 1 || $nscale > 200} return
1117 proc invoke_acquire {} {
1118 global clipboard errorInfo
1122 set clipboard [clipboard get]
1124 parser-control-failed-unexpected .cp.ctrl.acquire acquire \
1125 $emsg "fetching clipboard:\n\n$errorInfo"
1130 clipboard $old "Clipboard contents:" { acquired ok } { no vessels } {
1138 proc invoke_notes {} {
1139 global notes_data errorInfo notes_loc
1145 parser-control-failed-unexpected .cp.ctrl.notes notes \
1146 $emsg "loading $notes_loc:\n\n$errorInfo"
1151 notes_data $old "Vessel notes:" "loaded ok" { no notes } {
1160 #---------- main program ----------
1165 httpclientsetup where-vessels
1171 if {[catch { parse-clipboard } emsg]} {
1172 puts stderr "$emsg\n$errorInfo"
1175 after idle invoke_notes