def main(): args = sys.argv[1:] try: speech.init() pygame.init() pygame.display.set_mode((640, 480)) pygame.display.set_caption("sudoaudio") s = SoundSplash(os.path.join(paths.sounds_path, "intro.ogg")) s.run() if len(args) < 1: dir = os.path.join(paths.puzzles_path, "pack1") basename = ChoiceMenu(_("Select puzzle"), list_puzzles(dir)).run() if basename is None: sys.exit(-1) file = os.path.join(dir, basename) else: file = args[0] Game(file).run() except: raise finally: pygame.quit() speech.quit()
def loadUserSettings(script=None, inputEvent=None): """Loads (and reloads) the user settings module, reinitializing things such as speech if necessary. Returns True to indicate the input event has been consumed. """ global _userSettings # Shutdown the output drivers and give them a chance to die. # httpserver.shutdown() speech.shutdown() braille.shutdown() mag.shutdown() if _currentPresentationManager >= 0: _PRESENTATION_MANAGERS[_currentPresentationManager].deactivate() time.sleep(1) reloaded = False if _userSettings: try: reload(_userSettings) reloaded = True except ImportError: debug.printException(debug.LEVEL_FINEST) except: debug.printException(debug.LEVEL_SEVERE) else: try: _userSettings = __import__("user-settings") except ImportError: debug.printException(debug.LEVEL_FINEST) except: debug.printException(debug.LEVEL_SEVERE) # If any settings were added to the command line, they take # precedence over everything else. # for key in _commandLineSettings: settings.__dict__[key] = _commandLineSettings[key] if settings.enableSpeech: try: speech.init() if reloaded: # Translators: there is a keystroke to reload the user # preferences. This is a spoken prompt to let the user # know when the preferences has been reloaded. # speech.speak(_("Orca user settings reloaded.")) debug.println(debug.LEVEL_CONFIGURATION, "Speech module has been initialized.") except: debug.printException(debug.LEVEL_SEVERE) debug.println(debug.LEVEL_SEVERE, "Could not initialize connection to speech.") else: debug.println(debug.LEVEL_CONFIGURATION, "Speech module has NOT been initialized.") if settings.enableBraille: try: braille.init(_processBrailleEvent, settings.tty) except: debug.printException(debug.LEVEL_WARNING) debug.println(debug.LEVEL_WARNING, "Could not initialize connection to braille.") if settings.enableMagnifier: try: mag.init() debug.println(debug.LEVEL_CONFIGURATION, "Magnification module has been initialized.") except: debug.printException(debug.LEVEL_SEVERE) debug.println(debug.LEVEL_SEVERE, "Could not initialize connection to magnifier.") else: debug.println(debug.LEVEL_CONFIGURATION, "Magnification module has NOT been initialized.") # We don't want the Caps_Lock modifier to act as a locking # modifier if it used as the Orca modifier key. In addition, if # the KP_Insert key is used as the Orca modifier key, we want to # make sure we clear any other keysyms that might be in use on # that key since we won't be able to detect them as being the Orca # modifier key. For example, KP_Insert produces "KP_Insert" when # pressed by itself, but Shift+KP_Insert produces "0". # # The original values are saved/reset in the orca shell script. # # [[[TODO: WDW - we probably should just to a 'xmodmap -e "%s = %s"' # for all of the orcaModifierKeys, but saving/restoring the values # becomes a little more difficult. If we could assume a writeable # filesystem (we cannot), we could do a 'xmodmap -pke > /tmp/foo' # to save the keymap and a 'xmodmap /tmp/foo' to restore it. # For now, we'll just look at the Orca modifier keys we support # (Caps Lock, KP_Insert, and Insert).]]] # for keyName in settings.orcaModifierKeys: if keyName == "Caps_Lock": os.system('xmodmap -e "clear Lock"') if keyName in ["Caps_Lock", "KP_Insert", "Insert"]: command = 'xmodmap -e "keysym %s = %s"' % (keyName, keyName) os.system(command) if _currentPresentationManager >= 0: _PRESENTATION_MANAGERS[_currentPresentationManager].activate() _showMainWindowGUI() httpserver.init() return True
def setupSpeech(prefsDict): """Sets up speech support. If speech setup is successful and the user wants it, writes speech settings to the setting file and returns True. If speech is not available, or the user doesn't want speech, returns False. """ global workingFactories global speechServerChoice global speechVoiceChoice # Use this because callbacks will often hang when not running # with bonobo main in use. # settings.enableSpeechCallbacks = False factories = speech.getSpeechServerFactories() if len(factories) == 0: # Translators: this means speech synthesis (i.e., the machine # speaks to you from its speakers) is not installed or working. # print _("Speech is unavailable.") return False speech.init() sayAndPrint(_("Welcome to Orca setup.")) workingFactories = [] for factory in factories: try: servers = factory.SpeechServer.getSpeechServers() if len(servers): workingFactories.append([factory, servers]) except: pass if len(workingFactories) == 0: # Translators: this means speech synthesis (i.e., the machine # speaks to you from its speakers) is not installed or working. # print _("Speech is unavailable.") return False elif len(workingFactories) > 1: # Translators: the speech system represents what general # speech wrapper is going to be used. For example, # gnome-speech is a speech system, speech dispatcher is # another, emacspeak is another. These all then provide # wrappers around specific speech servers (engines). # sayAndPrint(_("Select desired speech system:")) choices = {} i = 1 for workingFactory in workingFactories: choices[i] = workingFactory sayAndPrint("%d. %s" \ % (i, workingFactory[0].SpeechServer.getFactoryName())) i += 1 # Translators: this is prompting for a numerical choice. # choice = int(sayAndPrint(_("Enter choice: "), False, True)) if (choice <= 0) or (choice >= i): # Translators: this means speech synthesis will not be used. # sayAndPrint(_("Speech will not be used.\n")) return False [factory, servers] = choices[choice] else: [factory, servers] = workingFactories[0] if len(servers) == 0: # Translators: this means no working speech servers (speech # synthesis engines) can be found. # sayAndPrint(_("No servers available.\n")) sayAndPrint(_("Speech will not be used.\n")) return False if len(servers) > 1: # Translators: this is prompting for a numerical choice from a list # of available speech synthesis engines. # sayAndPrint(_("Select desired speech server."), len(workingFactories) > 1) i = 1 choices = {} for server in servers: sayAndPrint("%d. %s" % (i, server.getInfo()[0])) choices[i] = server i += 1 # Translators: this is prompting for a numerical choice. # choice = int(sayAndPrint(_("Enter choice: "), False, True)) if (choice <= 0) or (choice >= i): # Translators: this means speech synthesis will not be used. # sayAndPrint(_("Speech will not be used.\n")) return False speechServerChoice = choices[choice] else: speechServerChoice = servers[0] families = speechServerChoice.getVoiceFamilies() if len(families) == 0: # Translators: this means the speech server (speech synthesis # engine) is not working properly and no voices (e.g., male, # female, child) are available. # sayAndPrint(_("No voices available.\n")) # Translators: this means speech synthesis will not be used. # sayAndPrint(_("Speech will not be used.\n")) return False if len(families) > 1: # Translators: this is prompting for a numerical value from a # list of choices of speech synthesis voices (e.g., male, # female, child). # sayAndPrint( _("Select desired voice:"), True, # stop False, # getInput speechServerChoice) # server i = 1 choices = {} for family in families: name = family[speechserver.VoiceFamily.NAME] \ + " (%s)" % family[speechserver.VoiceFamily.LOCALE] voice = acss.ACSS({acss.ACSS.FAMILY: family}) sayAndPrint( "%d. %s" % (i, name), False, # stop False, # getInput speechServerChoice, # speech server voice) # voice choices[i] = voice i += 1 # Translators: this is prompting for a numerical choice. # choice = int( sayAndPrint( _("Enter choice: "), False, # stop True, # getInput speechServerChoice)) # speech server if (choice <= 0) or (choice >= i): # Translators: this means speech synthesis will not be used. # sayAndPrint(_("Speech will not be used.\n")) return False defaultACSS = choices[choice] else: defaultACSS = acss.ACSS({acss.ACSS.FAMILY: families[0]}) speechVoiceChoice = defaultACSS # Force the rate to 50 so it will be set to something # and output to the user settings file. 50 is chosen # here, BTW, since it is the default value. The same # goes for gain (volume) and average-pitch, but they # range from 0-10 instead of 0-100. # defaultACSS[acss.ACSS.RATE] = 50 defaultACSS[acss.ACSS.GAIN] = 9 defaultACSS[acss.ACSS.AVERAGE_PITCH] = 5 uppercaseACSS = acss.ACSS({acss.ACSS.AVERAGE_PITCH: 6}) hyperlinkACSS = acss.ACSS({}) voices = { settings.DEFAULT_VOICE: defaultACSS, settings.UPPERCASE_VOICE: uppercaseACSS, settings.HYPERLINK_VOICE: hyperlinkACSS } prefsDict["enableSpeech"] = True prefsDict["speechServerFactory"] = factory prefsDict["speechServerInfo"] = speechServerChoice prefsDict["voices"] = voices # Translators: the word echo feature of Orca will speak the word # prior to the caret when the user types a word delimiter. # answer = sayAndPrint(_("Enable echo by word? Enter y or n: "), True, True, speechServerChoice, speechVoiceChoice) prefsDict["enableEchoByWord"] = checkYes(answer) # Translators: if key echo is enabled, Orca will speak the name of a key # as the user types on the keyboard. If the user wants key echo, they # will then be prompted for which classes of keys they want echoed. # answer = sayAndPrint(_("Enable key echo? Enter y or n: "), True, True, speechServerChoice, speechVoiceChoice) if checkYes(answer): prefsDict["enableKeyEcho"] = True # Translators: this is in reference to key echo for # normal text entry keys. # answer = sayAndPrint( _("Enable alphanumeric and punctuation keys? Enter y or n: "), True, True, speechServerChoice, speechVoiceChoice) prefsDict["enablePrintableKeys"] = checkYes(answer) # Translators: this is in reference to key echo for # CTRL, ALT, Shift, Insert, and "Fn" on laptops. # answer = sayAndPrint(_("Enable modifier keys? Enter y or n: "), True, True, speechServerChoice, speechVoiceChoice) prefsDict["enableModifierKeys"] = checkYes(answer) # Translators: this is in reference to key echo for # Caps Lock, Num Lock, Scroll Lock, etc. # answer = sayAndPrint(_("Enable locking keys? Enter y or n: "), True, True, speechServerChoice, speechVoiceChoice) prefsDict["enableLockingKeys"] = checkYes(answer) # Translators: this is in reference to key echo for # the keys at the top of the keyboard. # answer = sayAndPrint(_("Enable function keys? Enter y or n: "), True, True, speechServerChoice, speechVoiceChoice) prefsDict["enableFunctionKeys"] = checkYes(answer) # Translators: this is in reference to key echo for # space, enter, escape, tab, backspace, delete, arrow # keys, page up, page down, etc. # answer = sayAndPrint(_("Enable action keys? Enter y or n: "), True, True, speechServerChoice, speechVoiceChoice) prefsDict["enableActionKeys"] = checkYes(answer) else: prefsDict["enableKeyEcho"] = False prefsDict["enablePrintableKeys"] = False prefsDict["enableModifierKeys"] = False prefsDict["enableLockingKeys"] = False prefsDict["enableFunctionKeys"] = False prefsDict["enableActionKeys"] = False # Translators: we allow the user to choose between the desktop (i.e., # has a numeric keypad) and laptop (i.e., small and compact) keyboard # layouts for how they might control Orca. # sayAndPrint(_("Select desired keyboard layout."), False, False, speechServerChoice, speechVoiceChoice) i = 1 choices = {} # Translators: we allow the user to choose between the desktop (i.e., # has a numeric keypad) and laptop (i.e., small and compact) keyboard # layouts for how they might control Orca. # sayAndPrint(_("1. Desktop")) # Translators: we allow the user to choose between the desktop (i.e., # has a numeric keypad) and laptop (i.e., small and compact) keyboard # layouts for how they might control Orca. # sayAndPrint(_("2. Laptop")) try: # Translators: this is prompting for a numerical choice. # choice = int(sayAndPrint(_("Enter choice: "), False, True)) except: choice = -1 if choice == 2: prefsDict["keyboardLayout"] = settings.GENERAL_KEYBOARD_LAYOUT_LAPTOP prefsDict["orcaModifierKeys"] = settings.LAPTOP_MODIFIER_KEYS else: prefsDict["keyboardLayout"] = settings.GENERAL_KEYBOARD_LAYOUT_DESKTOP prefsDict["orcaModifierKeys"] = settings.DESKTOP_MODIFIER_KEYS if (choice <= 0) or (choice >= 3): sayAndPrint(_("Invalid choice. Selecting desktop keyboard layout.\n")) return True
def setupSpeech(prefsDict): """Sets up speech support. If speech setup is successful and the user wants it, writes speech settings to the setting file and returns True. If speech is not available, or the user doesn't want speech, returns False. """ global workingFactories global speechServerChoice global speechVoiceChoice # Use this because callbacks in this setup can hang. # TODO: Is this true still?? # settings.enableSpeechCallbacks = False factories = speech.getSpeechServerFactories() if len(factories) == 0: # Translators: this means speech synthesis (i.e., the machine # speaks to you from its speakers) is not installed or working. # print _("Speech is unavailable.") return False try: speech.init() except: # Translators: this means speech synthesis (i.e., the machine # speaks to you from its speakers) is not installed or working. # print _("Speech is unavailable.") return False sayAndPrint(_("Welcome to Orca setup.")) workingFactories = [] for factory in factories: try: servers = factory.SpeechServer.getSpeechServers() if len(servers): workingFactories.append([factory, servers]) except: pass if len(workingFactories) == 0: # Translators: this means speech synthesis (i.e., the machine # speaks to you from its speakers) is not installed or working. # print _("Speech is unavailable.") return False elif len(workingFactories) > 1: # Translators: the speech system represents what general # speech wrapper is going to be used. Speech-dispatcher # is an example of a speech system. It provides wrappers # around specific speech servers (engines). # sayAndPrint(_("Select desired speech system:")) choices = {} i = 1 for workingFactory in workingFactories: choices[i] = workingFactory sayAndPrint("%d. %s" \ % (i, workingFactory[0].SpeechServer.getFactoryName())) i += 1 # Translators: this is prompting for a numerical choice. # while True: try: choice = int(sayAndPrint(_("Enter choice: "), False, True)) break except: # Translators: this is letting the user they input an # invalid integer value on the command line and is # also requesting they enter a valid integer value. # sayAndPrint(_("Please enter a valid number.")) if (choice <= 0) or (choice >= i): # Translators: this means speech synthesis will not be used. # sayAndPrint(_("Speech will not be used.\n")) return False [factory, servers] = choices[choice] else: [factory, servers] = workingFactories[0] if len(servers) == 0: # Translators: this means no working speech servers (speech # synthesis engines) can be found. # sayAndPrint(_("No servers available.\n")) sayAndPrint(_("Speech will not be used.\n")) return False if len(servers) > 1: # Translators: this is prompting for a numerical choice from a list # of available speech synthesis engines. # sayAndPrint(_("Select desired speech server."), len(workingFactories) > 1) i = 1 choices = {} for server in servers: sayAndPrint("%d. %s" % (i, server.getInfo()[0])) choices[i] = server i += 1 # Translators: this is prompting for a numerical choice. # while True: try: choice = int(sayAndPrint(_("Enter choice: "), False, True)) break except: sayAndPrint(_("Please enter a valid number.")) if (choice <= 0) or (choice >= i): # Translators: this means speech synthesis will not be used. # sayAndPrint(_("Speech will not be used.\n")) return False speechServerChoice = choices[choice] else: speechServerChoice = servers[0] families = speechServerChoice.getVoiceFamilies() if len(families) == 0: # Translators: this means the speech server (speech synthesis # engine) is not working properly and no voices (e.g., male, # female, child) are available. # sayAndPrint(_("No voices available.\n")) # Translators: this means speech synthesis will not be used. # sayAndPrint(_("Speech will not be used.\n")) return False if len(families) > 1: # Translators: this is prompting for a numerical value from a # list of choices of speech synthesis voices (e.g., male, # female, child). # sayAndPrint(_("Select desired voice:"), True, # stop False, # getInput speechServerChoice) # server i = 1 choices = {} for family in families: name = family[speechserver.VoiceFamily.NAME] \ + " (%s)" % family[speechserver.VoiceFamily.LOCALE] voice = acss.ACSS({acss.ACSS.FAMILY : family}) sayAndPrint("%d. %s" % (i, name), False, # stop False, # getInput speechServerChoice, # speech server voice) # voice choices[i] = voice i += 1 while True: try: # Translators: this is prompting for a numerical choice. # choice = int(sayAndPrint(_("Enter choice: "), False, # stop True, # getInput speechServerChoice)) # speech server break except: sayAndPrint(_("Please enter a valid number.")) if (choice <= 0) or (choice >= i): # Translators: this means speech synthesis will not be used. # sayAndPrint(_("Speech will not be used.\n")) return False defaultACSS = choices[choice] else: defaultACSS = acss.ACSS({acss.ACSS.FAMILY : families[0]}) speechVoiceChoice = defaultACSS # Force the rate to 50 so it will be set to something # and output to the user settings file. 50 is chosen # here, BTW, since it is the default value. The same # goes for gain (volume) and average-pitch, but they # range from 0-10 instead of 0-100. # defaultACSS[acss.ACSS.RATE] = 50 defaultACSS[acss.ACSS.GAIN] = 100 defaultACSS[acss.ACSS.AVERAGE_PITCH] = 5 uppercaseACSS = acss.ACSS({acss.ACSS.AVERAGE_PITCH : 6}) hyperlinkACSS = acss.ACSS({}) systemACSS = acss.ACSS({}) voices = { settings.DEFAULT_VOICE : defaultACSS, settings.UPPERCASE_VOICE : uppercaseACSS, settings.HYPERLINK_VOICE : hyperlinkACSS, settings.SYSTEM_VOICE : systemACSS } prefsDict["enableSpeech"] = True prefsDict["speechServerFactory"] = factory.__name__ prefsDict["speechServerInfo"] = speechServerChoice.getInfo() prefsDict["voices"] = voices stop = True while True: # Translators: the word echo feature of Orca will speak the # word prior to the caret when the user types a word # delimiter. # answer = sayAndPrint(_("Enable echo by word? Enter y or n: "), stop, True, speechServerChoice, speechVoiceChoice) try: prefsDict["enableEchoByWord"] = checkYes(answer) break except: stop = False sayAndPrint(_("Please enter y or n.")) stop = True while True: # Translators: if key echo is enabled, Orca will speak the # name of a key as the user types on the keyboard. If the # user wants key echo, they will then be prompted for which # classes of keys they want echoed. # answer = sayAndPrint(_("Enable key echo? Enter y or n: "), stop, True, speechServerChoice, speechVoiceChoice) try: prefsDict["enableKeyEcho"] = checkYes(answer) break except: stop = False sayAndPrint(_("Please enter y or n.")) keyEcho = prefsDict["enableKeyEcho"] if not keyEcho: prefsDict["enableKeyEcho"] = False prefsDict["enablePrintableKeys"] = False prefsDict["enableModifierKeys"] = False prefsDict["enableFunctionKeys"] = False prefsDict["enableActionKeys"] = False stop = True while keyEcho and True: # Translators: this is in reference to key echo for # normal text entry keys. # answer = sayAndPrint( \ _("Enable alphanumeric and punctuation keys? Enter y or n: "), stop, True, speechServerChoice, speechVoiceChoice) try: prefsDict["enablePrintableKeys"] = checkYes(answer) break except: stop = False sayAndPrint(_("Please enter y or n.")) stop = True while keyEcho and True: # Translators: this is in reference to key echo for # CTRL, ALT, Shift, Insert, and "Fn" on laptops. # answer = sayAndPrint(_("Enable modifier keys? Enter y or n: "), stop, True, speechServerChoice, speechVoiceChoice) try: prefsDict["enableModifierKeys"] = checkYes(answer) break except: stop = False sayAndPrint(_("Please enter y or n.")) stop = True while keyEcho and True: # Translators: this is in reference to key echo for # the keys at the top of the keyboard. # answer = sayAndPrint(_("Enable function keys? Enter y or n: "), stop, True, speechServerChoice, speechVoiceChoice) try: prefsDict["enableFunctionKeys"] = checkYes(answer) break except: stop = False sayAndPrint(_("Please enter y or n.")) stop = True while keyEcho and True: # Translators: this is in reference to key echo for # space, enter, escape, tab, backspace, delete, arrow # keys, page up, page down, etc. # answer = sayAndPrint(_("Enable action keys? Enter y or n: "), stop, True, speechServerChoice, speechVoiceChoice) try: prefsDict["enableActionKeys"] = checkYes(answer) break except: stop = False sayAndPrint(_("Please enter y or n.")) # Translators: we allow the user to choose between the desktop (i.e., # has a numeric keypad) and laptop (i.e., small and compact) keyboard # layouts for how they might control Orca. # sayAndPrint(_("Select desired keyboard layout."), True, False, speechServerChoice, speechVoiceChoice) i = 1 choices = {} # Translators: we allow the user to choose between the desktop (i.e., # has a numeric keypad) and laptop (i.e., small and compact) keyboard # layouts for how they might control Orca. # sayAndPrint(_("1. Desktop"), False, False, speechServerChoice, speechVoiceChoice) # Translators: we allow the user to choose between the desktop (i.e., # has a numeric keypad) and laptop (i.e., small and compact) keyboard # layouts for how they might control Orca. # sayAndPrint(_("2. Laptop"), False, False, speechServerChoice, speechVoiceChoice) while True: try: # Translators: this is prompting for a numerical choice. # choice = int(sayAndPrint(_("Enter choice: "), False, True, speechServerChoice, speechVoiceChoice)) if choice == 2: prefsDict["keyboardLayout"] = \ settings.GENERAL_KEYBOARD_LAYOUT_LAPTOP prefsDict["orcaModifierKeys"] = \ settings.LAPTOP_MODIFIER_KEYS break elif choice == 1: prefsDict["keyboardLayout"] = \ settings.GENERAL_KEYBOARD_LAYOUT_DESKTOP prefsDict["orcaModifierKeys"] = \ settings.DESKTOP_MODIFIER_KEYS break else: sayAndPrint(_("Please enter a valid number.")) except: sayAndPrint(_("Please enter a valid number.")) return True
def __init__(self, okaomanager=None): speech.init() pass