home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / orca / script.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  17.9 KB  |  490 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """Each script maintains a set of key bindings, braille bindings, and
  5. AT-SPI event listeners.  The key bindings are an instance of
  6. KeyBindings.  The braille bindings are also a dictionary where the
  7. keys are BrlTTY command integers and the values are instances of
  8. InputEventHandler.  The listeners field is a dictionary where the keys
  9. are AT-SPI event names and the values are function pointers.
  10.  
  11. Instances of scripts are intended to be created solely by the
  12. focus_tracking_presenter.
  13.  
  14. This Script class is not intended to be instantiated directly.
  15. Instead, it is expected that subclasses of the Script class will be
  16. created in their own module.  The module defining the Script subclass
  17. is also required to have a 'getScript(app)' method that returns an
  18. instance of the Script subclass.  See default.py for an example."""
  19. __id__ = '$Id: script.py 4103 2008-08-15 11:07:31Z wwalker $'
  20. __version__ = '$Revision: 4103 $'
  21. __date__ = '$Date: 2008-08-15 07:07:31 -0400 (Fri, 15 Aug 2008) $'
  22. __copyright__ = 'Copyright (c) 2005-2008 Sun Microsystems Inc.'
  23. __license__ = 'LGPL'
  24. import braillegenerator
  25. import debug
  26. import flat_review
  27. import keybindings
  28. import orca_state
  29. import settings
  30. import speechgenerator
  31. import structural_navigation
  32. import where_am_I
  33. import bookmarks
  34. import tutorialgenerator
  35.  
  36. class Script:
  37.     '''The specific focus tracking scripts for applications.
  38.     '''
  39.     
  40.     def __init__(self, app):
  41.         '''Creates a script for the given application, if necessary.
  42.         This method should not be called by anyone except the
  43.         focus_tracking_presenter.
  44.  
  45.         Arguments:
  46.         - app: the Python Accessible application to create a script for
  47.         '''
  48.         self.app = app
  49.         if app:
  50.             self.name = self.app.name
  51.         else:
  52.             self.name = 'default'
  53.         self.name += ' (module=' + self.__module__ + ')'
  54.         self.listeners = self.getListeners()
  55.         self.presentIfInactive = True
  56.         self.structuralNavigation = self.getStructuralNavigation()
  57.         self.inputEventHandlers = { }
  58.         self.pointOfReference = { }
  59.         self.setupInputEventHandlers()
  60.         self.keyBindings = self.getKeyBindings()
  61.         self.brailleBindings = self.getBrailleBindings()
  62.         self.app_pronunciation_dict = self.getPronunciations()
  63.         self.brailleGenerator = self.getBrailleGenerator()
  64.         self.speechGenerator = self.getSpeechGenerator()
  65.         self.whereAmI = self.getWhereAmI()
  66.         self.bookmarks = self.getBookmarks()
  67.         self.voices = settings.voices
  68.         self.tutorialGenerator = self.getTutorialGenerator()
  69.         self.flatReviewContextClass = flat_review.Context
  70.         self.findCommandRun = False
  71.         self.commFailureWaitTime = settings.commFailureWaitTime
  72.         self.commFailureAttemptLimit = settings.commFailureAttemptLimit
  73.         debug.println(debug.LEVEL_FINE, 'NEW SCRIPT: %s' % self.name)
  74.  
  75.     
  76.     def getListeners(self):
  77.         '''Sets up the AT-SPI event listeners for this script.
  78.  
  79.         Returns a dictionary where the keys are AT-SPI event names
  80.         and the values are script methods.
  81.         '''
  82.         return { }
  83.  
  84.     
  85.     def setupInputEventHandlers(self):
  86.         '''Defines InputEventHandler fields for this script that can be
  87.         called by the key and braille bindings.'''
  88.         pass
  89.  
  90.     
  91.     def getKeyBindings(self):
  92.         '''Defines the key bindings for this script.
  93.  
  94.         Returns an instance of keybindings.KeyBindings.
  95.         '''
  96.         return keybindings.KeyBindings()
  97.  
  98.     
  99.     def getKeyBindingsForInputHandler(self, inputEventHandler):
  100.         ''' Returns a KeyBindings object with the list of KeyBindings that
  101.         matche the passed inputEventHandler as argument (at least the
  102.         inputEventHandler that has the same handler function)
  103.  
  104.         Arguments:
  105.         - inputEventHandler: an instance of input_event.InputEventHandler
  106.  
  107.         Returns an instance of keybindings.KeyBindings populated with
  108.         keybindings.KeyBinding instances that match the inputEventHandler.
  109.         '''
  110.         matches = keybindings.KeyBindings()
  111.         for binding in self.keyBindings.keyBindings:
  112.             if inputEventHandler == binding.handler:
  113.                 matches.add(binding)
  114.                 continue
  115.         
  116.         return matches
  117.  
  118.     
  119.     def getBrailleBindings(self):
  120.         '''Defines the braille bindings for this script.
  121.  
  122.         Returns a dictionary where the keys are BrlTTY commands and the
  123.         values are InputEventHandler instances.
  124.         '''
  125.         return { }
  126.  
  127.     
  128.     def getPronunciations(self):
  129.         '''Defines the application specific pronunciations for this script.
  130.  
  131.         Returns a dictionary where the keys are the actual text strings and
  132.         the values are the replacement strings that are spoken instead.
  133.         '''
  134.         return { }
  135.  
  136.     
  137.     def getBrailleCommandsForInputHandler(self, inputEventHandler):
  138.         """Returns a list of BrlTTY commands (they're in braille.py) that
  139.         match the given inputEventHandler passed as argument.
  140.  
  141.         Arguments:
  142.         - inputEventHandler: an instance of input_event.InputEventHandler
  143.  
  144.         Returns a list (possibly empty) of BrlTTY commands (they're in
  145.         braille.py) that match the given inputEventHandler passed.
  146.         """
  147.         return _[1]
  148.  
  149.     
  150.     def getBrailleGenerator(self):
  151.         '''Returns the braille generator for this script.
  152.         '''
  153.         return braillegenerator.BrailleGenerator(self)
  154.  
  155.     
  156.     def getSpeechGenerator(self):
  157.         '''Returns the speech generator for this script.
  158.         '''
  159.         return speechgenerator.SpeechGenerator(self)
  160.  
  161.     
  162.     def getTutorialGenerator(self):
  163.         '''Returns the tutorial generator for this script.
  164.         '''
  165.         return tutorialgenerator.TutorialGenerator(self)
  166.  
  167.     
  168.     def getEnabledStructuralNavigationTypes(self):
  169.         '''Returns a list of the structural navigation object types
  170.         enabled in this script.
  171.         '''
  172.         return []
  173.  
  174.     
  175.     def getStructuralNavigation(self):
  176.         """Returns the 'structural navigation' class for this script.
  177.         """
  178.         types = self.getEnabledStructuralNavigationTypes()
  179.         return structural_navigation.StructuralNavigation(self, types)
  180.  
  181.     
  182.     def useStructuralNavigationModel(self):
  183.         """Returns True if we should use structural navigation. Most
  184.         scripts will have no need to override this.  Gecko does however
  185.         because within an HTML document there are times when we do want
  186.         to use it and times when we don't even though it is enabled,
  187.         e.g. in a form field.
  188.         """
  189.         return self.structuralNavigation.enabled
  190.  
  191.     
  192.     def getWhereAmI(self):
  193.         '''Returns the "where am I" class for this script.
  194.         '''
  195.         return where_am_I.WhereAmI(self)
  196.  
  197.     
  198.     def echoKey(self, keyEvent):
  199.         """Determine whether this script should echo the current key event.
  200.         Note that the keyEcho() method in orca.py will still take into 
  201.         account whatever the user's various preferences for key echoing
  202.         are, which may override what is return by this echoKey() method.
  203.  
  204.         Arguments:
  205.         - keyEvent - the key event
  206.  
  207.         Returns an indication of whether a key echo event should be
  208.         allowed to happen for this script.
  209.         """
  210.         return True
  211.  
  212.     
  213.     def getBookmarks(self):
  214.         '''Returns the "bookmarks" class for this script.
  215.         '''
  216.         
  217.         try:
  218.             return self.bookmarks
  219.         except AttributeError:
  220.             self.bookmarks = bookmarks.Bookmarks(self)
  221.             return self.bookmarks
  222.  
  223.  
  224.     
  225.     def getAppPreferencesGUI(self):
  226.         '''Return a GtkVBox contain the application unique configuration
  227.         GUI items for the current application.
  228.         '''
  229.         pass
  230.  
  231.     
  232.     def setAppPreferences(self, prefs):
  233.         '''Write out the application specific preferences lines and set the
  234.         new values.
  235.  
  236.         Arguments:
  237.         - prefs: file handle for application preferences.
  238.         '''
  239.         pass
  240.  
  241.     
  242.     def overrideAppKeyBindings(self, script, keyBindings):
  243.         '''Allow for the customization of application specific key bindings.
  244.  
  245.         Arguments:
  246.         - script: the application script.
  247.         - keyBindings: the set of key bindings for this script.
  248.         '''
  249.         return keyBindings
  250.  
  251.     
  252.     def overridePronunciations(self, script, pronunciations):
  253.         '''Allow for the customization of application specific pronunciations.
  254.  
  255.         Arguments:
  256.         - script: the application script.
  257.         - pronunciations: the dictionary of pronunciations for this script.
  258.         '''
  259.         return pronunciations
  260.  
  261.     
  262.     def getAppState(self):
  263.         '''Returns an object that can be passed to setAppState.  This
  264.         object will be used by setAppState to restore any state
  265.         information that was being maintained by the script.'''
  266.         pass
  267.  
  268.     
  269.     def setAppState(self, appState):
  270.         '''Sets the application state using the given appState object.
  271.  
  272.         Arguments:
  273.         - appState: an object obtained from getAppState
  274.         '''
  275.         pass
  276.  
  277.     
  278.     def getClickCount(self):
  279.         '''Return the count of the number of clicks a user has made to one
  280.         of the keys on the keyboard.
  281.         '''
  282.         return orca_state.clickCount
  283.  
  284.     
  285.     def processObjectEvent(self, event):
  286.         """Processes all AT-SPI object events of interest to this
  287.         script.  The interest in events is specified via the
  288.         'listeners' field that was defined during the construction of
  289.         this script.
  290.  
  291.         In general, the primary purpose of handling object events is to
  292.         keep track of changes to the locus of focus and notify the
  293.         orca module of these changes via orca.setLocusOfFocus and
  294.         orca.visualAppearanceChanged.
  295.  
  296.         Note that this script may be passed events it doesn't care
  297.         about, so it needs to react accordingly.
  298.  
  299.         Arguments:
  300.         - event: the Event
  301.         """
  302.         if not orca_state.activeScript == self:
  303.             pass
  304.         processEvent = self.presentIfInactive
  305.         if not processEvent:
  306.             return None
  307.         for key in self.listeners.keys():
  308.             if event.type.startswith(key):
  309.                 self.listeners[key](event)
  310.                 continue
  311.             processEvent
  312.         
  313.  
  314.     
  315.     def consumesKeyboardEvent(self, keyboardEvent):
  316.         '''Called when a key is pressed on the keyboard.
  317.  
  318.         Arguments:
  319.         - keyboardEvent: an instance of input_event.KeyboardEvent
  320.  
  321.         Returns True if the event is of interest.
  322.         '''
  323.         user_bindings = None
  324.         user_bindings_map = settings.keyBindingsMap
  325.         if self.__module__ in user_bindings_map:
  326.             user_bindings = user_bindings_map[self.__module__]
  327.         elif 'default' in user_bindings_map:
  328.             user_bindings = user_bindings_map['default']
  329.         
  330.         consumes = False
  331.         if user_bindings:
  332.             handler = user_bindings.getInputHandler(keyboardEvent)
  333.             if handler and handler.function in self.structuralNavigation.functions:
  334.                 return self.useStructuralNavigationModel()
  335.             consumes = handler != None
  336.         
  337.         if not consumes:
  338.             handler = self.keyBindings.getInputHandler(keyboardEvent)
  339.             if handler and handler.function in self.structuralNavigation.functions:
  340.                 return self.useStructuralNavigationModel()
  341.             consumes = handler != None
  342.         
  343.         return consumes
  344.  
  345.     
  346.     def processKeyboardEvent(self, keyboardEvent):
  347.         """Processes the given keyboard event.
  348.  
  349.         This method will primarily use the keybindings field of this
  350.         script instance see if this script has an interest in the
  351.         event.
  352.  
  353.         NOTE: there is latent, but unsupported, logic for allowing
  354.         the user's user-settings.py file to extend and/or override
  355.         the keybindings for a script.
  356.  
  357.         Arguments:
  358.         - keyboardEvent: an instance of input_event.KeyboardEvent
  359.         """
  360.         keyboardEvent.script = self
  361.         user_bindings = None
  362.         user_bindings_map = settings.keyBindingsMap
  363.         if self.__module__ in user_bindings_map:
  364.             user_bindings = user_bindings_map[self.__module__]
  365.         elif 'default' in user_bindings_map:
  366.             user_bindings = user_bindings_map['default']
  367.         
  368.         consumed = False
  369.         if user_bindings:
  370.             consumed = user_bindings.consumeKeyboardEvent(self, keyboardEvent)
  371.         
  372.         if not consumed:
  373.             consumed = self.keyBindings.consumeKeyboardEvent(self, keyboardEvent)
  374.         
  375.         return consumed
  376.  
  377.     
  378.     def consumesBrailleEvent(self, brailleEvent):
  379.         '''Called when a key is pressed on the braille display.
  380.  
  381.         Arguments:
  382.         - brailleEvent: an instance of input_event.KeyboardEvent
  383.  
  384.         Returns True if the event is of interest.
  385.         '''
  386.         user_bindings = None
  387.         user_bindings_map = settings.brailleBindingsMap
  388.         if self.__module__ in user_bindings_map:
  389.             user_bindings = user_bindings_map[self.__module__]
  390.         elif 'default' in user_bindings_map:
  391.             user_bindings = user_bindings_map['default']
  392.         
  393.         command = brailleEvent.event
  394.         consumes = False
  395.         if user_bindings:
  396.             consumes = command in user_bindings
  397.         
  398.         if not consumes:
  399.             consumes = command in self.brailleBindings
  400.         
  401.         return consumes
  402.  
  403.     
  404.     def processBrailleEvent(self, brailleEvent):
  405.         """Called whenever a key is pressed on the Braille display.
  406.  
  407.         This method will primarily use the brailleBindings field of
  408.         this script instance see if this script has an interest in the
  409.         event.
  410.  
  411.         NOTE: there is latent, but unsupported, logic for allowing
  412.         the user's user-settings.py file to extend and/or override
  413.         the brailleBindings for a script.
  414.  
  415.         Arguments:
  416.         - brailleEvent: an instance of input_event.BrailleEvent
  417.         """
  418.         brailleEvent.script = self
  419.         consumed = False
  420.         user_bindings = None
  421.         command = brailleEvent.event
  422.         user_bindings_map = settings.brailleBindingsMap
  423.         if self.name in user_bindings_map:
  424.             user_bindings = user_bindings_map[self.name]
  425.         elif 'default' in user_bindings_map:
  426.             user_bindings = user_bindings_map['default']
  427.         
  428.         if user_bindings and command in user_bindings:
  429.             handler = user_bindings[command]
  430.             consumed = handler.processInputEvent(self, brailleEvent)
  431.         
  432.         if not consumed and command in self.brailleBindings:
  433.             handler = self.brailleBindings[command]
  434.             consumed = handler.processInputEvent(self, brailleEvent)
  435.         
  436.         return consumed
  437.  
  438.     
  439.     def locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus):
  440.         '''Called when the visual object with focus changes.
  441.  
  442.         The primary purpose of this method is to present locus of focus
  443.         information to the user.
  444.  
  445.         NOTE: scripts should not call this method directly.  Instead,
  446.         a script should call orca.setLocusOfFocus, which will eventually
  447.         result in this method being called.
  448.  
  449.         Arguments:
  450.         - event: if not None, the Event that caused the change
  451.         - oldLocusOfFocus: Accessible that is the old locus of focus
  452.         - newLocusOfFocus: Accessible that is the new locus of focus
  453.         '''
  454.         pass
  455.  
  456.     
  457.     def visualAppearanceChanged(self, event, obj):
  458.         """Called when the visual appearance of an object changes.
  459.         This method should not be called for objects whose visual
  460.         appearance changes solely because of focus -- setLocusOfFocus
  461.         is used for that.  Instead, it is intended mostly for objects
  462.         whose notional 'value' has changed, such as a checkbox
  463.         changing state, a progress bar advancing, a slider moving,
  464.         text inserted, caret moved, etc.
  465.  
  466.         The primary purpose of this method is to present the changed
  467.         information to the user.
  468.  
  469.         NOTE: scripts should not call this method directly.  Instead,
  470.         a script should call orca.visualAppearanceChanged, which will
  471.         eventually result in this method being called.
  472.  
  473.         Arguments:
  474.         - event: if not None, the Event that caused this to happen
  475.         - obj: the Accessible whose visual appearance changed.
  476.         """
  477.         pass
  478.  
  479.     
  480.     def activate(self):
  481.         '''Called when this script is activated.'''
  482.         pass
  483.  
  484.     
  485.     def deactivate(self):
  486.         '''Called when this script is deactivated.'''
  487.         pass
  488.  
  489.  
  490.