3 # Revision 1.4 1995-03-14 17:32:29 adam
4 # Presentation of full Marc record in popup window.
6 # Revision 1.3 1995/03/12 19:31:52 adam
7 # Pattern matching implemented when retrieving MARC records. More
8 # diagnostic functions.
10 # Revision 1.2 1995/03/10 18:00:15 adam
11 # Actual presentation in line-by-line format. RPN query support.
13 # Revision 1.1 1995/03/09 16:15:07 adam
14 # First presentRequest attempts. Hot-target list.
23 if {[file readable "~/.tk-c"]} {
27 proc top-down-window {w} {
28 frame $w.top -relief raised -border 1
29 frame $w.bot -relief raised -border 1
31 pack $w.top $w.bot -side top -fill both -expand yes
34 proc top-down-ok-cancel {w ok-action} {
35 frame $w.bot.left -relief sunken -border 1
36 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
37 button $w.bot.left.ok -width 6 -text {Ok} \
39 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
40 button $w.bot.cancel -width 6 -text {Cancel} \
42 pack $w.bot.cancel -side left -expand yes
50 proc show-target {target} {
51 .bot.target configure -text "$target"
54 proc show-busy {v1 v2} {
57 .bot.status configure -fg $v1
58 after 200 [list show-busy $v2 $v1]
62 proc show-status {status b} {
65 .bot.status configure -text "$status"
66 .bot.status configure -fg black
72 # . config -cursor {watch black white}
74 # . config -cursor {top_left_arrow black white}
80 proc show-message {msg} {
81 .bot.message configure -text "$msg"
84 proc insertWithTags {w text args} {
85 set start [$w index insert]
86 $w insert insert $text
87 foreach tag [$w tag names $start] {
88 $w tag remove $tag $start insert
91 $w tag add $i $start insert
95 proc show-full-marc {no} {
100 if {[winfo exists $w]} {
101 $w.top.record delete 0.0 end
107 wm minsize $w 200 200
109 frame $w.top -relief raised -border 1
110 frame $w.bot -relief raised -border 1
112 # pack $w.top $w.bot -side top -fill both -expand yes
113 pack $w.top -side top -fill both -expand yes
114 pack $w.bot -fill both
116 text $w.top.record -width 60 -height 10 \
117 -yscrollcommand "$w.top.s set"
118 scrollbar $w.top.s -command "$w.top.record yview"
124 set r [z39.$setNo recordMarc $no line * * *]
126 $w.top.record tag configure marc-tag -foreground blue
127 $w.top.record tag configure marc-data -foreground black
128 $w.top.record tag configure marc-id -foreground red
131 set tag [lindex $line 0]
132 set indicator [lindex $line 1]
133 set fields [lindex $line 2]
135 if {$indicator != ""} {
136 insertWithTags $w.top.record "$tag $indicator" marc-tag
138 insertWithTags $w.top.record "$tag " marc-tag
140 foreach field $fields {
141 set id [lindex $field 0]
142 set data [lindex $field 1]
144 insertWithTags $w.top.record " $id " marc-id
146 set start [$w.top.record index insert]
147 insertWithTags $w.top.record $data {}
149 $w.top.record insert end "\n"
152 bind $w <Return> {destroy .full-marc}
154 pack $w.top.s -side right -fill y
155 pack $w.top.record -expand yes -fill both
157 frame $w.bot.left -relief sunken -border 1
158 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
159 button $w.bot.left.close -width 6 -text {Close} \
160 -command {destroy .full-marc}
161 pack $w.bot.left.close -expand yes -padx 3 -pady 3
162 button $w.bot.edit -width 6 -text {Edit} \
163 -command {destroy .full-marc}
164 pack $w.bot.edit -side left -expand yes
168 proc update-target-hotlist {target} {
171 set len [llength $hotTargets]
173 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
175 set indx [lsearch $hotTargets $target]
177 set hotTargets [lreplace $hotTargets $indx $indx]
179 set hotTargets [linsert $hotTargets 0 $target]
183 proc set-target-hotlist {} {
187 foreach target $hotTargets {
188 .top.target.m add command -label $target -command \
189 "menu-open-target $target"
197 proc menu-open-target {target} {
199 update-target-hotlist $target
202 proc open-target-action {} {
203 set host [.target-connect.top.host.entry get]
204 set port [.target-connect.top.port.entry get]
212 open-target "${host}:${port}"
213 update-target-hotlist ${host}:${port}
214 destroy .target-connect
217 proc open-target {target} {
220 z39 comstack ${csRadioType}
227 proc load-set-action {} {
233 set fname [.load-set.top.filename.entry get]
236 .data.list delete 0 end
238 show-status {Loading} 1
239 z39.$setNo loadFile $fname
241 set no [z39.$setNo numberOfRecordsReturned]
242 add-title-lines $no 1
244 show-status {Ready} 0
256 frame $w.top.filename
258 pack $w.top.filename -side top -anchor e -pady 2
260 entry-fields $w.top {filename} \
262 {load-set-action} {destroy .load-set}
264 top-down-ok-cancel $w {load-set-action}
267 proc init-request {} {
270 z39 callback {init-response}
272 show-status {Initializing} 1
276 proc init-response {} {
277 show-status {Ready} 0
278 pack .mid.searchlabel .mid.searchentry -side left
279 bind .mid.searchentry <Return> search-request
280 focus .mid.searchentry
283 proc search-request {} {
289 z39 callback {search-response}
290 z39.$setNo search [.mid.searchentry get]
291 show-status {Search} 1
294 proc search-response {} {
299 .data.list delete 0 end
300 show-status {Ready} 0
301 show-message "[z39.$setNo resultCount] hits"
302 set setMax [z39.$setNo resultCount]
307 z39 callback {present-response}
309 z39.$setNo present 1 $setMax
310 show-status {Retrieve} 1
313 proc add-title-lines {no offset} {
316 for {set i 0} {$i < $no} {incr i} {
317 set o [expr $i + $offset]
318 set title [lindex [z39.$setNo recordMarc $o field 245 * a] 0]
319 set year [lindex [z39.$setNo recordMarc $o field 260 * c] 0]
320 .data.list insert end "$title - $year"
324 proc present-response {} {
329 puts "In present-response"
330 set no [z39.$setNo numberOfRecordsReturned]
331 puts "Returned $no records, setOffset $setOffset"
332 add-title-lines $no $setOffset
333 set setOffset [expr $setOffset + $no]
334 if { $setOffset <= $setMax} {
335 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
337 show-status {Finished} 0
341 proc bind-fields {list returnAction escapeAction} {
342 set max [expr [llength $list]-1]
343 for {set i 0} {$i < $max} {incr i} {
344 bind [lindex $list $i] <Return> $returnAction
345 bind [lindex $list $i] <Escape> $escapeAction
346 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
348 bind [lindex $list $i] <Return> $returnAction
349 bind [lindex $list $i] <Escape> $escapeAction
350 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
351 focus [lindex $list 0]
354 proc entry-fields {parent list tlist returnAction escapeAction} {
357 foreach field $list {
358 set label ${parent}.${field}.label
359 set entry ${parent}.${field}.entry
360 label $label -text [lindex $tlist $i] -anchor e
361 entry $entry -width 30 -relief sunken
362 pack $label -side left
363 pack $entry -side right
367 bind-fields $alist $returnAction $escapeAction
370 proc open-target-dialog {} {
371 set w .target-connect
382 pack $w.top.host $w.top.port \
383 -side top -anchor e -pady 2
385 entry-fields $w.top {host port } \
386 {{Hostname:} {Port number:}} \
387 {open-target-action} {destroy .target-connect}
389 top-down-ok-cancel $w {open-target-action}
392 proc close-target {} {
393 pack forget .mid.searchlabel .mid.searchentry
396 show-status {Not connected} 0
400 proc protocol-setup-action {} {
401 destroy .protocol-setup
405 proc place-force {window parent} {
406 set g [wm geometry $parent]
408 set p1 [string first + $g]
409 set p2 [string last + $g]
411 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
412 set y [expr 60+[string range $g [expr $p2 +1] end]]
413 wm geometry $window +${x}+${y}
416 proc protocol-setup {} {
417 set w .protocol-setup
425 frame $w.top.description
426 frame $w.top.idAuthentification
427 frame $w.top.maximumMessageSize
428 frame $w.top.preferredMessageSize
429 frame $w.top.cs-type -relief ridge -border 2
430 frame $w.top.query -relief ridge -border 2
432 # Maximum/preferred/idAuth ...
433 pack $w.top.description \
434 $w.top.idAuthentification $w.top.maximumMessageSize \
435 $w.top.preferredMessageSize -side top -anchor e -pady 2
437 entry-fields $w.top {description idAuthentification maximumMessageSize \
438 preferredMessageSize} \
439 {{Description:} {Id Authentification:} {Maximum Message Size:}
440 {Preferred Message Size:}} \
441 {protocol-setup-action} {destroy .protocol-setup}
444 pack $w.top.cs-type -side left -pady 2 -padx 2
448 label $w.top.cs-type.label -text "Transport" -anchor e
449 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
450 -command {puts tcp/ip} -variable csRadioType -value tcpip
451 radiobutton $w.top.cs-type.mosi -text "MOSI" \
452 -command {puts mosi} -variable csRadioType -value mosi
454 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
455 -padx 4 -side top -fill x
458 pack $w.top.query -side right -pady 2 -padx 2 -expand yes
460 label $w.top.query.label -text "Query support" -anchor e
461 checkbutton $w.top.query.c1 -text "CCL query"
462 checkbutton $w.top.query.c2 -text "RPN query"
463 checkbutton $w.top.query.c3 -text "Result sets"
465 pack $w.top.query.label -side top -anchor w
466 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
467 -padx 4 -side left -fill x
469 top-down-ok-cancel $w {protocol-setup-action}
472 proc database-select-action {} {
473 z39 databaseNames [.database-select.top.database.entry get]
474 destroy .database-select
477 proc database-select {} {
478 set w .database-select
486 frame $w.top.database
488 pack $w.top.database -side top -anchor e -pady 2
490 entry-fields $w.top {database} \
492 {database-select-action} {destroy .database-select}
494 top-down-ok-cancel $w {database-select-action}
497 proc save-settings {} {
500 set f [open "~/.tk-c" w]
501 puts $f "# Setup file"
502 puts $f "set hotTargets \{ $hotTargets \}"
506 frame .top -border 1 -relief raised
507 frame .mid -border 1 -relief raised
508 frame .data -border 1 -relief raised
509 frame .bot -border 1 -relief raised
510 pack .top .mid -side top -fill x
511 pack .data -side top -fill both -expand yes
514 menubutton .top.file -text "File" -menu .top.file.m
516 .top.file.m add command -label "Save settings" -command {save-settings}
517 .top.file.m add command -label "Load Set" -command {load-set}
518 .top.file.m add separator
519 .top.file.m add command -label "Exit" -command {destroy .}
521 menubutton .top.target -text "Target" -menu .top.target.m
523 .top.target.m add command -label "Connect" -command {open-target-dialog}
524 .top.target.m add command -label "Disconnect" -command {close-target}
525 .top.target.m add command -label "Initialize" -command {init-request}
526 .top.target.m add command -label "Setup" -command {protocol-setup}
527 .top.target.m add separator
530 menubutton .top.database -text "Database" -menu .top.database.m
532 .top.database.m add command -label "Select ..." -command {database-select}
533 .top.database.m add command -label "Add ..." -command {puts "Add"}
535 menubutton .top.help -text "Help" -menu .top.help.m
537 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
538 .top.help.m add command -label "About" -command {puts "About"}
540 pack .top.file .top.target .top.database -side left
541 pack .top.help -side right
543 label .mid.searchlabel -text {Search:}
544 entry .mid.searchentry -width 50 -relief sunken
546 listbox .data.list -yscrollcommand {.data.scroll set}
548 scrollbar .data.scroll -orient vertical -border 1
549 pack .data.list -side left -fill both -expand yes
550 pack .data.scroll -side right -fill y
551 .data.scroll config -command {.data.list yview}
553 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
554 label .bot.status -text "Not connected" -width 12 -relief \
555 sunken -anchor w -border 1
556 label .bot.message -text "" -width 20 -relief \
557 sunken -anchor w -border 1
558 pack .bot.target .bot.status .bot.message -anchor nw -side left -padx 2 -pady 2
560 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
561 show-full-marc $indx}
566 set csRadioType [z39 comstack]