blob: ebe468a85311bcb1e08a6665902c7d5ec7bda233 [file] [log] [blame]
Guido van Rossum74b3f8a1993-10-28 09:53:13 +00001# Interface to the interactive CWI library catalog.
2
3import sys
4import stdwin
5from stdwinevents import *
6import select
7import telnetlib
8import vt100win
9from form import Form
10
11
12# Main program
13
14def main():
Guido van Rossum74901d51993-11-01 14:50:59 +000015 vt = vt100win.VT100win()
16 #
17 host = 'biefstuk.cwi.nl'
18 tn = telnetlib.Telnet(host, 0)
19 #
20 try:
21 vt.send(tn.read_until('login: ', 10))
22 tn.write('cwilib\r')
Guido van Rossum74b3f8a1993-10-28 09:53:13 +000023 #
Guido van Rossum74901d51993-11-01 14:50:59 +000024 vt.send(tn.read_until('Hit <RETURN> to continue...', 10))
25 tn.write('\r')
Guido van Rossum74b3f8a1993-10-28 09:53:13 +000026 #
Guido van Rossum74901d51993-11-01 14:50:59 +000027 vt.send(tn.read_until('QUIT', 20))
28 except EOFError:
29 sys.stderr.write('Connection closed prematurely\n')
30 sys.exit(1)
31 #
32 define_screens(vt)
33 matches = vt.which_screens()
34 if 'menu' not in matches:
35 sys.stderr.write('Main menu does not appear\n')
36 sys.exit(1)
37 #
38 tn.write('\r\r')
39 vt.open('Progress -- CWI Library')
40 vt.set_debuglevel(0)
41 ui = UserInterface()
42 #
43 while 1:
Guido van Rossum74b3f8a1993-10-28 09:53:13 +000044 try:
Guido van Rossum74901d51993-11-01 14:50:59 +000045 data = tn.read_very_eager()
Guido van Rossum74b3f8a1993-10-28 09:53:13 +000046 except EOFError:
Guido van Rossum74901d51993-11-01 14:50:59 +000047 stdwin.message('Connection closed--goodbye')
48 break
49 if data:
50 print 'send...'
51 vt.send(data)
52 print 'send...done'
53 continue
54 event = stdwin.pollevent()
55 if event:
56 type, window, detail = event
57 if window == None and type == WE_LOST_SEL:
58 window = ui.queryform.window
59 event = type, window, detail
60 if type == WE_CLOSE:
61 break
62 if window in ui.windows:
63 ui.dispatch(type, window, detail)
64 elif window == vt.window:
65 if type == WE_NULL:
66 pass
67 elif type == WE_COMMAND:
68 if detail == WC_RETURN:
69 tn.write('\r')
70 elif detail == WC_BACKSPACE:
71 tn.write('\b')
72 elif detail == WC_TAB:
73 tn.write('\t')
74 elif detail == WC_UP:
75 tn.write('\033[A')
76 elif detail == WC_DOWN:
77 tn.write('\033[B')
78 elif detail == WC_RIGHT:
79 tn.write('\033[C')
80 elif detail == WC_LEFT:
81 tn.write('\033[D')
82 else:
83 print '*** Command:', detail
84 elif type == WE_CHAR:
85 tn.write(detail)
86 elif type == WE_DRAW:
87 vt.draw(detail)
88 elif type in (WE_ACTIVATE, WE_DEACTIVATE):
89 pass
Guido van Rossum74b3f8a1993-10-28 09:53:13 +000090 else:
Guido van Rossum74901d51993-11-01 14:50:59 +000091 print '*** VT100 event:', type, detail
92 else:
93 print '*** Alien event:', type, window, detail
94 continue
95 rfd, wfd, xfd = select.select([tn, stdwin], [], [])
Guido van Rossum74b3f8a1993-10-28 09:53:13 +000096
97
98# Subroutine to define our screen recognition patterns
99
100def define_screens(vt):
Guido van Rossum74901d51993-11-01 14:50:59 +0000101 vt.define_screen('menu', {
102 'title': ('search', 0, 0, 80,
103 ' SEARCH FUNCTIONS +OTHER FUNCTIONS '),
104 })
105 vt.define_screen('search', {
106 'title': ('search', 0, 0, 80, ' Search '),
107 })
108 vt.define_screen('shortlist', {'title': ('search', 0, 0, 80,
109 ' Short-list')})
110 vt.define_screen('showrecord', {
111 'title': ('search', 0, 0, 80, ' Show record '),
112 })
113 vt.define_screen('timelimit', {
114 'limit': ('search', 12, 0, 80, ' TIME LIMIT '),
115 })
116 vt.define_screen('attention', {
117 'BASE': ('copy', 0, 0, 0, 'search'),
118 'title': ('search', 10, 0, 80, ' ATTENTION ')})
119 vt.define_screen('syntaxerror', {
120 'BASE': ('copy', 0, 0, 0, 'attention'),
121 'message': ('search', 12, 0, 80, ' Syntax error'),
122 })
123 vt.define_screen('emptyerror', {
124 'BASE': ('copy', 0, 0, 0, 'attention'),
125 'message': ('search', 12, 0, 80,
126 ' Check your input. Search at least one term'),
127 })
128 vt.define_screen('unsortedwarning', {
129 'BASE': ('copy', 0, 0, 0, 'attention'),
130 'message': ('search', 12, 0, 80,
131 ' Number of records exceeds sort limit'),
132 })
133 vt.define_screen('thereismore', {
134 'BASE': ('copy', 0, 0, 0, 'showrecord'),
135 'message': ('search', 15, 0, 80,
136 'There is more within this record. Use the arrow keys'),
137 })
138 vt.define_screen('nofurther', {
139 'BASE': ('copy', 0, 0, 0, 'showrecord'),
140 'message': ('search', 17, 0, 80, 'You cannot go further\.'),
141 })
142 vt.define_screen('nofurtherback', {
143 'BASE': ('copy', 0, 0, 0, 'showrecord'),
144 'message': ('search', 17, 0, 80,
145 'You cannot go further back'),
146 })
Guido van Rossum74b3f8a1993-10-28 09:53:13 +0000147
148
149# Class to implement our user interface.
150
151class UserInterface:
152
Guido van Rossum74901d51993-11-01 14:50:59 +0000153 def __init__(self):
154 stdwin.setfont('7x14')
155 self.queryform = QueryForm()
156 self.listform = ListForm()
157 self.recordform = RecordForm()
158 self.forms = [self.queryform, self.listform, self.recordform]
159 define_query_fields(self.queryform)
160 self.windows = []
161 for form in self.forms:
162 if form.formheight > 0:
163 form.open()
164 self.windows.append(form.window)
Guido van Rossum74b3f8a1993-10-28 09:53:13 +0000165
Guido van Rossum74901d51993-11-01 14:50:59 +0000166 def __del__(self):
167 self.close()
Guido van Rossum74b3f8a1993-10-28 09:53:13 +0000168
Guido van Rossum74901d51993-11-01 14:50:59 +0000169 def close(self):
170 for form in self.forms:
171 form.close()
Guido van Rossum74b3f8a1993-10-28 09:53:13 +0000172
Guido van Rossum74901d51993-11-01 14:50:59 +0000173 def dispatch(self, type, window, detail):
174 for form in self.forms:
175 if window == form.window:
176 form.dispatch(type, detail)
Guido van Rossum74b3f8a1993-10-28 09:53:13 +0000177
178
179def define_query_fields(f):
Guido van Rossum74901d51993-11-01 14:50:59 +0000180 f.define_field('name', 'Name auth./ed.', 1, 60)
181 f.define_field('title', 'Title', 4, 60)
182 f.define_field('shelfmark', 'Shelf mark', 1, 60)
183 f.define_field('class', 'Prim. classif.', 1, 60)
184 f.define_field('series', 'Series', 1, 60)
185 f.define_field('congress', 'Congr. pl./year', 1, 60)
186 f.define_field('type', 'Type', 1, 60)
Guido van Rossum74b3f8a1993-10-28 09:53:13 +0000187
188
189class QueryForm(Form):
190
Guido van Rossum74901d51993-11-01 14:50:59 +0000191 def __init__(self):
192 Form.__init__(self, 'Query form -- CWI Library')
Guido van Rossum74b3f8a1993-10-28 09:53:13 +0000193
Guido van Rossum74901d51993-11-01 14:50:59 +0000194 def dispatch(self, type, detail):
195 if type == WE_COMMAND and detail == WC_RETURN:
196 print '*** SUBMIT ***'
197 else:
198 Form.dispatch(self, type, detail)
Guido van Rossum74b3f8a1993-10-28 09:53:13 +0000199
200
201class ListForm(Form):
202
Guido van Rossum74901d51993-11-01 14:50:59 +0000203 def __init__(self):
204 Form.__init__(self, 'Short list -- CWI Library')
Guido van Rossum74b3f8a1993-10-28 09:53:13 +0000205
206
207class RecordForm(Form):
208
Guido van Rossum74901d51993-11-01 14:50:59 +0000209 def __init__(self):
210 Form.__init__(self, 'Record detail -- CWI Library')
Guido van Rossum74b3f8a1993-10-28 09:53:13 +0000211
212
213main()