3 # Revision 1.7 1995-03-16 17:54:03 adam
4 # Minor changes really.
6 # Revision 1.6 1995/03/15 19:10:20 adam
7 # Database setup in protocol-setup (rather target setup).
9 # Revision 1.5 1995/03/15 13:59:23 adam
12 # Revision 1.4 1995/03/14 17:32:29 adam
13 # Presentation of full Marc record in popup window.
15 # Revision 1.3 1995/03/12 19:31:52 adam
16 # Pattern matching implemented when retrieving MARC records. More
17 # diagnostic functions.
19 # Revision 1.2 1995/03/10 18:00:15 adam
20 # Actual presentation in line-by-line format. RPN query support.
22 # Revision 1.1 1995/03/09 16:15:07 adam
23 # First presentRequest attempts. Hot-target list.
30 set profile(Default) {{} {} 16384 8192 tcpip {books names demo} }
35 if {[file readable "~/.tk-c"]} {
39 proc top-down-window {w} {
40 frame $w.top -relief raised -border 1
41 frame $w.bot -relief raised -border 1
43 pack $w.top $w.bot -side top -fill both -expand yes
46 proc top-down-ok-cancel {w ok-action} {
47 frame $w.bot.left -relief sunken -border 1
48 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
49 button $w.bot.left.ok -width 6 -text {Ok} \
51 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
52 button $w.bot.cancel -width 6 -text {Cancel} \
54 pack $w.bot.cancel -side left -expand yes
62 proc show-target {target} {
63 .bot.target configure -text "$target"
66 proc show-busy {v1 v2} {
69 .bot.status configure -fg $v1
70 after 200 [list show-busy $v2 $v1]
74 proc show-status {status b} {
77 .bot.status configure -text "$status"
78 .bot.status configure -fg black
84 # . config -cursor {watch black white}
86 # . config -cursor {top_left_arrow black white}
92 proc show-message {msg} {
93 .bot.message configure -text "$msg"
96 proc insertWithTags {w text args} {
97 set start [$w index insert]
98 $w insert insert $text
99 foreach tag [$w tag names $start] {
100 $w tag remove $tag $start insert
103 $w tag add $i $start insert
107 proc show-full-marc {no} {
112 if {[winfo exists $w]} {
113 $w.top.record delete 0.0 end
119 wm minsize $w 200 200
121 frame $w.top -relief raised -border 1
122 frame $w.bot -relief raised -border 1
124 # pack $w.top $w.bot -side top -fill both -expand yes
125 pack $w.top -side top -fill both -expand yes
126 pack $w.bot -fill both
128 text $w.top.record -width 60 -height 10 \
129 -yscrollcommand [list $w.top.s set]
130 scrollbar $w.top.s -command [list $w.top.record yview]
136 set r [z39.$setNo recordMarc $no line * * *]
138 $w.top.record tag configure marc-tag -foreground blue
139 $w.top.record tag configure marc-data -foreground black
140 $w.top.record tag configure marc-id -foreground red
143 set tag [lindex $line 0]
144 set indicator [lindex $line 1]
145 set fields [lindex $line 2]
147 if {$indicator != ""} {
148 insertWithTags $w.top.record "$tag $indicator" marc-tag
150 insertWithTags $w.top.record "$tag " marc-tag
152 foreach field $fields {
153 set id [lindex $field 0]
154 set data [lindex $field 1]
156 insertWithTags $w.top.record " $id " marc-id
158 set start [$w.top.record index insert]
159 insertWithTags $w.top.record $data {}
161 $w.top.record insert end "\n"
164 bind $w <Return> {destroy .full-marc}
166 pack $w.top.s -side right -fill y
167 pack $w.top.record -expand yes -fill both
169 frame $w.bot.left -relief sunken -border 1
170 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
171 button $w.bot.left.close -width 6 -text {Close} \
172 -command {destroy .full-marc}
173 pack $w.bot.left.close -expand yes -padx 3 -pady 3
174 button $w.bot.edit -width 6 -text {Edit} \
175 -command {destroy .full-marc}
176 pack $w.bot.edit -side left -expand yes
180 proc update-target-hotlist {target} {
183 set len [llength $hotTargets]
185 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
187 set indx [lsearch $hotTargets $target]
189 set hotTargets [lreplace $hotTargets $indx $indx]
191 set hotTargets [linsert $hotTargets 0 $target]
195 proc set-target-hotlist {} {
199 foreach target $hotTargets {
200 .top.target.m add command -label $target -command \
201 "menu-open-target $target"
209 proc menu-open-target {target} {
211 update-target-hotlist $target
214 proc open-target-action {} {
215 set host [.target-connect.top.host.entry get]
216 set port [.target-connect.top.port.entry get]
224 open-target "${host}:${port}"
225 update-target-hotlist ${host}:${port}
226 destroy .target-connect
229 proc open-target {target} {
232 z39 comstack ${csRadioType}
239 proc load-set-action {} {
245 set fname [.load-set.top.filename.entry get]
248 .data.list delete 0 end
250 show-status {Loading} 1
251 z39.$setNo loadFile $fname
253 set no [z39.$setNo numberOfRecordsReturned]
254 add-title-lines $no 1
256 show-status {Ready} 0
268 frame $w.top.filename
270 pack $w.top.filename -side top -anchor e -pady 2
272 entry-fields $w.top {filename} \
274 {load-set-action} {destroy .load-set}
276 top-down-ok-cancel $w {load-set-action}
279 proc init-request {} {
282 z39 callback {init-response}
284 show-status {Initializing} 1
288 proc init-response {} {
289 show-status {Ready} 0
290 pack .mid.searchlabel .mid.searchentry -side left
291 bind .mid.searchentry <Return> search-request
292 focus .mid.searchentry
295 proc search-request {} {
301 z39 callback {search-response}
302 z39.$setNo search [.mid.searchentry get]
303 show-status {Search} 1
306 proc search-response {} {
311 .data.list delete 0 end
312 show-status {Ready} 0
313 show-message "[z39.$setNo resultCount] hits"
314 set setMax [z39.$setNo resultCount]
319 z39 callback {present-response}
321 z39.$setNo present 1 $setMax
322 show-status {Retrieve} 1
325 proc add-title-lines {no offset} {
328 for {set i 0} {$i < $no} {incr i} {
329 set o [expr $i + $offset]
330 set title [lindex [z39.$setNo recordMarc $o field 245 * a] 0]
331 set year [lindex [z39.$setNo recordMarc $o field 260 * c] 0]
332 .data.list insert end "$title - $year"
336 proc present-response {} {
341 puts "In present-response"
342 set no [z39.$setNo numberOfRecordsReturned]
343 puts "Returned $no records, setOffset $setOffset"
344 add-title-lines $no $setOffset
345 set setOffset [expr $setOffset + $no]
346 if { $setOffset <= $setMax} {
347 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
349 show-status {Finished} 0
353 proc bind-fields {list returnAction escapeAction} {
354 set max [expr [llength $list]-1]
355 for {set i 0} {$i < $max} {incr i} {
356 bind [lindex $list $i] <Return> $returnAction
357 bind [lindex $list $i] <Escape> $escapeAction
358 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
360 bind [lindex $list $i] <Return> $returnAction
361 bind [lindex $list $i] <Escape> $escapeAction
362 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
363 focus [lindex $list 0]
366 proc entry-fields {parent list tlist returnAction escapeAction} {
369 foreach field $list {
370 set label ${parent}.${field}.label
371 set entry ${parent}.${field}.entry
372 label $label -text [lindex $tlist $i] -anchor e
373 entry $entry -width 24 -relief sunken
374 pack $label -side left
375 pack $entry -side right
379 bind-fields $alist $returnAction $escapeAction
382 proc open-target-dialog {} {
383 set w .target-connect
394 pack $w.top.host $w.top.port \
395 -side top -anchor e -pady 2
397 entry-fields $w.top {host port } \
398 {{Hostname:} {Port number:}} \
399 {open-target-action} {destroy .target-connect}
401 top-down-ok-cancel $w {open-target-action}
404 proc close-target {} {
405 pack forget .mid.searchlabel .mid.searchentry
408 show-status {Not connected} 0
412 proc protocol-setup-action {} {
417 set w .protocol-setup.top
419 set len [$w.databases.list size]
420 for {set i 0} {$i < $len} {incr i} {
421 lappend b [$w.databases.list get $i]
423 set profile($hostname) [list [$w.description.entry get] \
424 [$w.idAuthentication.entry get] \
425 [$w.maximumRecordSize.entry get] \
426 [$w.preferredMessageSize.entry get] \
430 puts $profile($hostname)
431 destroy .protocol-setup
435 proc place-force {window parent} {
436 set g [wm geometry $parent]
438 set p1 [string first + $g]
439 set p2 [string last + $g]
441 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
442 set y [expr 60+[string range $g [expr $p2 +1] end]]
443 wm geometry $window +${x}+${y}
447 proc add-database-action {} {
448 .protocol-setup.top.databases.list insert end \
449 [.database-select.top.database.entry get]
450 destroy .database-select
453 proc add-database {} {
454 set w .database-select
458 place-force $w .protocol-setup
462 frame $w.top.database
464 pack $w.top.database -side top -anchor e -pady 2
466 entry-fields $w.top {database} \
467 {{Database to add:}} \
468 {add-database-action} {destroy .database-select}
470 top-down-ok-cancel $w {add-database-action}
473 proc delete-database {} {
474 foreach i [lsort -decreasing \
475 [.protocol-setup.top.databases.list curselection]] {
476 .protocol-setup.top.databases.list delete $i
480 proc protocol-setup {} {
481 set w .protocol-setup
493 if {$hostname == ""} {
497 puts $profile($hostname)
499 frame $w.top.description
500 frame $w.top.idAuthentication
501 frame $w.top.maximumRecordSize
502 frame $w.top.preferredMessageSize
503 frame $w.top.cs-type -relief ridge -border 2
504 frame $w.top.query -relief ridge -border 2
505 frame $w.top.databases -relief ridge -border 2
507 # Maximum/preferred/idAuth ...
508 pack $w.top.description \
509 $w.top.idAuthentication $w.top.maximumRecordSize \
510 $w.top.preferredMessageSize -side top -anchor e -pady 2
513 entry-fields $w.top {description idAuthentication maximumRecordSize \
514 preferredMessageSize} \
515 {{Description:} {Id Authentification:} {Maximum Record Size:}
516 {Preferred Message Size:}} \
517 {protocol-setup-action} {destroy .protocol-setup}
519 $w.top.description.entry insert 0 [lindex $profile($hostname) 0]
520 $w.top.idAuthentication.entry insert 0 [lindex $profile($hostname) 1]
521 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($hostname) 2]
522 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($hostname) 3]
525 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
527 label $w.top.databases.label -text "Databases"
528 button $w.top.databases.add -text "Add" -command {add-database}
529 button $w.top.databases.delete -text "Delete" -command {delete-database}
530 listbox $w.top.databases.list -geometry 20x6 \
531 -yscrollcommand "$w.top.databases.scroll set"
532 scrollbar $w.top.databases.scroll -orient vertical -border 1
533 pack $w.top.databases.label -side top -fill x \
535 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
537 pack $w.top.databases.list -side left -fill both -expand yes \
539 pack $w.top.databases.scroll -side right -fill y \
541 $w.top.databases.scroll config -command "$w.top.databases.list yview"
543 foreach b [lindex $profile($hostname) 5] {
544 $w.top.databases.list insert end $b
548 set csRadioType [lindex $profile($hostname) 4]
550 pack $w.top.cs-type -pady 6 -padx 6 -side top
552 label $w.top.cs-type.label -text "Transport"
553 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
554 -command {puts tcp/ip} -variable csRadioType -value tcpip
555 radiobutton $w.top.cs-type.mosi -text "MOSI" \
556 -command {puts mosi} -variable csRadioType -value mosi
558 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
559 -padx 4 -side top -fill x
562 pack $w.top.query -pady 6 -padx 6 -side top
564 label $w.top.query.label -text "Query support" -anchor e
565 checkbutton $w.top.query.c1 -text "CCL query"
566 checkbutton $w.top.query.c2 -text "RPN query"
567 checkbutton $w.top.query.c3 -text "Result sets"
569 pack $w.top.query.label -side top
570 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
571 -padx 4 -side top -fill x
573 top-down-ok-cancel $w {protocol-setup-action}
576 proc database-select-action {} {
577 set w .database-select.top
579 foreach indx [$w.databases.list curselection] {
580 lappend b [$w.databases.list get $indx]
585 destroy .database-select
588 proc database-select {} {
589 set w .database-select
599 if {$hostname == ""} {
603 #frame $w.top.database
604 frame $w.top.databases -relief ridge -border 2
606 #pack $w.top.database -side top -anchor e -pady 2
608 #entry-fields $w.top {database} \
610 # {database-select-action} {destroy .database-select}
612 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
614 label $w.top.databases.label -text "List"
615 listbox $w.top.databases.list -geometry 20x6 \
616 -yscrollcommand "$w.top.databases.scroll set"
617 scrollbar $w.top.databases.scroll -orient vertical -border 1
618 pack $w.top.databases.label -side top -fill x \
620 pack $w.top.databases.list -side left -fill both -expand yes \
622 pack $w.top.databases.scroll -side right -fill y \
624 $w.top.databases.scroll config -command "$w.top.databases.list yview"
626 foreach b [lindex $profile($hostname) 5] {
627 $w.top.databases.list insert end $b
629 top-down-ok-cancel $w {database-select-action}
632 proc save-settings {} {
635 set f [open "~/.tk-c" w]
636 puts $f "# Setup file"
637 puts $f "set hotTargets \{ $hotTargets \}"
641 frame .top -border 1 -relief raised
642 frame .mid -border 1 -relief raised
643 frame .data -border 1 -relief raised
644 frame .bot -border 1 -relief raised
645 pack .top .mid -side top -fill x
646 pack .data -side top -fill both -expand yes
649 menubutton .top.file -text "File" -menu .top.file.m
651 .top.file.m add command -label "Save settings" -command {save-settings}
652 .top.file.m add command -label "Load Set" -command {load-set}
653 .top.file.m add separator
654 .top.file.m add command -label "Exit" -command {destroy .}
656 menubutton .top.target -text "Target" -menu .top.target.m
658 .top.target.m add command -label "Connect" -command {open-target-dialog}
659 .top.target.m add command -label "Disconnect" -command {close-target}
660 .top.target.m add command -label "Initialize" -command {init-request}
661 .top.target.m add command -label "Setup" -command {protocol-setup}
662 .top.target.m add separator
665 menubutton .top.database -text "Database" -menu .top.database.m
667 .top.database.m add command -label "Select ..." -command {database-select}
668 .top.database.m add command -label "Add ..." -command {puts "Add"}
670 menubutton .top.help -text "Help" -menu .top.help.m
672 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
673 .top.help.m add command -label "About" -command {puts "About"}
675 pack .top.file .top.target .top.database -side left
676 pack .top.help -side right
678 label .mid.searchlabel -text {Search:}
679 entry .mid.searchentry -width 50 -relief sunken
681 listbox .data.list -yscrollcommand {.data.scroll set}
683 scrollbar .data.scroll -orient vertical -border 1
684 pack .data.list -side left -fill both -expand yes
685 pack .data.scroll -side right -fill y
686 .data.scroll config -command {.data.list yview}
688 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
689 label .bot.status -text "Not connected" -width 12 -relief \
690 sunken -anchor w -border 1
691 label .bot.message -text "" -width 20 -relief \
692 sunken -anchor w -border 1
693 pack .bot.target .bot.status .bot.message -anchor nw -side left -padx 2 -pady 2
695 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
696 show-full-marc $indx}
701 set csRadioType [z39 comstack]
702 z39 preferredMessageSize 12000