cpython/Mac/Lib/test/ctbtest.py

51 lines
1.1 KiB
Python
Raw Normal View History

1995-03-07 12:40:18 -04:00
#
# Simple test program for ctb module: emulate a terminal.
# To simplify matters use the python console window for output.
1995-03-07 12:40:18 -04:00
#
import ctb
import Evt
import Events
import MacOS
1995-03-07 12:40:18 -04:00
import sys
def cb(err):
print 'Done, err=', err
def main():
if not ctb.available():
print 'Communications Toolbox not available'
sys.exit(1)
# Disable Python's event processing (we do that)
MacOS.EnableAppswitch(0)
1995-03-07 12:40:18 -04:00
print 'Minimal terminal emulator V1.0'
print '(type command-Q to exit)'
1995-03-07 12:40:18 -04:00
print
l = ctb.CMNew('Serial Tool', None)
l.Open(10)
l.SetConfig(l.GetConfig() + ' baud 4800')
1995-03-07 12:40:18 -04:00
while 1:
l.Idle() # Give time to ctb
ok, evt = Evt.WaitNextEvent(0xffff, 0)
if ok:
what, message, when, where, modifiers = evt
if what == Events.keyDown:
# It is ours. Check for command-. to terminate
ch = chr(message & Events.charCodeMask)
if ch == 'q' and (modifiers & Events.cmdKey):
break
l.Write(ch, ctb.cmData, -1, 0)
d, dummy = l.Read(1000, ctb.cmData, 1)
1995-03-07 12:40:18 -04:00
if d:
for ch in d:
if ch != '\r':
sys.stdout.write(ch)
sys.stdout.flush()
1995-03-07 12:40:18 -04:00
l.Close(-1, 1)
del l
1995-12-21 11:38:14 -04:00
main()