| 43 | import string |
| 44 | |
| 45 | def main(): |
| 46 | # Make variables global, my choice... ;o) |
| 47 | global delay |
| 48 | global text |
| 49 | global ascii_num |
| 50 | global dah_dit |
| 51 | global morse_code |
| 52 | global count |
| 53 | |
| 54 | # Allocate start values... |
| 55 | delay=225 |
| 56 | text="(C)2010-2012, B.Walker, G0LCU..." |
| 57 | ascii_num=63 |
| 58 | dah_dit=0 |
| 59 | # The code below is the "?" character for any unknown character entered. |
| 60 | morse_code="..--.." |
| 61 | count=0 |
| 62 | |
| 63 | while 1: |
| 64 | # Enter a simple loop... |
| 65 | # A basic ?nix type screen clear command... |
| 66 | count=os.system("clear") |
| 67 | # A simple user screen, QUIT or EXIT<RETURN/ENTER> to STOP... |
| 68 | print "\nA simple Morse Code Generator and tutor.\n" |
| 69 | print "(C)2010-2012, B.Walker, G0LCU.\n" |
| 70 | print "It has a fixed speed of around 8 words per minute...\n" |
| 71 | text=raw_input("Press <RETURN/ENTER> to continue:- ") |
| 72 | text=string.upper(text) |
| 73 | if text=="QUIT" or text=="EXIT": break |
| 74 | # Don't allow any errors. |
| 75 | if len(text)>=2: text="" |
| 76 | if text=="": ascii_num=int(random.random()*43)+48 |
| 77 | if text!="": ascii_num=ord(text) |
| 78 | # This is the "?" character... |
| 79 | if ascii_num>=58 and ascii_num<=64: |
| 80 | morse_code="..--.." |
| 81 | ascii_num=63 |
| 82 | if ascii_num<=47 or ascii_num>=91: |
| 83 | morse_code="..--.." |
| 84 | ascii_num=63 |
| 85 | # Now to generate the relevant code according to the correct ASCII |
| 86 | # character entered. |
| 87 | if ascii_num==48: morse_code="-----" |
| 88 | if ascii_num==49: morse_code=".----" |
| 89 | if ascii_num==50: morse_code="..---" |
| 90 | if ascii_num==51: morse_code="...--" |
| 91 | if ascii_num==52: morse_code="....-" |
| 92 | if ascii_num==53: morse_code="....." |
| 93 | if ascii_num==54: morse_code="-...." |
| 94 | if ascii_num==55: morse_code="--..." |
| 95 | if ascii_num==56: morse_code="---.." |
| 96 | if ascii_num==57: morse_code="----." |
| 97 | if ascii_num==65: morse_code=".-" |
| 98 | if ascii_num==66: morse_code="-..." |
| 99 | if ascii_num==67: morse_code="-.-." |
| 100 | if ascii_num==68: morse_code="-.." |
| 101 | if ascii_num==69: morse_code="." |
| 102 | if ascii_num==70: morse_code="..-." |