diff options
Diffstat (limited to 'Mac')
-rw-r--r-- | Mac/Demo/resources/copyres.py | 6 | ||||
-rw-r--r-- | Mac/Demo/sound/morselib.py | 40 |
2 files changed, 33 insertions, 13 deletions
diff --git a/Mac/Demo/resources/copyres.py b/Mac/Demo/resources/copyres.py index 528ff16..cb1fa8e 100644 --- a/Mac/Demo/resources/copyres.py +++ b/Mac/Demo/resources/copyres.py @@ -6,6 +6,12 @@ READ = 1 WRITE = 2 smAllScripts = -3 +def raw_input(prompt): + import sys + sys.stdout.write(prompt) + sys.stdout.flush() + return sys.stdin.readline() + def copyres(src, dst): """Copy resource from src file to dst file.""" diff --git a/Mac/Demo/sound/morselib.py b/Mac/Demo/sound/morselib.py index 98e2590..3c7493f 100644 --- a/Mac/Demo/sound/morselib.py +++ b/Mac/Demo/sound/morselib.py @@ -61,11 +61,10 @@ morsetab = { } def morsecode(s): - from string import lower m = '' for c in s: - c = lower(c) - if morsetab.has_key(c): + c = c.lower() + if c in morsetab: c = morsetab[c] + ' ' else: c = '? ' @@ -107,9 +106,12 @@ class BaseMorse: def sendmorse(self, s): for c in s: - if c == '.': self.dot() - elif c == '-': self.dah() - else: self.pdah() + if c == '.': + self.dot() + elif c == '-': + self.dah() + else: + self.pdah() self.pdot() def sendascii(self, s): @@ -122,8 +124,9 @@ class BaseMorse: import Audio_mac class MyAudio(Audio_mac.Play_Audio_mac): def _callback(self, *args): - if hasattr(self, 'usercallback'): self.usercallback() - apply(Audio_mac.Play_Audio_mac._callback, (self,) + args) + if hasattr(self, 'usercallback'): + self.usercallback() + Audio_mac.Play_Audio_mac._callback(self, args) class MacMorse(BaseMorse): @@ -169,12 +172,21 @@ class MacMorse(BaseMorse): def usercallback(self): if self.morsequeue: c, self.morsequeue = self.morsequeue[0], self.morsequeue[1:] - if c == '.': self.dot() - elif c == '-': self.dah() - else: self.pdah() + if c == '.': + self.dot() + elif c == '-': + self.dah() + else: + self.pdah() self.pdot() +def raw_input(prompt): + import sys + sys.stdout.write(prompt) + sys.stdout.flush() + return sys.stdin.readline() + def test(): m = MacMorse() while 1: @@ -183,6 +195,8 @@ def test(): except (EOFError, KeyboardInterrupt): break m.send(line) - while m.morsequeue: pass + while m.morsequeue: + pass -test() +if __name__ == '__main__': + test() |