#!/usr/bin/env python3 from dial import DialManager, DialThread from hangup import HangUpThread from time import sleep from queue import Queue from threading import Event if __name__ == "__main__": queue = Queue() phone_held = Event() phone_hung_up = Event() # start phone as on hook phone_held.clear() phone_hung_up.set() dial_thread = DialThread(queue) dial_thread.start() dial_manager = DialManager(phone_held, phone_hung_up) hang_up_thread = HangUpThread(phone_held, phone_hung_up, dial_manager) hang_up_thread.start() while True: # Wait for phone to be picked up phone_held.wait() # Dial a number try: dialed = queue.get(block=True, timeout=0.1) except: continue response = dial_manager.dial(dialed) # If we matched a sequence, play out event if response is not None: response.speak()