3 # Revision 1.9 1995-03-17 18:26:16 adam
4 # Non-blocking i/o used now. Database names popup as cascade items.
6 # Revision 1.8 1995/03/17 15:45:00 adam
7 # Improved target/database setup.
9 # Revision 1.7 1995/03/16 17:54:03 adam
10 # Minor changes really.
12 # Revision 1.6 1995/03/15 19:10:20 adam
13 # Database setup in protocol-setup (rather target setup).
15 # Revision 1.5 1995/03/15 13:59:23 adam
18 # Revision 1.4 1995/03/14 17:32:29 adam
19 # Presentation of full Marc record in popup window.
21 # Revision 1.3 1995/03/12 19:31:52 adam
22 # Pattern matching implemented when retrieving MARC records. More
23 # diagnostic functions.
25 # Revision 1.2 1995/03/10 18:00:15 adam
26 # Actual presentation in line-by-line format. RPN query support.
28 # Revision 1.1 1995/03/09 16:15:07 adam
29 # First presentRequest attempts. Hot-target list.
36 set profile(Default) {{} {} {210} {} 16384 8192 tcpip {}}
43 if {[file readable "~/.tk-c"]} {
47 proc top-down-window {w} {
48 frame $w.top -relief raised -border 1
49 frame $w.bot -relief raised -border 1
51 pack $w.top $w.bot -side top -fill both -expand yes
54 proc top-down-ok-cancel {w ok-action} {
55 frame $w.bot.left -relief sunken -border 1
56 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
57 button $w.bot.left.ok -width 6 -text {Ok} \
59 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
60 button $w.bot.cancel -width 6 -text {Cancel} \
62 pack $w.bot.cancel -side left -expand yes
70 proc show-target {target} {
71 .bot.target configure -text "$target"
74 proc show-busy {v1 v2} {
77 .bot.status configure -fg $v1
78 after 200 [list show-busy $v2 $v1]
82 proc show-status {status b} {
85 .bot.status configure -text "$status"
86 .bot.status configure -fg black
92 # . config -cursor {watch black white}
94 # . config -cursor {top_left_arrow black white}
100 proc show-message {msg} {
101 .bot.message configure -text "$msg"
104 proc insertWithTags {w text args} {
105 set start [$w index insert]
106 $w insert insert $text
107 foreach tag [$w tag names $start] {
108 $w tag remove $tag $start insert
111 $w tag add $i $start insert
115 proc show-full-marc {no} {
120 if {[winfo exists $w]} {
121 $w.top.record delete 0.0 end
127 wm minsize $w 200 200
129 frame $w.top -relief raised -border 1
130 frame $w.bot -relief raised -border 1
132 # pack $w.top $w.bot -side top -fill both -expand yes
133 pack $w.top -side top -fill both -expand yes
134 pack $w.bot -fill both
136 text $w.top.record -width 60 -height 10 -wrap word \
137 -yscrollcommand [list $w.top.s set]
138 scrollbar $w.top.s -command [list $w.top.record yview]
144 set r [z39.$setNo recordMarc $no line * * *]
146 $w.top.record tag configure marc-tag -foreground blue
147 $w.top.record tag configure marc-data -foreground black
148 $w.top.record tag configure marc-id -foreground red
151 set tag [lindex $line 0]
152 set indicator [lindex $line 1]
153 set fields [lindex $line 2]
155 if {$indicator != ""} {
156 insertWithTags $w.top.record "$tag $indicator" marc-tag
158 insertWithTags $w.top.record "$tag " marc-tag
160 foreach field $fields {
161 set id [lindex $field 0]
162 set data [lindex $field 1]
164 insertWithTags $w.top.record " $id " marc-id
166 set start [$w.top.record index insert]
167 insertWithTags $w.top.record $data {}
169 $w.top.record insert end "\n"
172 bind $w <Return> {destroy .full-marc}
174 pack $w.top.s -side right -fill y
175 pack $w.top.record -expand yes -fill both
177 frame $w.bot.left -relief sunken -border 1
178 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
179 button $w.bot.left.close -width 6 -text {Close} \
180 -command {destroy .full-marc}
181 pack $w.bot.left.close -expand yes -padx 3 -pady 3
182 button $w.bot.edit -width 6 -text {Edit} \
183 -command {destroy .full-marc}
184 pack $w.bot.edit -side left -expand yes
188 proc update-target-hotlist {target} {
191 set len [llength $hotTargets]
193 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
195 set indx [lsearch $hotTargets $target]
197 set hotTargets [lreplace $hotTargets $indx $indx]
199 set hotTargets [linsert $hotTargets 0 $target]
203 proc set-target-hotlist {} {
207 foreach target $hotTargets {
208 .top.target.m add command -label "$i $target" -command \
209 "menu-open-target $target {}"
217 proc menu-open-target {target base} {
218 open-target $target $base
219 update-target-hotlist $target
222 proc define-target-action {} {
225 set target [.target-define.top.target.entry get]
229 update-target-hotlist $target
230 foreach n [array names profile] {
236 set profile($target) $profile(Default)
237 protocol-setup $target
238 destroy .target-define
241 proc open-target {target base} {
244 .top.target.m disable 0
245 .top.target.m enable 1
247 z39 comstack [lindex $profile($target) 6]
248 # z39 idAuthentication [lindex $profile($target) 3]
249 z39 maximumRecordSize [lindex $profile($target) 4]
250 z39 preferredMessageSize [lindex $profile($target) 5]
251 puts -nonewline "maximumRecordSize="
252 puts [z39 maximumRecordSize]
253 puts -nonewline "preferredMessageSize="
254 puts [z39 preferredMessageSize]
256 z39 databaseNames [lindex [lindex $profile($target) 7] 0]
258 z39 databaseNames $base
261 z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
265 proc load-set-action {} {
271 set fname [.load-set.top.filename.entry get]
274 .data.list delete 0 end
276 show-status {Loading} 1
277 z39.$setNo loadFile $fname
279 set no [z39.$setNo numberOfRecordsReturned]
280 add-title-lines $no 1
282 show-status {Ready} 0
294 frame $w.top.filename
296 pack $w.top.filename -side top -anchor e -pady 2
298 entry-fields $w.top {filename} \
300 {load-set-action} {destroy .load-set}
302 top-down-ok-cancel $w {load-set-action}
305 proc init-request {} {
308 z39 callback {init-response}
310 show-status {Initializing} 1
314 proc init-response {} {
315 show-status {Ready} 0
316 pack .mid.searchlabel .mid.searchentry -side left
317 bind .mid.searchentry <Return> search-request
318 focus .mid.searchentry
321 proc search-request {} {
327 z39 callback {search-response}
328 z39.$setNo search [.mid.searchentry get]
329 show-status {Search} 1
332 proc search-response {} {
337 .data.list delete 0 end
338 show-status {Ready} 0
339 show-message "[z39.$setNo resultCount] hits"
340 set setMax [z39.$setNo resultCount]
348 z39 callback {present-response}
350 z39.$setNo present 1 $setMax
351 show-status {Retrieve} 1
354 proc add-title-lines {no offset} {
357 for {set i 0} {$i < $no} {incr i} {
358 set o [expr $i + $offset]
359 set title [lindex [z39.$setNo recordMarc $o field 245 * a] 0]
360 set year [lindex [z39.$setNo recordMarc $o field 260 * c] 0]
361 set nostr [format "%3d" $o]
362 .data.list insert end "$nostr $title - $year"
366 proc present-response {} {
371 puts "In present-response"
372 set no [z39.$setNo numberOfRecordsReturned]
373 puts "Returned $no records, setOffset $setOffset"
374 add-title-lines $no $setOffset
375 set setOffset [expr $setOffset + $no]
376 if { $setOffset <= $setMax} {
377 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
379 show-status {Finished} 0
383 proc left-cursor {w} {
384 set i [$w index insert]
391 proc right-cursor {w} {
392 set i [$w index insert]
397 proc bind-fields {list returnAction escapeAction} {
398 set max [expr [llength $list]-1]
399 for {set i 0} {$i < $max} {incr i} {
400 bind [lindex $list $i] <Return> $returnAction
401 bind [lindex $list $i] <Escape> $escapeAction
402 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
403 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
404 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
406 bind [lindex $list $i] <Return> $returnAction
407 bind [lindex $list $i] <Escape> $escapeAction
408 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
409 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
410 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
411 focus [lindex $list 0]
414 proc entry-fields {parent list tlist returnAction escapeAction} {
417 foreach field $list {
418 set label ${parent}.${field}.label
419 set entry ${parent}.${field}.entry
420 label $label -text [lindex $tlist $i] -anchor e
421 entry $entry -width 28 -relief sunken
422 pack $label -side left
423 pack $entry -side right
427 bind-fields $alist $returnAction $escapeAction
430 proc define-target-dialog {} {
442 -side top -anchor e -pady 2
444 entry-fields $w.top {target} \
446 {define-target-action} {destroy .target-define}
448 top-down-ok-cancel $w {define-target-action}
451 proc close-target {} {
452 pack forget .mid.searchlabel .mid.searchentry
455 show-status {Not connected} 0
457 .top.target.m disable 1
458 .top.target.m enable 0
461 proc protocol-setup-action {target} {
464 global settingsChanged
466 set w .protocol-setup.top
469 set settingsChanged 1
470 set len [$w.databases.list size]
471 for {set i 0} {$i < $len} {incr i} {
472 lappend b [$w.databases.list get $i]
474 set profile($target) [list [$w.description.entry get] \
475 [$w.host.entry get] \
476 [$w.port.entry get] \
477 [$w.idAuthentication.entry get] \
478 [$w.maximumRecordSize.entry get] \
479 [$w.preferredMessageSize.entry get] \
484 puts $profile($target)
485 destroy .protocol-setup
489 proc place-force {window parent} {
490 set g [wm geometry $parent]
492 set p1 [string first + $g]
493 set p2 [string last + $g]
495 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
496 set y [expr 60+[string range $g [expr $p2 +1] end]]
497 wm geometry $window +${x}+${y}
501 proc add-database-action {} {
502 .protocol-setup.top.databases.list insert end \
503 [.database-select.top.database.entry get]
504 destroy .database-select
507 proc add-database {} {
508 set w .database-select
512 place-force $w .protocol-setup
516 frame $w.top.database
518 pack $w.top.database -side top -anchor e -pady 2
520 entry-fields $w.top {database} \
521 {{Database to add:}} \
522 {add-database-action} {destroy .database-select}
524 top-down-ok-cancel $w {add-database-action}
527 proc delete-database {} {
528 foreach i [lsort -decreasing \
529 [.protocol-setup.top.databases.list curselection]] {
530 .protocol-setup.top.databases.list delete $i
534 proc protocol-setup {target} {
535 set w .protocol-setup
542 wm title $w "Setup $target"
551 puts $profile($target)
555 frame $w.top.description
556 frame $w.top.idAuthentication
557 frame $w.top.maximumRecordSize
558 frame $w.top.preferredMessageSize
559 frame $w.top.cs-type -relief ridge -border 2
560 frame $w.top.query -relief ridge -border 2
561 frame $w.top.databases -relief ridge -border 2
563 # Maximum/preferred/idAuth ...
564 pack $w.top.description $w.top.host $w.top.port \
565 $w.top.idAuthentication $w.top.maximumRecordSize \
566 $w.top.preferredMessageSize -side top -anchor e -pady 2
569 entry-fields $w.top {description host port idAuthentication \
570 maximumRecordSize preferredMessageSize} \
571 {{Description:} {Host:} {Port:} {Id Authentification:} \
572 {Maximum Record Size:} {Preferred Message Size:}} \
573 [list protocol-setup-action $target] {destroy .protocol-setup}
575 $w.top.description.entry insert 0 [lindex $profile($target) 0]
576 $w.top.host.entry insert 0 [lindex $profile($target) 1]
577 $w.top.port.entry insert 0 [lindex $profile($target) 2]
578 $w.top.idAuthentication.entry insert 0 [lindex $profile($target) 3]
579 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($target) 4]
580 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($target) 5]
583 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
585 label $w.top.databases.label -text "Databases"
586 button $w.top.databases.add -text "Add" -command {add-database}
587 button $w.top.databases.delete -text "Delete" -command {delete-database}
588 listbox $w.top.databases.list -geometry 20x6 \
589 -yscrollcommand "$w.top.databases.scroll set"
590 scrollbar $w.top.databases.scroll -orient vertical -border 1
591 pack $w.top.databases.label -side top -fill x \
593 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
595 pack $w.top.databases.list -side left -fill both -expand yes \
597 pack $w.top.databases.scroll -side right -fill y \
599 $w.top.databases.scroll config -command "$w.top.databases.list yview"
601 foreach b [lindex $profile($target) 7] {
602 $w.top.databases.list insert end $b
606 set csRadioType [lindex $profile($target) 6]
608 pack $w.top.cs-type -pady 6 -padx 6 -side top
610 label $w.top.cs-type.label -text "Transport"
611 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
612 -command {puts tcp/ip} -variable csRadioType -value tcpip
613 radiobutton $w.top.cs-type.mosi -text "MOSI" \
614 -command {puts mosi} -variable csRadioType -value mosi
616 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
617 -padx 4 -side top -fill x
620 pack $w.top.query -pady 6 -padx 6 -side top
622 label $w.top.query.label -text "Query support" -anchor e
623 checkbutton $w.top.query.c1 -text "CCL query"
624 checkbutton $w.top.query.c2 -text "RPN query"
625 checkbutton $w.top.query.c3 -text "Result sets"
627 pack $w.top.query.label -side top
628 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
629 -padx 4 -side top -fill x
631 top-down-ok-cancel $w [list protocol-setup-action $target]
634 proc database-select-action {} {
635 set w .database-select.top
637 foreach indx [$w.databases.list curselection] {
638 lappend b [$w.databases.list get $indx]
643 destroy .database-select
646 proc database-select {} {
647 set w .database-select
661 frame $w.top.databases -relief ridge -border 2
663 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
665 label $w.top.databases.label -text "List"
666 listbox $w.top.databases.list -geometry 20x6 \
667 -yscrollcommand "$w.top.databases.scroll set"
668 scrollbar $w.top.databases.scroll -orient vertical -border 1
669 pack $w.top.databases.label -side top -fill x \
671 pack $w.top.databases.list -side left -fill both -expand yes \
673 pack $w.top.databases.scroll -side right -fill y \
675 $w.top.databases.scroll config -command "$w.top.databases.list yview"
677 foreach b [lindex $profile($hostid) 7] {
678 $w.top.databases.list insert end $b
680 top-down-ok-cancel $w {database-select-action}
683 proc cascade-target-list {} {
686 foreach sub [winfo children .top.target.m.clist] {
690 .top.target.m.clist delete 0 last
691 foreach n [array names profile] {
692 if {$n != "Default"} {
693 set nl [string tolower $n]
694 if {[llength [lindex $profile($n) 7]] > 1} {
695 .top.target.m.clist add cascade -label $n \
696 -menu .top.target.m.clist.$nl
697 menu .top.target.m.clist.$nl
698 foreach b [lindex $profile($n) 7] {
699 .top.target.m.clist.$nl add command -label $b \
700 -command "menu-open-target $n $b"
703 .top.target.m.clist add command -label $n \
704 -command "menu-open-target $n {}"
708 .top.target.m.slist delete 0 last
709 foreach n [array names profile] {
710 if {$n != "Default"} {
711 .top.target.m.slist add command -label $n \
712 -command "protocol-setup $n"
717 proc save-settings {} {
720 global settingsChanged
722 set f [open "~/.tk-c" w]
723 puts $f "# Setup file"
724 puts $f "set hotTargets \{ $hotTargets \}"
726 foreach n [array names profile] {
727 puts -nonewline $f "set profile($n) \{"
728 puts -nonewline $f $profile($n)
732 set settingsChanged 0
744 message $w.top.message -text $ask
746 pack $w.top.message -side left -pady 6 -padx 20 -expand yes -fill x
749 top-down-ok-cancel $w {alert-action}
753 proc alert-action {} {
759 proc exit-action {} {
760 global settingsChanged
762 if {$settingsChanged} {
763 set a [alert "you havent saved your settings. Do you wish to save?"]
771 frame .top -border 1 -relief raised
772 frame .mid -border 1 -relief raised
773 frame .data -border 1 -relief raised
774 frame .bot -border 1 -relief raised
775 pack .top .mid -side top -fill x
776 pack .data -side top -fill both -expand yes
779 menubutton .top.file -text "File" -menu .top.file.m
781 .top.file.m add command -label "Save settings" -command {save-settings}
782 .top.file.m add command -label "Load Set" -command {load-set}
783 .top.file.m add separator
784 .top.file.m add command -label "Exit" -command {exit-action}
786 menubutton .top.target -text "Target" -menu .top.target.m
788 .top.target.m add cascade -label "Connect" -menu .top.target.m.clist
789 .top.target.m add command -label "Disconnect" -command {close-target}
790 #.top.target.m add command -label "Initialize" -command {init-request}
791 .top.target.m add cascade -label "Setup" -menu .top.target.m.slist
792 .top.target.m add command -label "Setup new" -command {define-target-dialog}
793 .top.target.m add separator
796 .top.target.m disable 1
798 menu .top.target.m.clist
799 menu .top.target.m.slist
802 menubutton .top.database -text "Database" -menu .top.database.m
804 .top.database.m add command -label "Select ..." -command {database-select}
805 .top.database.m add command -label "Add ..." -command {puts "Add"}
807 menubutton .top.help -text "Help" -menu .top.help.m
810 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
811 .top.help.m add command -label "About" -command {puts "About"}
813 pack .top.file .top.target .top.database -side left
814 pack .top.help -side right
816 label .mid.searchlabel -text {Search:}
817 entry .mid.searchentry -width 40 -relief sunken
819 bind .mid.searchentry <Left> {left-cursor .mid.searchentry}
820 bind .mid.searchentry <Right> {right-cursor .mid.searchentry}
822 listbox .data.list -yscrollcommand {.data.scroll set}
823 scrollbar .data.scroll -orient vertical -border 1
824 pack .data.list -side left -fill both -expand yes
825 pack .data.scroll -side right -fill y
826 .data.scroll config -command {.data.list yview}
828 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
829 label .bot.status -text "Not connected" -width 12 -relief \
830 sunken -anchor w -border 1
831 label .bot.message -text "" -width 20 -relief \
832 sunken -anchor w -border 1
833 pack .bot.target .bot.status .bot.message -anchor nw -side left -padx 2 -pady 2
835 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
836 show-full-marc $indx}