3 # Revision 1.2 1995-03-10 18:00:15 adam
4 # Actual presentation in line-by-line format. RPN query support.
6 # Revision 1.1 1995/03/09 16:15:07 adam
7 # First presentRequest attempts. Hot-target list.
17 if {[file readable "~/.tk-c"]} {
21 proc show-target {target} {
22 .bot.target configure -text "$target"
25 proc show-busy {v1 v2} {
28 .bot.status configure -fg $v1
29 after 200 [list show-busy $v2 $v1]
33 proc show-status {status b} {
36 .bot.status configure -text "$status"
37 .bot.status configure -fg black
43 # . config -cursor {watch black white}
45 # . config -cursor {top_left_arrow black white}
51 proc show-message {msg} {
52 .bot.message configure -text "$msg"
55 proc update-target-hotlist {target} {
58 set len [llength $hotTargets]
60 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
62 set indx [lsearch $hotTargets $target]
64 set hotTargets [lreplace $hotTargets $indx $indx]
66 set hotTargets [linsert $hotTargets 0 $target]
70 proc set-target-hotlist {} {
74 foreach target $hotTargets {
75 .top.target.m add command -label $target -command \
76 "menu-open-target $target"
84 proc menu-open-target {target} {
86 update-target-hotlist $target
89 proc open-target-action {} {
90 set host [.target-connect.top.host.entry get]
91 set port [.target-connect.top.port.entry get]
99 open-target "${host}:${port}"
100 update-target-hotlist ${host}:${port}
101 destroy .target-connect
104 proc open-target {target} {
107 z39 comstack ${csRadioType}
114 proc init-request {} {
117 z39 callback {init-response}
119 show-status {Initializing} 1
123 proc init-response {} {
124 show-status {Ready} 0
125 pack .mid.searchlabel .mid.searchentry -side left
126 bind .mid.searchentry <Return> search-request
127 focus .mid.searchentry
130 proc search-request {} {
136 z39 callback {search-response}
137 z39.$SetNo search [.mid.searchentry get]
138 show-status {Search} 1
141 proc search-response {} {
146 .data.list delete 0 end
147 show-status {Ready} 0
148 show-message "[z39.$SetNo resultCount] hits"
149 set setMax [z39.$SetNo resultCount]
154 z39 callback {present-response}
156 z39.$SetNo present 1 $setMax
157 show-status {Retrieve} 1
160 proc present-response {} {
165 puts "In present-response"
166 set no [z39.$SetNo numberOfRecordsReturned]
167 puts "Returned $no records, setOffset $setOffset"
168 for {set i 0} {$i < $no} {incr i} {
169 set o [expr $i + $setOffset]
170 set title [lindex [z39.$SetNo getRecord $o 245 a] 0]
171 set year [lindex [z39.$SetNo getRecord $o 260 c] 0]
172 .data.list insert end "$title - $year"
174 set setOffset [expr $setOffset + $no]
175 if { $setOffset <= $setMax} {
176 z39.$SetNo present $setOffset [expr $setMax - $setOffset + 1]
178 show-status {Finished} 0
182 proc bind-fields {list returnAction escapeAction} {
183 set max [expr [llength $list]-1]
184 for {set i 0} {$i < $max} {incr i} {
185 bind [lindex $list $i] <Return> $returnAction
186 bind [lindex $list $i] <Escape> $escapeAction
187 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
189 bind [lindex $list $i] <Return> $returnAction
190 bind [lindex $list $i] <Escape> $escapeAction
191 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
192 focus [lindex $list 0]
195 proc entry-fields {parent list tlist returnAction escapeAction} {
198 foreach field $list {
199 set label ${parent}.${field}.label
200 set entry ${parent}.${field}.entry
201 label $label -text [lindex $tlist $i] -anchor e
202 entry $entry -width 30 -relief sunken
203 pack $label -side left
204 pack $entry -side right
208 bind-fields $alist $returnAction $escapeAction
211 proc open-target-dialog {} {
212 set w .target-connect
218 frame $w.top -relief sunken -border 1
219 frame $w.bot -relief sunken -border 1
221 pack $w.top $w.bot -side top -fill both -expand yes
226 pack $w.top.host $w.top.port \
227 -side top -anchor e -pady 2
229 entry-fields $w.top {host port } \
230 {{Hostname:} {Port number:}} \
231 {open-target-action} {destroy .target-connect}
233 frame $w.bot.left -relief sunken -border 1
234 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
235 button $w.bot.left.ok -width 6 -text {Ok} \
236 -command {open-target-action}
237 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
238 button $w.bot.cancel -width 6 -text {Cancel} \
239 -command {destroy .target-connect}
240 pack $w.bot.cancel -side left -expand yes
247 proc close-target {} {
248 pack forget .mid.searchlabel .mid.searchentry
251 show-status {Not connected} 0
255 proc protocol-setup-action {} {
256 destroy .protocol-setup
260 proc place-force {window parent} {
261 set g [wm geometry $parent]
263 set p1 [string first + $g]
264 set p2 [string last + $g]
266 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
267 set y [expr 60+[string range $g [expr $p2 +1] end]]
268 wm geometry $window +${x}+${y}
271 proc protocol-setup {} {
272 set w .protocol-setup
278 frame $w.top -relief sunken -border 1
279 frame $w.bot -relief sunken -border 1
281 pack $w.top $w.bot -side top -fill both -expand yes
283 frame $w.top.description
284 frame $w.top.idAuthentification
285 frame $w.top.maximumMessageSize
286 frame $w.top.preferredMessageSize
287 frame $w.top.cs-type -relief ridge -border 2
288 frame $w.top.query -relief ridge -border 2
290 # Maximum/preferred/idAuth ...
291 pack $w.top.description \
292 $w.top.idAuthentification $w.top.maximumMessageSize \
293 $w.top.preferredMessageSize -side top -anchor e -pady 2
295 entry-fields $w.top {description idAuthentification maximumMessageSize \
296 preferredMessageSize} \
297 {{Description:} {Id Authentification:} {Maximum Message Size:}
298 {Preferred Message Size:}} \
299 {protocol-setup-action} {destroy .protocol-setup}
302 pack $w.top.cs-type -side left -pady 2 -padx 2
306 label $w.top.cs-type.label -text "Transport" -anchor e
307 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
308 -command {puts tcp/ip} -variable csRadioType -value tcpip
309 radiobutton $w.top.cs-type.mosi -text "MOSI" \
310 -command {puts mosi} -variable csRadioType -value mosi
312 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
313 -padx 4 -side top -fill x
316 pack $w.top.query -side right -pady 2 -padx 2 -expand yes
318 label $w.top.query.label -text "Query support" -anchor e
319 checkbutton $w.top.query.c1 -text "CCL query"
320 checkbutton $w.top.query.c2 -text "RPN query"
321 checkbutton $w.top.query.c3 -text "Result sets"
323 pack $w.top.query.label -side top -anchor w
324 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
325 -padx 4 -side left -fill x
328 frame $w.bot.left -relief sunken -border 1
329 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
330 button $w.bot.left.ok -width 6 -text {Ok} \
331 -command {protocol-setup-action}
332 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
333 button $w.bot.cancel -width 6 -text {Cancel} \
334 -command "destroy $w"
335 pack $w.bot.cancel -side left -expand yes
344 proc database-select-action {} {
345 z39 databaseNames [.database-select.top.database.entry get]
346 destroy .database-select
349 proc database-select {} {
350 set w .database-select
356 frame $w.top -relief sunken -border 1
357 frame $w.bot -relief sunken -border 1
359 pack $w.top $w.bot -side top -fill both -expand yes
361 frame $w.top.database
364 pack $w.top.database -side top -anchor e -pady 2
366 entry-fields $w.top {database} \
368 {database-select-action} {destroy .database-select}
371 frame $w.bot.left -relief sunken -border 1
372 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
373 button $w.bot.left.ok -width 6 -text {Ok} \
374 -command {protocol-setup-action}
375 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
376 button $w.bot.cancel -width 6 -text {Cancel} \
377 -command "destroy .database-select"
378 pack $w.bot.cancel -side left -expand yes
386 proc save-settings {} {
389 set f [open "~/.tk-c" w]
390 puts $f "# Setup file"
391 puts $f "set hotTargets \{ $hotTargets \}"
395 frame .top -border 1 -relief raised
396 frame .mid -border 1 -relief raised
397 frame .data -border 1 -relief raised
398 frame .bot -border 1 -relief raised
399 pack .top .mid -side top -fill x
400 pack .data -side top -fill both -expand yes
403 menubutton .top.file -text "File" -menu .top.file.m
405 .top.file.m add command -label "Save settings" -command {save-settings}
406 .top.file.m add command -label "Exit" -command {destroy .}
408 menubutton .top.target -text "Target" -menu .top.target.m
410 .top.target.m add command -label "Connect" -command {open-target-dialog}
411 .top.target.m add command -label "Disconnect" -command {close-target}
412 .top.target.m add command -label "Initialize" -command {init-request}
413 .top.target.m add command -label "Setup" -command {protocol-setup}
414 .top.target.m add separator
417 menubutton .top.database -text "Database" -menu .top.database.m
419 .top.database.m add command -label "Select ..." -command {database-select}
420 .top.database.m add command -label "Add ..." -command {puts "Add"}
422 menubutton .top.help -text "Help" -menu .top.help.m
424 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
425 .top.help.m add command -label "About" -command {puts "About"}
427 pack .top.file .top.target .top.database -side left
428 pack .top.help -side right
430 label .mid.searchlabel -text {Search:}
431 entry .mid.searchentry -width 50 -relief sunken
433 listbox .data.list -yscrollcommand {.data.scroll set}
435 scrollbar .data.scroll -orient vertical -border 1
436 pack .data.list -side left -fill both -expand yes
437 pack .data.scroll -side right -fill y
438 .data.scroll config -command {.data.list yview}
440 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
441 label .bot.status -text "Not connected" -width 12 -relief \
442 sunken -anchor w -border 1
443 label .bot.message -text "" -width 20 -relief \
444 sunken -anchor w -border 1
445 pack .bot.target .bot.status .bot.message -anchor nw -side left -padx 2 -pady 2
447 for {set i 0} {$i < 30} {incr i} {
448 .data.list insert end "Record $i"
451 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
452 puts "y=%y index $indx" }
456 set csRadioType [z39 comstack]