3 # Revision 1.3 1995-03-12 19:31:52 adam
4 # Pattern matching implemented when retrieving MARC records. More
5 # diagnostic functions.
7 # Revision 1.2 1995/03/10 18:00:15 adam
8 # Actual presentation in line-by-line format. RPN query support.
10 # Revision 1.1 1995/03/09 16:15:07 adam
11 # First presentRequest attempts. Hot-target list.
21 if {[file readable "~/.tk-c"]} {
25 proc show-target {target} {
26 .bot.target configure -text "$target"
29 proc show-busy {v1 v2} {
32 .bot.status configure -fg $v1
33 after 200 [list show-busy $v2 $v1]
37 proc show-status {status b} {
40 .bot.status configure -text "$status"
41 .bot.status configure -fg black
47 # . config -cursor {watch black white}
49 # . config -cursor {top_left_arrow black white}
55 proc show-message {msg} {
56 .bot.message configure -text "$msg"
59 proc update-target-hotlist {target} {
62 set len [llength $hotTargets]
64 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
66 set indx [lsearch $hotTargets $target]
68 set hotTargets [lreplace $hotTargets $indx $indx]
70 set hotTargets [linsert $hotTargets 0 $target]
74 proc set-target-hotlist {} {
78 foreach target $hotTargets {
79 .top.target.m add command -label $target -command \
80 "menu-open-target $target"
88 proc menu-open-target {target} {
90 update-target-hotlist $target
93 proc open-target-action {} {
94 set host [.target-connect.top.host.entry get]
95 set port [.target-connect.top.port.entry get]
103 open-target "${host}:${port}"
104 update-target-hotlist ${host}:${port}
105 destroy .target-connect
108 proc open-target {target} {
111 z39 comstack ${csRadioType}
118 proc init-request {} {
121 z39 callback {init-response}
123 show-status {Initializing} 1
127 proc init-response {} {
128 show-status {Ready} 0
129 pack .mid.searchlabel .mid.searchentry -side left
130 bind .mid.searchentry <Return> search-request
131 focus .mid.searchentry
134 proc search-request {} {
140 z39 callback {search-response}
141 z39.$SetNo search [.mid.searchentry get]
142 show-status {Search} 1
145 proc search-response {} {
150 .data.list delete 0 end
151 show-status {Ready} 0
152 show-message "[z39.$SetNo resultCount] hits"
153 set setMax [z39.$SetNo resultCount]
158 z39 callback {present-response}
160 z39.$SetNo present 1 $setMax
161 show-status {Retrieve} 1
164 proc present-response {} {
169 puts "In present-response"
170 set no [z39.$SetNo numberOfRecordsReturned]
171 puts "Returned $no records, setOffset $setOffset"
172 for {set i 0} {$i < $no} {incr i} {
173 set o [expr $i + $setOffset]
174 set title [lindex [z39.$SetNo getMARC $o field 245 a] 0]
175 set year [lindex [z39.$SetNo getMARC $o field 260 c] 0]
176 .data.list insert end "$title - $year"
178 set setOffset [expr $setOffset + $no]
179 if { $setOffset <= $setMax} {
180 z39.$SetNo present $setOffset [expr $setMax - $setOffset + 1]
182 show-status {Finished} 0
186 proc bind-fields {list returnAction escapeAction} {
187 set max [expr [llength $list]-1]
188 for {set i 0} {$i < $max} {incr i} {
189 bind [lindex $list $i] <Return> $returnAction
190 bind [lindex $list $i] <Escape> $escapeAction
191 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
193 bind [lindex $list $i] <Return> $returnAction
194 bind [lindex $list $i] <Escape> $escapeAction
195 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
196 focus [lindex $list 0]
199 proc entry-fields {parent list tlist returnAction escapeAction} {
202 foreach field $list {
203 set label ${parent}.${field}.label
204 set entry ${parent}.${field}.entry
205 label $label -text [lindex $tlist $i] -anchor e
206 entry $entry -width 30 -relief sunken
207 pack $label -side left
208 pack $entry -side right
212 bind-fields $alist $returnAction $escapeAction
215 proc open-target-dialog {} {
216 set w .target-connect
222 frame $w.top -relief sunken -border 1
223 frame $w.bot -relief sunken -border 1
225 pack $w.top $w.bot -side top -fill both -expand yes
230 pack $w.top.host $w.top.port \
231 -side top -anchor e -pady 2
233 entry-fields $w.top {host port } \
234 {{Hostname:} {Port number:}} \
235 {open-target-action} {destroy .target-connect}
237 frame $w.bot.left -relief sunken -border 1
238 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
239 button $w.bot.left.ok -width 6 -text {Ok} \
240 -command {open-target-action}
241 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
242 button $w.bot.cancel -width 6 -text {Cancel} \
243 -command {destroy .target-connect}
244 pack $w.bot.cancel -side left -expand yes
251 proc close-target {} {
252 pack forget .mid.searchlabel .mid.searchentry
255 show-status {Not connected} 0
259 proc protocol-setup-action {} {
260 destroy .protocol-setup
264 proc place-force {window parent} {
265 set g [wm geometry $parent]
267 set p1 [string first + $g]
268 set p2 [string last + $g]
270 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
271 set y [expr 60+[string range $g [expr $p2 +1] end]]
272 wm geometry $window +${x}+${y}
275 proc protocol-setup {} {
276 set w .protocol-setup
282 frame $w.top -relief sunken -border 1
283 frame $w.bot -relief sunken -border 1
285 pack $w.top $w.bot -side top -fill both -expand yes
287 frame $w.top.description
288 frame $w.top.idAuthentification
289 frame $w.top.maximumMessageSize
290 frame $w.top.preferredMessageSize
291 frame $w.top.cs-type -relief ridge -border 2
292 frame $w.top.query -relief ridge -border 2
294 # Maximum/preferred/idAuth ...
295 pack $w.top.description \
296 $w.top.idAuthentification $w.top.maximumMessageSize \
297 $w.top.preferredMessageSize -side top -anchor e -pady 2
299 entry-fields $w.top {description idAuthentification maximumMessageSize \
300 preferredMessageSize} \
301 {{Description:} {Id Authentification:} {Maximum Message Size:}
302 {Preferred Message Size:}} \
303 {protocol-setup-action} {destroy .protocol-setup}
306 pack $w.top.cs-type -side left -pady 2 -padx 2
310 label $w.top.cs-type.label -text "Transport" -anchor e
311 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
312 -command {puts tcp/ip} -variable csRadioType -value tcpip
313 radiobutton $w.top.cs-type.mosi -text "MOSI" \
314 -command {puts mosi} -variable csRadioType -value mosi
316 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
317 -padx 4 -side top -fill x
320 pack $w.top.query -side right -pady 2 -padx 2 -expand yes
322 label $w.top.query.label -text "Query support" -anchor e
323 checkbutton $w.top.query.c1 -text "CCL query"
324 checkbutton $w.top.query.c2 -text "RPN query"
325 checkbutton $w.top.query.c3 -text "Result sets"
327 pack $w.top.query.label -side top -anchor w
328 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
329 -padx 4 -side left -fill x
332 frame $w.bot.left -relief sunken -border 1
333 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
334 button $w.bot.left.ok -width 6 -text {Ok} \
335 -command {protocol-setup-action}
336 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
337 button $w.bot.cancel -width 6 -text {Cancel} \
338 -command "destroy $w"
339 pack $w.bot.cancel -side left -expand yes
348 proc database-select-action {} {
349 z39 databaseNames [.database-select.top.database.entry get]
350 destroy .database-select
353 proc database-select {} {
354 set w .database-select
360 frame $w.top -relief sunken -border 1
361 frame $w.bot -relief sunken -border 1
363 pack $w.top $w.bot -side top -fill both -expand yes
365 frame $w.top.database
368 pack $w.top.database -side top -anchor e -pady 2
370 entry-fields $w.top {database} \
372 {database-select-action} {destroy .database-select}
375 frame $w.bot.left -relief sunken -border 1
376 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
377 button $w.bot.left.ok -width 6 -text {Ok} \
378 -command {protocol-setup-action}
379 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
380 button $w.bot.cancel -width 6 -text {Cancel} \
381 -command "destroy .database-select"
382 pack $w.bot.cancel -side left -expand yes
390 proc save-settings {} {
393 set f [open "~/.tk-c" w]
394 puts $f "# Setup file"
395 puts $f "set hotTargets \{ $hotTargets \}"
399 frame .top -border 1 -relief raised
400 frame .mid -border 1 -relief raised
401 frame .data -border 1 -relief raised
402 frame .bot -border 1 -relief raised
403 pack .top .mid -side top -fill x
404 pack .data -side top -fill both -expand yes
407 menubutton .top.file -text "File" -menu .top.file.m
409 .top.file.m add command -label "Save settings" -command {save-settings}
410 .top.file.m add command -label "Exit" -command {destroy .}
412 menubutton .top.target -text "Target" -menu .top.target.m
414 .top.target.m add command -label "Connect" -command {open-target-dialog}
415 .top.target.m add command -label "Disconnect" -command {close-target}
416 .top.target.m add command -label "Initialize" -command {init-request}
417 .top.target.m add command -label "Setup" -command {protocol-setup}
418 .top.target.m add separator
421 menubutton .top.database -text "Database" -menu .top.database.m
423 .top.database.m add command -label "Select ..." -command {database-select}
424 .top.database.m add command -label "Add ..." -command {puts "Add"}
426 menubutton .top.help -text "Help" -menu .top.help.m
428 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
429 .top.help.m add command -label "About" -command {puts "About"}
431 pack .top.file .top.target .top.database -side left
432 pack .top.help -side right
434 label .mid.searchlabel -text {Search:}
435 entry .mid.searchentry -width 50 -relief sunken
437 listbox .data.list -yscrollcommand {.data.scroll set}
439 scrollbar .data.scroll -orient vertical -border 1
440 pack .data.list -side left -fill both -expand yes
441 pack .data.scroll -side right -fill y
442 .data.scroll config -command {.data.list yview}
444 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
445 label .bot.status -text "Not connected" -width 12 -relief \
446 sunken -anchor w -border 1
447 label .bot.message -text "" -width 20 -relief \
448 sunken -anchor w -border 1
449 pack .bot.target .bot.status .bot.message -anchor nw -side left -padx 2 -pady 2
451 for {set i 0} {$i < 30} {incr i} {
452 .data.list insert end "Record $i"
455 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
456 puts "y=%y index $indx" }
460 set csRadioType [z39 comstack]