Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cb2554e

Browse files
committed
Still not a real test, but at least it runs again
1 parent 1801aad commit cb2554e

1 file changed

Lines changed: 26 additions & 17 deletions

File tree

Mac/Lib/test/ctbtest.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#
22
# Simple test program for ctb module: emulate a terminal.
3+
# To simplify matters use the python console window for output.
34
#
45
import ctb
5-
import macconsole
6+
import Evt
7+
import Events
8+
import MacOS
69
import sys
710

811
def cb(err):
@@ -12,29 +15,35 @@ def main():
1215
if not ctb.available():
1316
print 'Communications Toolbox not available'
1417
sys.exit(1)
15-
# c = macconsole.copen('Terminal window')
18+
# Disable Python's event processing (we do that)
19+
MacOS.EnableAppswitch(0)
1620
print 'Minimal terminal emulator V1.0'
17-
print '(type @ to exit)'
21+
print '(type command-Q to exit)'
1822
print
19-
c = macconsole.fopen(sys.stdin)
20-
f = sys.stdin
21-
c.setmode(macconsole.C_RAW)
2223

2324
l = ctb.CMNew('Serial Tool', None)
24-
l.Open(0)
25+
l.Open(10)
26+
l.SetConfig(l.GetConfig() + ' baud 4800')
2527

2628
while 1:
27-
l.Idle()
28-
d = f.read(1)
29-
if d == '@':
30-
break
31-
if d:
32-
l.Write(d, ctb.cmData, -1, 0)
33-
l.Idle()
34-
d, dummy = l.Read(1000, ctb.cmData, 0)
29+
l.Idle() # Give time to ctb
30+
31+
ok, evt = Evt.WaitNextEvent(0xffff, 0)
32+
if ok:
33+
what, message, when, where, modifiers = evt
34+
35+
if what == Events.keyDown:
36+
# It is ours. Check for command-. to terminate
37+
ch = chr(message & Events.charCodeMask)
38+
if ch == 'q' and (modifiers & Events.cmdKey):
39+
break
40+
l.Write(ch, ctb.cmData, -1, 0)
41+
d, dummy = l.Read(1000, ctb.cmData, 1)
3542
if d:
36-
f.write(d)
37-
f.flush()
43+
for ch in d:
44+
if ch != '\r':
45+
sys.stdout.write(ch)
46+
sys.stdout.flush()
3847
l.Close(-1, 1)
3948
del l
4049

0 commit comments

Comments
 (0)