3 # Revision 1.24 1995-05-31 08:36:24 adam
4 # Bug fix in client.tcl: didn't save options on clientrc.tcl.
5 # New method: referenceId. More work on scan.
7 # Revision 1.23 1995/05/29 10:33:41 adam
8 # README and rename of startup script.
10 # Revision 1.22 1995/05/26 11:44:09 adam
11 # Bugs fixed. More work on MARC utilities and queries. Test
12 # client is up-to-date again.
14 # Revision 1.21 1995/05/11 15:34:46 adam
15 # Scan request changed a bit. This version works with RLG.
17 # Revision 1.20 1995/04/21 16:31:57 adam
18 # New radiobutton: protocol (z39v2/SR).
20 # Revision 1.19 1995/04/18 16:11:50 adam
21 # First version of graphical Scan. Some work on query-by-form.
23 # Revision 1.18 1995/04/10 10:50:22 adam
24 # Result-set name defaults to suffix of ir-set name.
25 # Started working on scan. Not finished at this point.
27 # Revision 1.17 1995/03/31 09:34:57 adam
28 # Search-button disabled when there is no connection.
30 # Revision 1.16 1995/03/31 08:56:36 adam
31 # New button "Search".
33 # Revision 1.15 1995/03/28 12:45:22 adam
34 # New ir method failback: called on disconnect/protocol error.
35 # New ir set/get method: protocol: SR / Z3950.
36 # Simple popup and disconnect when failback is invoked.
38 # Revision 1.14 1995/03/22 16:07:55 adam
41 # Revision 1.13 1995/03/21 17:27:26 adam
42 # Short-hand keys in setup.
44 # Revision 1.12 1995/03/21 13:41:03 adam
45 # Comstack cs_create not used too often. Non-blocking connect.
47 # Revision 1.11 1995/03/21 10:39:06 adam
48 # Diagnostic error message displayed with tkerror.
50 # Revision 1.10 1995/03/20 15:24:06 adam
51 # Diagnostic records saved on searchResponse.
53 # Revision 1.9 1995/03/17 18:26:16 adam
54 # Non-blocking i/o used now. Database names popup as cascade items.
56 # Revision 1.8 1995/03/17 15:45:00 adam
57 # Improved target/database setup.
59 # Revision 1.7 1995/03/16 17:54:03 adam
60 # Minor changes really.
62 # Revision 1.6 1995/03/15 19:10:20 adam
63 # Database setup in protocol-setup (rather target setup).
65 # Revision 1.5 1995/03/15 13:59:23 adam
68 # Revision 1.4 1995/03/14 17:32:29 adam
69 # Presentation of full Marc record in popup window.
71 # Revision 1.3 1995/03/12 19:31:52 adam
72 # Pattern matching implemented when retrieving MARC records. More
73 # diagnostic functions.
75 # Revision 1.2 1995/03/10 18:00:15 adam
76 # Actual presentation in line-by-line format. RPN query support.
78 # Revision 1.1 1995/03/09 16:15:07 adam
79 # First presentRequest attempts. Hot-target list.
86 set profile(Default) {{} {} {210} {} 16384 8192 tcpip {} 1 {} {} z39v2}
91 set queryTypes {Simple}
92 set queryButtons { { {I 0} {I 1} {I 2} } }
93 set queryInfo { { {Title {1=4}} {Author {1=1}} \
94 {Subject {1=21}} {Any {1=1016}} } }
98 if {[file readable "clientrc.tcl"]} {
102 set queryButtonsFind [lindex $queryButtons 0]
103 set queryInfoFind [lindex $queryInfo 0]
105 proc top-down-window {w} {
106 frame $w.top -relief raised -border 1
107 frame $w.bot -relief raised -border 1
109 pack $w.top -side top -fill both -expand yes
110 pack $w.bot -fill both
113 proc top-down-ok-cancel {w ok-action g} {
114 frame $w.bot.left -relief sunken -border 1
115 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
116 button $w.bot.left.ok -width 6 -text {Ok} \
117 -command ${ok-action}
118 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
119 button $w.bot.cancel -width 6 -text {Cancel} \
120 -command "destroy $w"
121 pack $w.bot.cancel -side left -expand yes
130 proc top-down-ok-cancelx {w buttonList g} {
132 set l [llength $buttonList]
134 frame $w.bot.$i -relief sunken -border 1
135 pack $w.bot.$i -side left -expand yes -padx 5 -pady 5
136 button $w.bot.$i.ok -text [lindex $buttonList $i] \
137 -command [lindex $buttonList [expr $i+1]]
138 pack $w.bot.$i.ok -expand yes -padx 3 -pady 3 -side left
142 button $w.bot.$i -text [lindex $buttonList $i] \
143 -command [lindex $buttonList [expr $i+1]]
144 pack $w.bot.$i -expand yes -padx 3 -pady 3 -side left
147 button $w.bot.cancel -width 6 -text {Cancel} \
148 -command "destroy $w"
149 pack $w.bot.cancel -side left -expand yes
158 proc show-target {target} {
159 .bot.target configure -text "$target"
162 proc show-busy {v1 v2} {
165 .bot.status configure -fg $v1
166 after 200 [list show-busy $v2 $v1]
170 proc show-status {status b} {
173 .bot.status configure -text "$status"
174 .bot.status configure -fg black
180 # . config -cursor {watch black white}
182 # . config -cursor {top_left_arrow black white}
188 proc show-message {msg} {
189 .bot.message configure -text "$msg"
192 proc insertWithTags {w text args} {
193 set start [$w index insert]
194 $w insert insert $text
195 foreach tag [$w tag names $start] {
196 $w tag remove $tag $start insert
199 $w tag add $i $start insert
203 proc show-full-marc {no} {
208 if {[winfo exists $w]} {
209 $w.top.record delete 0.0 end
215 wm minsize $w 200 200
217 frame $w.top -relief raised -border 1
218 frame $w.bot -relief raised -border 1
220 pack $w.top -side top -fill both -expand yes
221 pack $w.bot -fill both
223 text $w.top.record -width 60 -height 12 -wrap word \
224 -yscrollcommand [list $w.top.s set]
225 scrollbar $w.top.s -command [list $w.top.record yview]
231 set r [z39.$setNo getMarc $no list * * *]
233 $w.top.record tag configure marc-tag -foreground blue
234 $w.top.record tag configure marc-data -foreground black
235 $w.top.record tag configure marc-id -foreground red
238 set tag [lindex $line 0]
239 set indicator [lindex $line 1]
240 set fields [lindex $line 2]
242 if {$indicator != ""} {
243 insertWithTags $w.top.record "$tag $indicator" marc-tag
245 insertWithTags $w.top.record "$tag " marc-tag
247 foreach field $fields {
248 set id [lindex $field 0]
249 set data [lindex $field 1]
251 insertWithTags $w.top.record " $id " marc-id
253 set start [$w.top.record index insert]
254 insertWithTags $w.top.record $data {}
256 $w.top.record insert end "\n"
259 bind $w <Return> {destroy .full-marc}
261 pack $w.top.s -side right -fill y
262 pack $w.top.record -expand yes -fill both
264 frame $w.bot.left -relief sunken -border 1
265 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
266 button $w.bot.left.close -width 6 -text {Close} \
267 -command {destroy .full-marc}
268 pack $w.bot.left.close -expand yes -padx 3 -pady 3
269 button $w.bot.edit -width 6 -text {Edit} \
270 -command {destroy .full-marc}
271 pack $w.bot.edit -side left -expand yes
275 proc update-target-hotlist {target} {
278 set len [llength $hotTargets]
280 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
282 set indx [lsearch $hotTargets $target]
284 set hotTargets [lreplace $hotTargets $indx $indx]
286 set hotTargets [linsert $hotTargets 0 $target]
290 proc set-target-hotlist {} {
294 foreach target $hotTargets {
295 .top.target.m add command -label "$i $target" -command \
296 "reopen-target $target {}"
304 proc reopen-target {target base} {
306 open-target $target $base
307 update-target-hotlist $target
310 proc define-target-action {} {
313 set target [.target-define.top.target.entry get]
317 update-target-hotlist $target
318 foreach n [array names profile] {
324 set profile($target) $profile(Default)
325 protocol-setup $target
326 destroy .target-define
329 proc fail-response {target} {
331 tkerror "Target connection closed or protocol error"
334 proc connect-response {target} {
335 puts "connect-response"
340 proc open-target {target base} {
345 z39 comstack [lindex $profile($target) 6]
346 z39 idAuthentication [lindex $profile($target) 3]
347 z39 maximumRecordSize [lindex $profile($target) 4]
348 z39 preferredMessageSize [lindex $profile($target) 5]
349 puts -nonewline "maximumRecordSize="
350 puts [z39 maximumRecordSize]
351 puts -nonewline "preferredMessageSize="
352 puts [z39 preferredMessageSize]
354 z39 databaseNames [lindex [lindex $profile($target) 7] 0]
356 z39 databaseNames $base
358 z39 failback [list fail-response $target]
359 z39 callback [list connect-response $target]
360 z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
361 show-status {Connecting} 1
363 .top.target.m disable 0
364 .top.target.m enable 1
367 proc close-target {} {
373 show-status {Not connected} 0
375 .top.target.m disable 1
376 .top.target.m enable 0
377 .top.search configure -state disabled
378 .mid.search configure -state disabled
379 .mid.scan configure -state disabled
382 proc load-set-action {} {
386 ir-set z39.$setNo z39
388 set fname [.load-set.top.filename.entry get]
393 show-status {Loading} 1
394 z39.$setNo loadFile $fname
396 set no [z39.$setNo numberOfRecordsReturned]
397 add-title-lines $setNo $no 1
399 show-status {Ready} 0
412 frame $w.top.filename
414 pack $w.top.filename -side top -anchor e -pady 2
416 entry-fields $w.top {filename} \
418 {load-set-action} {destroy .load-set}
420 top-down-ok-cancel $w {load-set-action} 1
424 proc init-request {} {
427 z39 callback {init-response}
429 show-status {Initializing} 1
432 proc init-response {} {
433 show-status {Ready} 0
434 .top.search configure -state normal
435 .mid.search configure -state normal
436 .mid.scan configure -state normal
437 if {![z39 initResult]} {
438 set u [z39 userInformationField]
440 tkerror "Connection rejected by target: $u"
444 proc search-request {} {
451 set query [index-query]
456 ir-set z39.$setNo z39
458 if {[lindex $profile($target) 10] == 1} {
459 z39.$setNo setName $setNo
460 puts "setName=${setNo}"
462 z39.$setNo setName Default
463 puts "setName=Default"
465 if {[lindex $profile($target) 8] == 1} {
466 z39.$setNo queryType rpn
468 if {[lindex $profile($target) 9] == 1} {
469 z39.$setNo queryType ccl
471 z39 callback {search-response}
472 z39.$setNo search $query
473 show-status {Search} 1
476 proc scan-request {} {
486 z39 callback {scan-response}
487 if {![winfo exists $w]} {
492 wm minsize $w 200 200
496 listbox $w.top.list -yscrollcommand [list $w.top.scroll set] \
497 -font fixed -geometry 50x14
498 scrollbar $w.top.scroll -orient vertical -border 1
499 pack $w.top.list -side left -fill both -expand yes
500 pack $w.top.scroll -side right -fill y
501 $w.top.scroll config -command [list $w.top.list yview]
503 top-down-ok-cancelx $w [list {Close} [list destroy $w]] 0
505 z39.scan numberOfTermsRequested 100
506 z39.scan scan "@attr 1=4 0"
511 proc scan-response {} {
513 set m [z39.scan numberOfEntriesReturned]
515 for {set i 0} {$i < $m} {incr i} {
516 set term [lindex [z39.scan scanLine $i] 1]
517 set nostr [format "%7d" [lindex [z39.scan scanLine $i] 2]]
519 $w.top.list insert end "$nostr $term"
521 show-status {Ready} 0
524 proc search-response {} {
530 show-status {Ready} 0
531 show-message "[z39.$setNo resultCount] hits"
532 set setMax [z39.$setNo resultCount]
535 set status [z39.$setNo responseStatus]
536 if {[lindex $status 0] == "NSD"} {
537 set code [lindex $status 1]
538 set msg [lindex $status 2]
539 set addinfo [lindex $status 3]
540 tkerror "NSD$code: $msg: $addinfo"
547 z39 callback {present-response}
549 z39.$setNo present $setOffset $setMax
550 show-status {Retrieve} 1
553 proc present-more {number} {
562 set max [z39.$setNo resultCount]
563 if {$max <= $setMax} {
567 puts "setOffset=$setOffset"
573 z39 callback {present-response}
574 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
575 show-status {Retrieve} 1
578 proc init-title-lines {} {
579 .data.list delete 0 end
582 proc add-title-lines {setno no offset} {
583 for {set i 0} {$i < $no} {incr i} {
584 set o [expr $i + $offset]
585 set title [lindex [z39.$setno getMarc $o field 245 * a] 0]
586 set year [lindex [z39.$setno getMarc $o field 260 * c] 0]
587 set nostr [format "%5d" $o]
588 .data.list insert end "$nostr $title - $year"
592 proc present-response {} {
597 puts "In present-response"
598 set no [z39.$setNo numberOfRecordsReturned]
599 puts "Returned $no records, setOffset $setOffset"
600 add-title-lines $setNo $no $setOffset
601 set setOffset [expr $setOffset + $no]
602 set status [z39.$setNo responseStatus]
603 if {[lindex $status 0] == "NSD"} {
604 show-status {Ready} 0
605 set code [lindex $status 1]
606 set msg [lindex $status 2]
607 set addinfo [lindex $status 3]
608 tkerror "NSD$code: $msg: $addinfo"
611 if {$no > 0 && $setOffset <= $setMax} {
612 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
614 show-status {Finished} 0
618 proc left-cursor {w} {
619 set i [$w index insert]
626 proc right-cursor {w} {
627 set i [$w index insert]
632 proc bind-fields {list returnAction escapeAction} {
633 set max [expr [llength $list]-1]
634 for {set i 0} {$i < $max} {incr i} {
635 bind [lindex $list $i] <Return> $returnAction
636 bind [lindex $list $i] <Escape> $escapeAction
637 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
638 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
639 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
641 bind [lindex $list $i] <Return> $returnAction
642 bind [lindex $list $i] <Escape> $escapeAction
643 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
644 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
645 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
646 focus [lindex $list 0]
649 proc entry-fields {parent list tlist returnAction escapeAction} {
652 foreach field $list {
653 set label ${parent}.${field}.label
654 set entry ${parent}.${field}.entry
655 label $label -text [lindex $tlist $i] -anchor e
656 entry $entry -width 32 -relief sunken
657 pack $label -side left
658 pack $entry -side right
662 bind-fields $alist $returnAction $escapeAction
665 proc define-target-dialog {} {
673 -side top -anchor e -pady 2
674 entry-fields $w.top {target} \
676 {define-target-action} {destroy .target-define}
677 top-down-ok-cancel $w {define-target-action} 1
680 proc protocol-setup-action {target} {
683 global protocolRadioType
684 global settingsChanged
687 global ResultSetCheck
689 set w .setup-${target}.top
691 #set w .protocol-setup.top
694 set settingsChanged 1
695 set len [$w.databases.list size]
696 for {set i 0} {$i < $len} {incr i} {
697 lappend b [$w.databases.list get $i]
699 set profile($target) [list [$w.description.entry get] \
700 [$w.host.entry get] \
701 [$w.port.entry get] \
702 [$w.idAuthentication.entry get] \
703 [$w.maximumRecordSize.entry get] \
704 [$w.preferredMessageSize.entry get] \
713 puts $profile($target)
714 destroy .setup-${target}
717 proc place-force {window parent} {
718 set g [wm geometry $parent]
720 set p1 [string first + $g]
721 set p2 [string last + $g]
723 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
724 set y [expr 60+[string range $g [expr $p2 +1] end]]
725 wm geometry $window +${x}+${y}
728 proc add-database-action {target} {
729 set w .setup-${target}
731 ${w}.top.databases.list insert end \
732 [.database-select.top.database.entry get]
733 destroy .database-select
736 proc add-database {target} {
737 set w .database-select
742 place-force $w .setup-${target}
746 frame $w.top.database
748 pack $w.top.database -side top -anchor e -pady 2
750 entry-fields $w.top {database} \
751 {{Database to add:}} \
752 [list add-database-action $target] {destroy .database-select}
754 top-down-ok-cancel $w [list add-database-action $target] 1
758 proc delete-database {target} {
759 set w .setup-${target}
761 foreach i [lsort -decreasing \
762 [$w.top.databases.list curselection]] {
763 $w.top.databases.list delete $i
767 proc protocol-setup {target} {
772 global protocolRadioType
775 global ResultSetCheck
779 wm title $w "Setup $target"
788 puts $profile($target)
792 frame $w.top.description
793 frame $w.top.idAuthentication
794 frame $w.top.maximumRecordSize
795 frame $w.top.preferredMessageSize
796 frame $w.top.cs-type -relief ridge -border 2
797 frame $w.top.protocol -relief ridge -border 2
798 frame $w.top.query -relief ridge -border 2
799 frame $w.top.databases -relief ridge -border 2
801 # Maximum/preferred/idAuth ...
802 pack $w.top.description $w.top.host $w.top.port \
803 $w.top.idAuthentication $w.top.maximumRecordSize \
804 $w.top.preferredMessageSize -side top -anchor e -pady 2
806 entry-fields $w.top {description host port idAuthentication \
807 maximumRecordSize preferredMessageSize} \
808 {{Description:} {Host:} {Port:} {Id Authentication:} \
809 {Maximum Record Size:} {Preferred Message Size:}} \
810 [list protocol-setup-action $target] [list destroy $w]
812 foreach sub {description host port idAuthentication \
813 maximumRecordSize preferredMessageSize} {
815 bind $w.top.$sub.entry <Control-a> "add-database $target"
816 bind $w.top.$sub.entry <Control-d> "delete-database $target"
818 $w.top.description.entry insert 0 [lindex $profile($target) 0]
819 $w.top.host.entry insert 0 [lindex $profile($target) 1]
820 $w.top.port.entry insert 0 [lindex $profile($target) 2]
821 $w.top.idAuthentication.entry insert 0 [lindex $profile($target) 3]
822 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($target) 4]
823 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($target) 5]
824 set csRadioType [lindex $profile($target) 6]
825 set RPNCheck [lindex $profile($target) 8]
826 set CCLCheck [lindex $profile($target) 9]
827 set ResultSetCheck [lindex $profile($target) 10]
828 set protocolRadioType [lindex $profile($target) 11]
829 if {$protocolRadioType == ""} {
830 set protocolRadioType z39v2
834 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill both
836 label $w.top.databases.label -text "Databases"
837 button $w.top.databases.add -text "Add" \
838 -command "add-database $target"
839 button $w.top.databases.delete -text "Delete" \
840 -command "delete-database $target"
841 listbox $w.top.databases.list -geometry 20x6 \
842 -yscrollcommand "$w.top.databases.scroll set"
843 scrollbar $w.top.databases.scroll -orient vertical -border 1
844 pack $w.top.databases.label -side top -fill x \
846 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
848 pack $w.top.databases.list -side left -fill both -expand yes \
850 pack $w.top.databases.scroll -side right -fill y \
852 $w.top.databases.scroll config -command "$w.top.databases.list yview"
854 foreach b [lindex $profile($target) 7] {
855 $w.top.databases.list insert end $b
859 pack $w.top.cs-type -pady 6 -padx 6 -side top -fill x
861 label $w.top.cs-type.label -text "Transport"
862 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" -anchor w \
863 -command {puts tcp/ip} -variable csRadioType -value tcpip
864 radiobutton $w.top.cs-type.mosi -text "MOSI" -anchor w\
865 -command {puts mosi} -variable csRadioType -value mosi
867 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
868 -padx 4 -side top -fill x
871 pack $w.top.protocol -pady 6 -padx 6 -side top -fill x
873 label $w.top.protocol.label -text "Protocol"
874 radiobutton $w.top.protocol.z39v2 -text "Z39.50" -anchor w \
875 -command {puts z39v2} -variable protocolRadioType -value z39v2
876 radiobutton $w.top.protocol.sr -text "SR" -anchor w \
877 -command {puts sr} -variable protocolRadioType -value sr
879 pack $w.top.protocol.label $w.top.protocol.z39v2 $w.top.protocol.sr \
880 -padx 4 -side top -fill x
883 pack $w.top.query -pady 6 -padx 6 -side top -fill x
885 label $w.top.query.label -text "Query support"
886 checkbutton $w.top.query.c1 -text "RPN query" -anchor w -variable RPNCheck
887 checkbutton $w.top.query.c2 -text "CCL query" -anchor w -variable CCLCheck
888 checkbutton $w.top.query.c3 -text "Result sets" -anchor w -variable ResultSetCheck
890 pack $w.top.query.label -side top
891 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
892 -padx 4 -side top -fill x
895 top-down-ok-cancel $w [list protocol-setup-action $target] 0
898 proc database-select-action {} {
899 set w .database-select.top
901 foreach indx [$w.databases.list curselection] {
902 lappend b [$w.databases.list get $indx]
907 destroy .database-select
910 proc database-select {} {
911 set w .database-select
921 frame $w.top.databases -relief ridge -border 2
923 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
925 label $w.top.databases.label -text "List"
926 listbox $w.top.databases.list -geometry 20x6 \
927 -yscrollcommand "$w.top.databases.scroll set"
928 scrollbar $w.top.databases.scroll -orient vertical -border 1
929 pack $w.top.databases.label -side top -fill x \
931 pack $w.top.databases.list -side left -fill both -expand yes \
933 pack $w.top.databases.scroll -side right -fill y \
935 $w.top.databases.scroll config -command "$w.top.databases.list yview"
937 foreach b [lindex $profile($hostid) 7] {
938 $w.top.databases.list insert end $b
940 top-down-ok-cancel $w {database-select-action} 1
943 proc cascade-target-list {} {
946 foreach sub [winfo children .top.target.m.clist] {
950 .top.target.m.clist delete 0 last
951 foreach n [array names profile] {
952 if {$n != "Default"} {
953 set nl [string tolower $n]
954 if {[llength [lindex $profile($n) 7]] > 1} {
955 .top.target.m.clist add cascade -label $n \
956 -menu .top.target.m.clist.$nl
957 menu .top.target.m.clist.$nl
958 foreach b [lindex $profile($n) 7] {
959 .top.target.m.clist.$nl add command -label $b \
960 -command "reopen-target $n $b"
963 .top.target.m.clist add command -label $n \
964 -command "reopen-target $n {}"
968 .top.target.m.slist delete 0 last
969 foreach n [array names profile] {
970 if {$n != "Default"} {
971 .top.target.m.slist add command -label $n \
972 -command "protocol-setup $n"
977 proc cascade-query-list {} {
981 .top.query.m.slist delete 0 last
982 foreach n $queryTypes {
983 .top.query.m.slist add command -label $n \
984 -command [list query-setup $i]
989 .top.query.m.clist delete 0 last
990 foreach n $queryTypes {
991 .top.query.m.clist add command -label $n \
992 -command [list query-select $i]
997 proc save-settings {} {
1000 global settingsChanged
1005 set f [open "clientrc.tcl" w]
1006 puts $f "# Setup file"
1007 puts $f "set hotTargets \{ $hotTargets \}"
1009 foreach n [array names profile] {
1010 puts -nonewline $f "set profile($n) \{"
1011 puts -nonewline $f $profile($n)
1014 puts -nonewline $f "set queryTypes \{"
1015 puts -nonewline $f $queryTypes
1018 puts -nonewline $f "set queryButtons \{"
1019 puts -nonewline $f $queryButtons
1022 puts -nonewline $f "set queryInfo \{"
1023 puts -nonewline $f $queryInfo
1027 set settingsChanged 0
1039 message $w.top.message -text $ask
1041 pack $w.top.message -side left -pady 6 -padx 20 -expand yes -fill x
1044 top-down-ok-cancel $w {alert-action} 1
1048 proc alert-action {} {
1054 proc exit-action {} {
1055 global settingsChanged
1057 if {$settingsChanged} {
1058 set a [alert "you havent saved your settings. Do you wish to save?"]
1066 proc listbuttonaction {w name h user i} {
1067 $w configure -text [lindex $name 0]
1068 $h [lindex $name 1] $user $i
1071 proc listbuttonx {button no names handle user} {
1072 if {[winfo exists $button]} {
1073 $button configure -text [lindex [lindex $names $no] 0]
1074 ${button}.m delete 0 last
1076 menubutton $button -text [lindex [lindex $names $no] 0] \
1077 -width 10 -menu ${button}.m -relief raised -border 1
1081 foreach name $names {
1082 ${button}.m add command -label [lindex $name 0] \
1083 -command [list listbuttonaction ${button} $name \
1089 proc listbutton {button no names} {
1090 menubutton $button -text [lindex $names $no] -width 10 -menu ${button}.m \
1091 -relief raised -border 1
1093 foreach name $names {
1094 ${button}.m add command -label $name \
1095 -command [list ${button} configure -text $name]
1099 proc query-add-index-action {queryNo} {
1100 set w .setup-query-$queryNo
1103 global queryButtonsTmp
1105 lappend queryInfoTmp [list [.query-add-index.top.index.entry get] {}]
1107 destroy .query-add-index
1108 #destroy $w.top.lines
1109 #frame $w.top.lines -relief ridge -border 2
1110 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
1111 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
1114 proc query-add-line {queryNo} {
1115 set w .setup-query-$queryNo
1118 global queryButtonsTmp
1120 lappend queryButtonsTmp {I 0}
1122 #destroy $w.top.lines
1123 #frame $w.top.lines -relief ridge -border 2
1124 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
1125 #pack $w.top.lines -side left -pady 6 -padx 6 -fill y
1128 proc query-del-line {queryNo} {
1129 set w .setup-query-$queryNo
1132 global queryButtonsTmp
1134 set l [llength $queryButtonsTmp]
1139 set queryButtonsTmp [lreplace $queryButtonsTmp $l $l]
1140 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
1143 proc query-add-index {queryNo} {
1144 set w .query-add-index
1147 place-force $w .setup-query-$queryNo
1151 -side top -anchor e -pady 2
1152 entry-fields $w.top {index} \
1154 [list query-add-index-action $queryNo] {destroy .query-add-index}
1155 top-down-ok-cancel $w [list query-add-index-action $queryNo] 1
1158 proc query-setup-action {queryNo} {
1161 global queryButtonsTmp
1163 global queryButtonsFind
1164 global queryInfoFind
1166 set queryInfo [lreplace $queryInfo $queryNo $queryNo \
1168 set queryButtons [lreplace $queryButtons $queryNo $queryNo \
1170 set queryInfoFind $queryInfoTmp
1171 set queryButtonsFind $queryButtonsTmp
1175 destroy .setup-query-$queryNo
1177 index-lines .lines 1 $queryButtonsFind $queryInfoFind activate-index
1180 proc activate-e-index {value no i} {
1181 global queryButtonsTmp
1183 puts $queryButtonsTmp
1184 set queryButtonsTmp [lreplace $queryButtonsTmp $no $no [list I $i]]
1185 puts $queryButtonsTmp
1191 proc activate-index {value no i} {
1192 global queryButtonsFind
1194 set queryButtonsFind [lreplace $queryButtonsFind $no $no [list I $i]]
1196 puts "queryButtonsFind $queryButtonsFind"
1202 proc query-setup {queryNo} {
1203 set w .setup-query-$queryNo
1205 set queryTypes {Simple}
1208 global queryButtonsTmp
1211 set queryName [lindex $queryTypes $queryNo]
1212 set queryInfoTmp [lindex $queryInfo $queryNo]
1213 set queryButtonsTmp [lindex $queryButtons $queryNo]
1215 #set queryButtons { {I 0 I 1 I 2} }
1216 #set queryInfo { { {Title ti} {Author au} {Subject sh} } }
1220 wm title $w "Query setup $queryName"
1225 frame $w.top.lines -relief ridge -border 2
1226 frame $w.top.use -relief ridge -border 2
1227 frame $w.top.relation -relief ridge -border 2
1228 frame $w.top.position -relief ridge -border 2
1229 frame $w.top.structure -relief ridge -border 2
1230 frame $w.top.truncation -relief ridge -border 2
1231 frame $w.top.completeness -relief ridge -border 2
1235 index-lines $w.top.lines 0 $queryButtonsTmp $queryInfoTmp activate-e-index
1237 pack $w.top.lines -side left -pady 6 -padx 6 -fill y
1240 pack $w.top.use -side left -pady 6 -padx 6 -fill y
1242 label $w.top.use.label -text "Use"
1243 listbox $w.top.use.list -geometry 20x10 \
1244 -yscrollcommand "$w.top.use.scroll set"
1245 scrollbar $w.top.use.scroll -orient vertical -border 1
1246 pack $w.top.use.label -side top -fill x \
1248 pack $w.top.use.list -side left -fill both -expand yes \
1250 pack $w.top.use.scroll -side right -fill y \
1252 $w.top.use.scroll config -command "$w.top.use.list yview"
1254 foreach u {{Personal name} {Corporate name}} {
1255 $w.top.use.list insert end $u
1257 # Relation Attributes
1258 pack $w.top.relation -pady 6 -padx 6 -side top
1260 label $w.top.relation.label -text "Relation" -width 18
1262 listbutton $w.top.relation.b 0\
1263 {{None} {Less than} {Greater than or equal} \
1264 {Equal} {Greater than or equal} {Greater than} {Not equal} \
1266 {Stem} {Relevance} {AlwaysMatches}}
1268 pack $w.top.relation.label $w.top.relation.b -fill x
1270 # Position Attributes
1271 pack $w.top.position -pady 6 -padx 6 -side top
1273 label $w.top.position.label -text "Position" -width 18
1275 listbutton $w.top.position.b 0 {{None} {First in field} {First in subfield}
1276 {Any position in field}}
1278 pack $w.top.position.label $w.top.position.b -fill x
1280 # Structure Attributes
1282 pack $w.top.structure -pady 6 -padx 6 -side top
1284 label $w.top.structure.label -text "Structure" -width 18
1286 listbutton $w.top.structure.b 0 {{None} {Phrase} {Word} {Key} {Year}
1287 {Date (norm)} {Word list} {Date (un-norm)} {Name (norm)} {Date (un-norm)}
1288 {Structure} {urx} {free-form} {doc-text} {local-number} {string}
1291 pack $w.top.structure.label $w.top.structure.b -fill x
1293 # Truncation Attributes
1295 pack $w.top.truncation -pady 6 -padx 6 -side top
1297 label $w.top.truncation.label -text "Truncation" -width 18
1299 listbutton $w.top.truncation.b 0 {{Auto} {Right} {Left} {Left and right} \
1300 {No truncation} {Process #} {Re-1} {Re-2}}
1301 pack $w.top.truncation.label $w.top.truncation.b -fill x
1303 # Completeness Attributes
1305 pack $w.top.completeness -pady 6 -padx 6 -side top
1307 label $w.top.completeness.label -text "Truncation" -width 18
1309 listbutton $w.top.completeness.b 0 {{None} {Incomplete subfield} \
1310 {Complete subfield} {Complete field}}
1311 pack $w.top.completeness.label $w.top.completeness.b -fill x
1314 top-down-ok-cancelx $w [list \
1315 {Ok} [list query-setup-action $queryNo] \
1316 {Add index} [list query-add-index $queryNo] \
1317 {Add line} [list query-add-line $queryNo] \
1318 {Delete line} [list query-del-line $queryNo]] 0
1321 proc index-clear {} {
1322 global queryButtonsFind
1325 foreach b $queryButtonsFind {
1326 .lines.$i.e delete 0 end
1331 proc index-query {} {
1332 global queryButtonsFind
1333 global queryInfoFind
1338 foreach b $queryButtonsFind {
1339 set term [string trim [.lines.$i.e get]]
1341 set attr [lindex [lindex $queryInfoFind [lindex $b 1]] 1]
1343 set term "\{${term}\}"
1345 set term "@attr $a ${term}"
1348 set qs "@and ${qs} ${term}"
1359 proc index-lines {w realOp buttonInfo queryInfo handle} {
1361 foreach b $buttonInfo {
1362 if {! [winfo exists $w.$i]} {
1363 frame $w.$i -background white -border 1
1365 listbuttonx $w.$i.l [lindex $b 1] $queryInfo $handle $i
1368 if {! [winfo exists $w.$i.e]} {
1369 entry $w.$i.e -width 32 -relief sunken -border 1
1370 bind $w.$i.e <FocusIn> [list $w.$i configure \
1372 bind $w.$i.e <FocusOut> [list $w.$i configure \
1374 pack $w.$i.l -side left
1375 pack $w.$i.e -side left -fill x -expand yes
1376 pack $w.$i -side top -fill x -padx 2 -pady 2
1377 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
1378 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
1379 bind $w.$i.e <Return> search-request
1382 pack $w.$i.l -side left
1383 pack $w.$i -side top -fill x -padx 2 -pady 2
1388 while {[winfo exists $w.$j]} {
1399 bind $w.$j.e <Tab> "focus $w.$k.e"
1403 bind $w.$i.e <Tab> "focus $w.0.e"
1408 proc search-fields {w buttondefs} {
1410 foreach buttondef $buttondefs {
1411 frame $w.$i -background white
1413 listbutton $w.$i.l 0 $buttondef
1414 entry $w.$i.e -width 32 -relief sunken
1416 pack $w.$i.l -side left
1417 pack $w.$i.e -side left -fill x -expand yes
1419 pack $w.$i -side top -fill x -padx 2 -pady 2
1421 bind $w.$i.e <Left> [list left-cursor $w.$i.e]
1422 bind $w.$i.e <Right> [list right-cursor $w.$i.e]
1430 bind $w.$j.e <Tab> "focus $w.$k.e \n
1431 $w.$k configure -background red \n
1432 $w.$j configure -background white"
1435 bind $w.$i.e <Tab> "focus $w.0.e \n
1436 $w.0 configure -background red \n
1437 $w.$i configure -background white"
1439 $w.0 configure -background red
1442 frame .top -border 1 -relief raised
1443 frame .lines -border 1 -relief raised
1444 frame .mid -border 1 -relief raised
1445 frame .data -border 1 -relief raised
1446 frame .bot -border 1 -relief raised
1447 pack .top .lines .mid -side top -fill x
1448 pack .data -side top -fill both -expand yes
1451 menubutton .top.file -text "File" -underline 0 -menu .top.file.m
1453 .top.file.m add command -label "Save settings" -command {save-settings}
1454 .top.file.m add command -label "Load Set" -command {load-set}
1455 .top.file.m add separator
1456 .top.file.m add command -label "Exit" -command {exit-action}
1458 menubutton .top.target -text "Target" -underline 0 -menu .top.target.m
1460 .top.target.m add cascade -label "Connect" -menu .top.target.m.clist
1461 .top.target.m add command -label "Disconnect" -command {close-target}
1462 #.top.target.m add command -label "Initialize" -command {init-request}
1463 .top.target.m add cascade -label "Setup" -menu .top.target.m.slist
1464 .top.target.m add command -label "Setup new" -command {define-target-dialog}
1465 .top.target.m add separator
1468 .top.target.m disable 1
1470 menu .top.target.m.clist
1471 menu .top.target.m.slist
1474 menubutton .top.search -text "Search" -underline 0 -menu .top.search.m
1476 .top.search.m add command -label "Database" -command {database-select}
1477 .top.search.m add cascade -label "Query type" -menu .top.search.m.querytype
1478 menu .top.search.m.querytype
1479 .top.search.m.querytype add radiobutton -label "RPN"
1480 .top.search.m.querytype add radiobutton -label "CCL"
1481 .top.search.m add cascade -label "Present" -menu .top.search.m.present
1482 menu .top.search.m.present
1483 .top.search.m.present add command -label "More" -command [list present-more 10]
1484 .top.search.m.present add command -label "All" -command [list present-more {}]
1485 .top.search configure -state disabled
1487 menubutton .top.query -text "Query" -underline 0 -menu .top.query.m
1489 .top.query.m add cascade -label "Choose" -menu .top.query.m.clist
1490 .top.query.m add command -label "Define" -command {new-query-dialog}
1491 .top.query.m add cascade -label "Edit" -menu .top.query.m.slist
1492 menu .top.query.m.clist
1493 menu .top.query.m.slist
1496 menubutton .top.help -text "Help" -menu .top.help.m
1499 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
1500 .top.help.m add command -label "About" -command {puts "About"}
1502 pack .top.file .top.target .top.query .top.search -side left
1503 pack .top.help -side right
1505 index-lines .lines 1 $queryButtonsFind [lindex $queryInfo 0] activate-index
1507 button .mid.search -width 6 -text {Search} -command search-request \
1509 button .mid.scan -width 6 -text {Scan} -command scan-request \
1511 button .mid.clear -width 6 -text {Clear} -command index-clear
1512 pack .mid.search .mid.scan .mid.clear -side left -padx 5 -pady 3
1514 listbox .data.list -yscrollcommand {.data.scroll set} -font fixed
1515 scrollbar .data.scroll -orient vertical -border 1
1516 pack .data.list -side left -fill both -expand yes
1517 pack .data.scroll -side right -fill y
1518 .data.scroll config -command {.data.list yview}
1520 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
1521 label .bot.status -text "Not connected" -width 12 -relief \
1522 sunken -anchor w -border 1
1523 label .bot.set -textvariable setNo -width 5 -relief \
1524 sunken -anchor w -border 1
1525 label .bot.message -text "" -width 14 -relief \
1526 sunken -anchor w -border 1
1527 pack .bot.target .bot.status .bot.set .bot.message -anchor nw \
1528 -side left -padx 2 -pady 2
1530 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
1531 show-full-marc $indx}