3 # Revision 1.5 1995-03-15 13:59:23 adam
6 # Revision 1.4 1995/03/14 17:32:29 adam
7 # Presentation of full Marc record in popup window.
9 # Revision 1.3 1995/03/12 19:31:52 adam
10 # Pattern matching implemented when retrieving MARC records. More
11 # diagnostic functions.
13 # Revision 1.2 1995/03/10 18:00:15 adam
14 # Actual presentation in line-by-line format. RPN query support.
16 # Revision 1.1 1995/03/09 16:15:07 adam
17 # First presentRequest attempts. Hot-target list.
26 if {[file readable "~/.tk-c"]} {
30 proc top-down-window {w} {
31 frame $w.top -relief raised -border 1
32 frame $w.bot -relief raised -border 1
34 pack $w.top $w.bot -side top -fill both -expand yes
37 proc top-down-ok-cancel {w ok-action} {
38 frame $w.bot.left -relief sunken -border 1
39 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
40 button $w.bot.left.ok -width 6 -text {Ok} \
42 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
43 button $w.bot.cancel -width 6 -text {Cancel} \
45 pack $w.bot.cancel -side left -expand yes
53 proc show-target {target} {
54 .bot.target configure -text "$target"
57 proc show-busy {v1 v2} {
60 .bot.status configure -fg $v1
61 after 200 [list show-busy $v2 $v1]
65 proc show-status {status b} {
68 .bot.status configure -text "$status"
69 .bot.status configure -fg black
75 # . config -cursor {watch black white}
77 # . config -cursor {top_left_arrow black white}
83 proc show-message {msg} {
84 .bot.message configure -text "$msg"
87 proc insertWithTags {w text args} {
88 set start [$w index insert]
89 $w insert insert $text
90 foreach tag [$w tag names $start] {
91 $w tag remove $tag $start insert
94 $w tag add $i $start insert
98 proc show-full-marc {no} {
103 if {[winfo exists $w]} {
104 $w.top.record delete 0.0 end
110 wm minsize $w 200 200
112 frame $w.top -relief raised -border 1
113 frame $w.bot -relief raised -border 1
115 # pack $w.top $w.bot -side top -fill both -expand yes
116 pack $w.top -side top -fill both -expand yes
117 pack $w.bot -fill both
119 text $w.top.record -width 60 -height 10 \
120 -yscrollcommand "$w.top.s set"
121 scrollbar $w.top.s -command "$w.top.record yview"
127 set r [z39.$setNo recordMarc $no line * * *]
129 $w.top.record tag configure marc-tag -foreground blue
130 $w.top.record tag configure marc-data -foreground black
131 $w.top.record tag configure marc-id -foreground red
134 set tag [lindex $line 0]
135 set indicator [lindex $line 1]
136 set fields [lindex $line 2]
138 if {$indicator != ""} {
139 insertWithTags $w.top.record "$tag $indicator" marc-tag
141 insertWithTags $w.top.record "$tag " marc-tag
143 foreach field $fields {
144 set id [lindex $field 0]
145 set data [lindex $field 1]
147 insertWithTags $w.top.record " $id " marc-id
149 set start [$w.top.record index insert]
150 insertWithTags $w.top.record $data {}
152 $w.top.record insert end "\n"
155 bind $w <Return> {destroy .full-marc}
157 pack $w.top.s -side right -fill y
158 pack $w.top.record -expand yes -fill both
160 frame $w.bot.left -relief sunken -border 1
161 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
162 button $w.bot.left.close -width 6 -text {Close} \
163 -command {destroy .full-marc}
164 pack $w.bot.left.close -expand yes -padx 3 -pady 3
165 button $w.bot.edit -width 6 -text {Edit} \
166 -command {destroy .full-marc}
167 pack $w.bot.edit -side left -expand yes
171 proc update-target-hotlist {target} {
174 set len [llength $hotTargets]
176 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
178 set indx [lsearch $hotTargets $target]
180 set hotTargets [lreplace $hotTargets $indx $indx]
182 set hotTargets [linsert $hotTargets 0 $target]
186 proc set-target-hotlist {} {
190 foreach target $hotTargets {
191 .top.target.m add command -label $target -command \
192 "menu-open-target $target"
200 proc menu-open-target {target} {
202 update-target-hotlist $target
205 proc open-target-action {} {
206 set host [.target-connect.top.host.entry get]
207 set port [.target-connect.top.port.entry get]
215 open-target "${host}:${port}"
216 update-target-hotlist ${host}:${port}
217 destroy .target-connect
220 proc open-target {target} {
223 z39 comstack ${csRadioType}
230 proc load-set-action {} {
236 set fname [.load-set.top.filename.entry get]
239 .data.list delete 0 end
241 show-status {Loading} 1
242 z39.$setNo loadFile $fname
244 set no [z39.$setNo numberOfRecordsReturned]
245 add-title-lines $no 1
247 show-status {Ready} 0
259 frame $w.top.filename
261 pack $w.top.filename -side top -anchor e -pady 2
263 entry-fields $w.top {filename} \
265 {load-set-action} {destroy .load-set}
267 top-down-ok-cancel $w {load-set-action}
270 proc init-request {} {
273 z39 callback {init-response}
275 show-status {Initializing} 1
279 proc init-response {} {
280 show-status {Ready} 0
281 pack .mid.searchlabel .mid.searchentry -side left
282 bind .mid.searchentry <Return> search-request
283 focus .mid.searchentry
286 proc search-request {} {
292 z39 callback {search-response}
293 z39.$setNo search [.mid.searchentry get]
294 show-status {Search} 1
297 proc search-response {} {
302 .data.list delete 0 end
303 show-status {Ready} 0
304 show-message "[z39.$setNo resultCount] hits"
305 set setMax [z39.$setNo resultCount]
310 z39 callback {present-response}
312 z39.$setNo present 1 $setMax
313 show-status {Retrieve} 1
316 proc add-title-lines {no offset} {
319 for {set i 0} {$i < $no} {incr i} {
320 set o [expr $i + $offset]
321 set title [lindex [z39.$setNo recordMarc $o field 245 * a] 0]
322 set year [lindex [z39.$setNo recordMarc $o field 260 * c] 0]
323 .data.list insert end "$title - $year"
327 proc present-response {} {
332 puts "In present-response"
333 set no [z39.$setNo numberOfRecordsReturned]
334 puts "Returned $no records, setOffset $setOffset"
335 add-title-lines $no $setOffset
336 set setOffset [expr $setOffset + $no]
337 if { $setOffset <= $setMax} {
338 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
340 show-status {Finished} 0
344 proc bind-fields {list returnAction escapeAction} {
345 set max [expr [llength $list]-1]
346 for {set i 0} {$i < $max} {incr i} {
347 bind [lindex $list $i] <Return> $returnAction
348 bind [lindex $list $i] <Escape> $escapeAction
349 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
351 bind [lindex $list $i] <Return> $returnAction
352 bind [lindex $list $i] <Escape> $escapeAction
353 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
354 focus [lindex $list 0]
357 proc entry-fields {parent list tlist returnAction escapeAction} {
360 foreach field $list {
361 set label ${parent}.${field}.label
362 set entry ${parent}.${field}.entry
363 label $label -text [lindex $tlist $i] -anchor e
364 entry $entry -width 30 -relief sunken
365 pack $label -side left
366 pack $entry -side right
370 bind-fields $alist $returnAction $escapeAction
373 proc open-target-dialog {} {
374 set w .target-connect
385 pack $w.top.host $w.top.port \
386 -side top -anchor e -pady 2
388 entry-fields $w.top {host port } \
389 {{Hostname:} {Port number:}} \
390 {open-target-action} {destroy .target-connect}
392 top-down-ok-cancel $w {open-target-action}
395 proc close-target {} {
396 pack forget .mid.searchlabel .mid.searchentry
399 show-status {Not connected} 0
403 proc protocol-setup-action {} {
404 destroy .protocol-setup
408 proc place-force {window parent} {
409 set g [wm geometry $parent]
411 set p1 [string first + $g]
412 set p2 [string last + $g]
414 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
415 set y [expr 60+[string range $g [expr $p2 +1] end]]
416 wm geometry $window +${x}+${y}
419 proc protocol-setup {} {
420 set w .protocol-setup
428 frame $w.top.description
429 frame $w.top.idAuthentification
430 frame $w.top.maximumMessageSize
431 frame $w.top.preferredMessageSize
432 frame $w.top.cs-type -relief ridge -border 2
433 frame $w.top.query -relief ridge -border 2
435 # Maximum/preferred/idAuth ...
436 pack $w.top.description \
437 $w.top.idAuthentification $w.top.maximumMessageSize \
438 $w.top.preferredMessageSize -side top -anchor e -pady 2
440 entry-fields $w.top {description idAuthentification maximumMessageSize \
441 preferredMessageSize} \
442 {{Description:} {Id Authentification:} {Maximum Message Size:}
443 {Preferred Message Size:}} \
444 {protocol-setup-action} {destroy .protocol-setup}
447 pack $w.top.cs-type -side left -pady 2 -padx 2
451 label $w.top.cs-type.label -text "Transport" -anchor e
452 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
453 -command {puts tcp/ip} -variable csRadioType -value tcpip
454 radiobutton $w.top.cs-type.mosi -text "MOSI" \
455 -command {puts mosi} -variable csRadioType -value mosi
457 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
458 -padx 4 -side top -fill x
461 pack $w.top.query -side right -pady 2 -padx 2 -expand yes
463 label $w.top.query.label -text "Query support" -anchor e
464 checkbutton $w.top.query.c1 -text "CCL query"
465 checkbutton $w.top.query.c2 -text "RPN query"
466 checkbutton $w.top.query.c3 -text "Result sets"
468 pack $w.top.query.label -side top -anchor w
469 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
470 -padx 4 -side left -fill x
472 top-down-ok-cancel $w {protocol-setup-action}
475 proc database-select-action {} {
476 z39 databaseNames [.database-select.top.database.entry get]
477 destroy .database-select
480 proc database-select {} {
481 set w .database-select
489 frame $w.top.database
491 pack $w.top.database -side top -anchor e -pady 2
493 entry-fields $w.top {database} \
495 {database-select-action} {destroy .database-select}
497 top-down-ok-cancel $w {database-select-action}
500 proc save-settings {} {
503 set f [open "~/.tk-c" w]
504 puts $f "# Setup file"
505 puts $f "set hotTargets \{ $hotTargets \}"
509 frame .top -border 1 -relief raised
510 frame .mid -border 1 -relief raised
511 frame .data -border 1 -relief raised
512 frame .bot -border 1 -relief raised
513 pack .top .mid -side top -fill x
514 pack .data -side top -fill both -expand yes
517 menubutton .top.file -text "File" -menu .top.file.m
519 .top.file.m add command -label "Save settings" -command {save-settings}
520 .top.file.m add command -label "Load Set" -command {load-set}
521 .top.file.m add separator
522 .top.file.m add command -label "Exit" -command {destroy .}
524 menubutton .top.target -text "Target" -menu .top.target.m
526 .top.target.m add command -label "Connect" -command {open-target-dialog}
527 .top.target.m add command -label "Disconnect" -command {close-target}
528 .top.target.m add command -label "Initialize" -command {init-request}
529 .top.target.m add command -label "Setup" -command {protocol-setup}
530 .top.target.m add separator
533 menubutton .top.database -text "Database" -menu .top.database.m
535 .top.database.m add command -label "Select ..." -command {database-select}
536 .top.database.m add command -label "Add ..." -command {puts "Add"}
538 menubutton .top.help -text "Help" -menu .top.help.m
540 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
541 .top.help.m add command -label "About" -command {puts "About"}
543 pack .top.file .top.target .top.database -side left
544 pack .top.help -side right
546 label .mid.searchlabel -text {Search:}
547 entry .mid.searchentry -width 50 -relief sunken
549 listbox .data.list -yscrollcommand {.data.scroll set}
551 scrollbar .data.scroll -orient vertical -border 1
552 pack .data.list -side left -fill both -expand yes
553 pack .data.scroll -side right -fill y
554 .data.scroll config -command {.data.list yview}
556 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
557 label .bot.status -text "Not connected" -width 12 -relief \
558 sunken -anchor w -border 1
559 label .bot.message -text "" -width 20 -relief \
560 sunken -anchor w -border 1
561 pack .bot.target .bot.status .bot.message -anchor nw -side left -padx 2 -pady 2
563 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
564 show-full-marc $indx}
569 set csRadioType [z39 comstack]
570 z39 preferredMessageSize 12000