Example #1
0
def accessibilityPutValue(processor, path, value):
    '''
    Sets the given value in an accessible of the given path.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path of the accessible
    :type path: tadek.core.accessible.Path
    :param value: New value of the accessible
    :type value: float
    :return: True if success, False otherwise
    :rtype: boolean
    '''
    log.debug(str(locals()))
    try:
        # Get object from the processor cache or from the accessible provider
        if processor.cache and processor.cache[-1] == path:
            a11y, obj, path = processor.cache
        else:
            a11y, obj = providers.accessible(path)
        # Reset the processor cache
        processor.cache = None
        if obj is None:
            log.warning("Attempt of setting value for non-accessible")
            return False
        status = a11y.setValue(obj, value)
    except:
        log.exception("Set accessible value error: %s" % path)
        # Reset the processor cache before leaving
        processor.cache = None
        return False
    if not status:
        log.info("Set accessible value failure: %s" % path)
    return status
Example #2
0
 def _responseExpandAll(self, response):
     '''
     Expands an accessible tree item from the response recursively.
     '''
     path = response.accessible.path
     log.debug("Expanding accessible tree item recursively: %s" % path)
     if not response.status:
         return False
     accessible = response.accessible
     item = None
     if path.tuple:
         item = self._pathItem(path)
         if not item:
             log.warning("Invalid accessible tree path: %s" % path)
             return False
         # Update the item
         self._setAccessibleItem(accessible, item)
         item.setDisabled(False)
     else:
         self._treeWidget.clear()
     self._manualExpand = True
     if item:
         item.setExpanded(True)
     for child in accessible.children():
         self._accessibleItem(child,
                              item or self._treeWidget,
                              recursive=True)
     for i in xrange(self._COLUMN_COUNT):
         self._treeWidget.resizeColumnToContents(i)
     self._manualExpand = False
     return True
Example #3
0
def accessibilityPutValue(processor, path, value):
    '''
    Sets the given value in an accessible of the given path.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path of the accessible
    :type path: tadek.core.accessible.Path
    :param value: New value of the accessible
    :type value: float
    :return: True if success, False otherwise
    :rtype: boolean
    '''
    log.debug(str(locals()))
    try:
        # Get object from the processor cache or from the accessible provider
        if processor.cache and processor.cache[-1] == path:
            a11y, obj, path = processor.cache
        else:
            a11y, obj = providers.accessible(path)
        # Reset the processor cache
        processor.cache = None
        if obj is None:
            log.warning("Attempt of setting value for non-accessible")
            return False
        status = a11y.setValue(obj, value)
    except:
        log.exception("Set accessible value error: %s" % path)
        # Reset the processor cache before leaving
        processor.cache = None
        return False
    if not status:
        log.info("Set accessible value failure: %s" % path)
    return status
Example #4
0
def systemGet(processor, path):
    '''
    Gets content data of a system file of the given path.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path to the system file
    :type path: string
    :return: The file content data or None
    :rtype: string
    '''
    log.debug(str(locals()))
    # Reset the processor cache
    processor.cache = None
    if not os.path.exists(path):
        log.warning("Attempt of getting not existing system file: %s" % path)
        return False, ''
    fd = None
    try:
        fd = open(path, 'r')
        data = fd.read()
    except:
        log.exception("Get system file failure: %s" % path)
        return False, ''
    finally:
        if fd:
            fd.close()
    return True, data
Example #5
0
 def _responseExpandAll(self, response):
     '''
     Expands an accessible tree item from the response recursively.
     '''
     path = response.accessible.path
     log.debug("Expanding accessible tree item recursively: %s" % path)
     if not response.status:
         return False
     accessible = response.accessible
     item = None
     if path.tuple:
         item = self._pathItem(path)
         if not item:
             log.warning("Invalid accessible tree path: %s" % path)
             return False
         # Update the item
         self._setAccessibleItem(accessible, item)
         item.setDisabled(False)
     else:
         self._treeWidget.clear()
     self._manualExpand = True
     if item:
         item.setExpanded(True)
     for child in accessible.children():
         self._accessibleItem(child, item or self._treeWidget,
                              recursive=True)
     for i in xrange(self._COLUMN_COUNT):
         self._treeWidget.resizeColumnToContents(i)
     self._manualExpand = False
     return True
Example #6
0
def systemGet(processor, path):
    '''
    Gets content data of a system file of the given path.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path to the system file
    :type path: string
    :return: The file content data or None
    :rtype: string
    '''
    log.debug(str(locals()))
    # Reset the processor cache
    processor.cache = None
    if not os.path.exists(path):
        log.warning("Attempt of getting not existing system file: %s" % path)
        return False, ''
    fd = None
    try:
        fd = open(path, 'r')
        data = fd.read()
    except:
        log.exception("Get system file failure: %s" % path)
        return False, ''
    finally:
        if fd:
            fd.close()
    return True, data
Example #7
0
    def _startSearching(self):
        '''
        Starts the searching process.
        '''
        self.buttonNext.setVisible(True)
        self.buttonNext.setEnabled(False)
        self.buttonSearch.setVisible(False)
        self.buttonStop.setEnabled(True)

        explorerDev = self._view.deviceTabAtIndex()
        if explorerDev is None:
            runWarning("No device is connected.", "Search unavailable")
            self.searchingStoppedUpdateState()
            return

        currentPath = explorerDev.selectedItemPath()
        if currentPath:
            if not explorerDev.itemExists(currentPath):
                self.searchingStoppedUpdateState()
                return
        else:
            runInformation("No item is selected.", "Search unavailable")
            self.searchingStoppedUpdateState()
            log.warning("Search cannot be performed since no reference item"
                " is selected")
            return

        self._explorerDev = explorerDev
        self._explorerDev.startItemChanged.connect(self._startItemChanged)
        self._explorerDev.itemFound.connect(self.itemFoundUpdateState)
        self._explorerDev.itemNotFound.connect(self.itemNotFoundUpdateState)
        self._explorerDev.searchingStopped.connect(self._stopSearching)
        self._searching = True

        criteria = {
            'name': self._name,
            'role': self._role,
            'state': self._state,
            'text': self._text,
            'matchType': self._matchType,
            'caseSensitiveMatch': self._caseSensitiveMatch
        }
        deep = False
        if self._method == self._DEEP_METHOD:
            deep = True
        try:
            explorerDev.find(self.Check(criteria), deep)
            self._lastNames.add(self._name)
            if self._role:
                self._lastRoles.add(self._role)
            if self._state:
                self._lastStates.add(self._state)
            self._manualUpdate = True
            self._refreshCompleters()
            self._manualUpdate = False
            self._saveState()
        except:
            self._stopSearching()
Example #8
0
    def _startSearching(self):
        '''
        Starts the searching process.
        '''
        self.buttonNext.setVisible(True)
        self.buttonNext.setEnabled(False)
        self.buttonSearch.setVisible(False)
        self.buttonStop.setEnabled(True)

        explorerDev = self._view.deviceTabAtIndex()
        if explorerDev is None:
            runWarning("No device is connected.", "Search unavailable")
            self.searchingStoppedUpdateState()
            return

        currentPath = explorerDev.selectedItemPath()
        if currentPath:
            if not explorerDev.itemExists(currentPath):
                self.searchingStoppedUpdateState()
                return
        else:
            runInformation("No item is selected.", "Search unavailable")
            self.searchingStoppedUpdateState()
            log.warning("Search cannot be performed since no reference item"
                        " is selected")
            return

        self._explorerDev = explorerDev
        self._explorerDev.startItemChanged.connect(self._startItemChanged)
        self._explorerDev.itemFound.connect(self.itemFoundUpdateState)
        self._explorerDev.itemNotFound.connect(self.itemNotFoundUpdateState)
        self._explorerDev.searchingStopped.connect(self._stopSearching)
        self._searching = True

        criteria = {
            'name': self._name,
            'role': self._role,
            'state': self._state,
            'text': self._text,
            'matchType': self._matchType,
            'caseSensitiveMatch': self._caseSensitiveMatch
        }
        deep = False
        if self._method == self._DEEP_METHOD:
            deep = True
        try:
            explorerDev.find(self.Check(criteria), deep)
            self._lastNames.add(self._name)
            if self._role:
                self._lastRoles.add(self._role)
            if self._state:
                self._lastStates.add(self._state)
            self._manualUpdate = True
            self._refreshCompleters()
            self._manualUpdate = False
            self._saveState()
        except:
            self._stopSearching()
Example #9
0
def runWarning(message, title="Warning"):
    '''
    Runs an warning message box with the given title and message.
    
    :param message: Message to be displayed inside the dialog
    :type message: string
    :param title:  Title of the dialog, if not provided, "Warning" is set
    :type title: string
    '''
    log.warning(message)
    return QtGui.QMessageBox.warning(utils.window(), title, message)
Example #10
0
def accessibilityExecMouse(processor, path, event, button, coordinates):
    '''
    Generates the given mouse event on an accessible of the specified path
    at the given coordinates using the specified mouse button.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path of the accessible
    :type path: tadek.core.accessible.Path
    :param event: A mouse event to generate
    :type event: string
    :param button: A mouse button to use
    :type button: string
    :param coordinates: A a mouse event coordinates
    :type coordinates: list
    :return: True if success, False otherwise
    :rtype: boolean
    '''
    log.debug(str(locals()))
    try:
        # Get object from the processor cache or from the accessible provider
        if processor.cache and processor.cache[-1] == path:
            a11y, obj, path = processor.cache
        else:
            a11y, obj = providers.accessible(path)
        # Reset the processor cache
        processor.cache = None
        if a11y is None:
            log.warning("Attempt of generating mouse event on non-accessible")
            return False
        button = getattr(a11y.buttonset, button, button)
        if event == 'CLICK':
            a11y.mouseClick(button=button, *coordinates)
        elif event == 'DOUBLE_CLICK':
            a11y.mouseDoubleClick(button=button, *coordinates)
        elif event == 'PRESS':
            a11y.mousePress(button=button, *coordinates)
        elif event == 'RELEASE':
            a11y.mouseRelease(button=button, *coordinates)
        elif event == 'ABSOLUTE_MOTION':
            a11y.mouseAbsoluteMotion(*coordinates)
        elif event == 'RELATIVE_MOTION':
            a11y.mouseRelativeMotion(*coordinates)
        else:
            log.warning("Unknown mouse event: %s", event)
            return False
    except:
        log.exception("Generate mouse event failure: %s" % path)
        # Reset the processor cache before leaving
        processor.cache = None
        return False
    return True
Example #11
0
def accessibilityExecMouse(processor, path, event, button, coordinates):
    '''
    Generates the given mouse event on an accessible of the specified path
    at the given coordinates using the specified mouse button.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path of the accessible
    :type path: tadek.core.accessible.Path
    :param event: A mouse event to generate
    :type event: string
    :param button: A mouse button to use
    :type button: string
    :param coordinates: A a mouse event coordinates
    :type coordinates: list
    :return: True if success, False otherwise
    :rtype: boolean
    '''
    log.debug(str(locals()))
    try:
        # Get object from the processor cache or from the accessible provider
        if processor.cache and processor.cache[-1] == path:
            a11y, obj, path = processor.cache
        else:
            a11y, obj = providers.accessible(path)
        # Reset the processor cache
        processor.cache = None
        if a11y is None:
            log.warning("Attempt of generating mouse event on non-accessible")
            return False
        button = getattr(a11y.buttonset, button, button)
        if event == 'CLICK':
            a11y.mouseClick(button=button, *coordinates)
        elif event == 'DOUBLE_CLICK':
            a11y.mouseDoubleClick(button=button, *coordinates)
        elif event == 'PRESS':
            a11y.mousePress(button=button, *coordinates)
        elif event == 'RELEASE':
            a11y.mouseRelease(button=button, *coordinates)
        elif event == 'ABSOLUTE_MOTION':
            a11y.mouseAbsoluteMotion(*coordinates)
        elif event == 'RELATIVE_MOTION':
            a11y.mouseRelativeMotion(*coordinates)
        else:
            log.warning("Unknown mouse event: %s", event)
            return False
    except:
        log.exception("Generate mouse event failure: %s" % path)
        # Reset the processor cache before leaving
        processor.cache = None
        return False
    return True
Example #12
0
 def _responseReceived(self, id):
     '''
     Emits 'responseReceived' or 'errorOccurred' signal.
     '''
     log.debug("Received message from '%s' device: %d" % (self.name, id))
     if id > protocol.DEFAULT_MSG_ID:
         self.responseReceived.emit(id)
     elif id == protocol.ERROR_MSG_ID:
         if self._connected:
             self.errorOccurred.emit()
         else:
             log.warning("Ignore error received from '%s' device: %s"
                          % (self.name, self.client.error()))
Example #13
0
 def _compileExpression(self, pattern, flags, toLog):
     '''
     Compiles regular expression provided as pattern to check its
     correctness (and remembers it) and logs a message on failure.
     '''
     msg = "Regular expression \"%s\" is incorrect"
     msgToLog = "Regular expression for %s is incorrect"
     try:
         return re.compile(pattern, flags)
     except:
         runWarning(msg % pattern[:-1], "Incorrect expression")
         log.warning(msgToLog, toLog)
         raise
Example #14
0
 def _responseReceived(self, id):
     '''
     Emits 'responseReceived' or 'errorOccurred' signal.
     '''
     log.debug("Received message from '%s' device: %d" % (self.name, id))
     if id > protocol.DEFAULT_MSG_ID:
         self.responseReceived.emit(id)
     elif id == protocol.ERROR_MSG_ID:
         if self._connected:
             self.errorOccurred.emit()
         else:
             log.warning("Ignore error received from '%s' device: %s" %
                         (self.name, self.client.error()))
Example #15
0
 def _compileExpression(self, pattern, flags, toLog):
     '''
     Compiles regular expression provided as pattern to check its
     correctness (and remembers it) and logs a message on failure.
     '''
     msg = "Regular expression \"%s\" is incorrect"
     msgToLog = "Regular expression for %s is incorrect"
     try:
         return re.compile(pattern, flags)
     except:
         runWarning(msg % pattern[:-1], "Incorrect expression")
         log.warning(msgToLog, toLog)
         raise
Example #16
0
 def loadState(self):
     '''
     Restores paths from configuration.
     '''
     enabled = config.getList(self._CONFIG_NAME,
                              self._CONFIG_SECTION_LOCATIONS, "enabled", [])
     disabled = config.getList(self._CONFIG_NAME,
                               self._CONFIG_SECTION_LOCATIONS, "disabled",
                               [])
     for path in disabled:
         message = self._addLocation(path)
         if message:
             log.warning(message)
     for path in enabled:
         message = self._addLocation(path)
         if message:
             log.warning(message)
         else:
             self._locItems[path].setCheckState(0, QtCore.Qt.Checked)
     self._loaded = True
Example #17
0
 def loadState(self):
     '''
     Restores paths from configuration.
     ''' 
     enabled = config.getList(self._CONFIG_NAME,
                              self._CONFIG_SECTION_LOCATIONS,
                              "enabled", [])
     disabled = config.getList(self._CONFIG_NAME,
                               self._CONFIG_SECTION_LOCATIONS,
                               "disabled", [])
     for path in disabled:
         message = self._addLocation(path)
         if message:
             log.warning(message)
     for path in enabled:
         message = self._addLocation(path)
         if message:
             log.warning(message)
         else:
             self._locItems[path].setCheckState(0, QtCore.Qt.Checked)
     self._loaded = True
Example #18
0
    def __init__(self, conf=None):
        '''
        Initializes daemon by starting and configuring a server.

        :param conf: A path to a daemon configuration file
        :type conf: string
        '''
        if conf is not None:
            if os.path.isfile(conf):
                config.update('daemon', conf)
            else:
                log.warning("Configuration file %s does not exist."
                            " Skipped" % conf)
        port = config.getInt('daemon', 'connection', 'port')
        ip = config.get('daemon', 'connection', 'address')
        if ip is None:
            log.warning("No attribute IP in daemon configuration file. "
                        "Using default value %s" % DEFAULT_IP)
            config.set('daemon', 'connection', 'address', DEFAULT_IP)
            ip = DEFAULT_IP
        if port is None:
            log.warning("No attribute port in daemon configuration file. "
                        "Using default value %d" % DEFAULT_PORT)
            config.set('daemon', 'connection', 'port', DEFAULT_PORT)
            port = DEFAULT_PORT
        server.Server.__init__(self, (ip, port))
        info = protocol.create(protocol.MSG_TYPE_RESPONSE,
                               protocol.MSG_TARGET_SYSTEM,
                               protocol.MSG_NAME_INFO,
                               version=config.VERSION,
                               locale=(locale.getdefaultlocale()[0] or ''),
                               extensions=protocol.getExtensions(),
                               status=True)
        self._infoData = info.marshal()
Example #19
0
 def _responseRefresh(self, response, expanded=False):
     '''
     Refreshes an accessible tree item from the response.
     '''
     path = response.accessible.path
     log.debug("Refreshing accessible tree item: %s" % path)
     accessible = response.accessible
     item = self._pathItem(path)
     if not item:
         # Top level items should not change
         parent = self._pathItem(path.parent())
         if not parent:
             log.warning("Invalid accessible tree path: %s" % path)
             return False
         item = self._accessibleItem(accessible, parent)
     if not response.status:
         self._disableAccessibleItem(item)
         return False
     else:
         item.setDisabled(False)
     # Update the item
     self._setAccessibleItem(accessible, item)
     # Checks if display the item in the view
     if self.selectedItemPath() == path:
         self._view.display(accessible)
     if expanded and item.isExpanded():
         for idx in xrange(accessible.count, item.childCount()):
             item.takeChild(idx)
         for idx in xrange(accessible.count):
             childPath = path.child(idx)
             id = self.device.requestDevice("requestAccessible", childPath,
                                            0)
             self._registerRequest(id, self._responseRefresh, True)
             self._runProgress(id,
                               "Refreshing path %s" % childPath,
                               timeout=self._TIMEOUT_REFRESH)
     elif accessible.count and not item.childCount():
         HighlightableItem(item)
     return True
Example #20
0
def accessibilityExecAction(processor, path, action):
    '''
    Executes the specified action of an accessible given by the path.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path of the accessible
    :type path: tadek.core.accessible.Path
    :param action: An accessible action to execute
    :type action: string
    :return: True if success, False otherwise
    :rtype: boolean
    '''
    log.debug(str(locals()))
    try:
        # Get object from the processor cache or from the accessible provider
        if processor.cache and processor.cache[-1] == path:
            a11y, obj, path = processor.cache
        else:
            a11y, obj = providers.accessible(path)
        # Reset the processor cache
        processor.cache = None
        if obj is None:
            log.warning("Attempt of executing action of non-accessible")
            return False
        if action == A11Y_ACTION_FOCUS:
            status = a11y.grabFocus(obj)
        else:
            status = a11y.doAction(obj, getattr(a11y.actionset, action,
                                                action))
    except:
        log.exception("Execute accessible action error: %s" % path)
        # Reset the processor cache before leaving
        processor.cache = None
        return False
    if not status:
        log.info("Execute accessible action failure: %s" % path)
    return status
Example #21
0
 def _responseRefresh(self, response, expanded=False):
     '''
     Refreshes an accessible tree item from the response.
     '''
     path = response.accessible.path
     log.debug("Refreshing accessible tree item: %s" % path)
     accessible = response.accessible
     item = self._pathItem(path)
     if not item:
         # Top level items should not change
         parent = self._pathItem(path.parent())
         if not parent:
             log.warning("Invalid accessible tree path: %s" % path)
             return False
         item = self._accessibleItem(accessible, parent)
     if not response.status:
         self._disableAccessibleItem(item)
         return False
     else:
         item.setDisabled(False)
     # Update the item
     self._setAccessibleItem(accessible, item)
     # Checks if display the item in the view
     if self.selectedItemPath() == path:
         self._view.display(accessible)
     if expanded and item.isExpanded():
         for idx in xrange(accessible.count, item.childCount()):
             item.takeChild(idx)
         for idx in xrange(accessible.count):
             childPath = path.child(idx)
             id = self.device.requestDevice("requestAccessible",
                                            childPath, 0)
             self._registerRequest(id, self._responseRefresh, True)
             self._runProgress(id, "Refreshing path %s" % childPath,
                               timeout=self._TIMEOUT_REFRESH)
     elif accessible.count and not item.childCount():
         HighlightableItem(item)
     return True
Example #22
0
def accessibilityExecAction(processor, path, action):
    '''
    Executes the specified action of an accessible given by the path.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path of the accessible
    :type path: tadek.core.accessible.Path
    :param action: An accessible action to execute
    :type action: string
    :return: True if success, False otherwise
    :rtype: boolean
    '''
    log.debug(str(locals()))
    try:
        # Get object from the processor cache or from the accessible provider
        if processor.cache and processor.cache[-1] == path:
            a11y, obj, path = processor.cache
        else:
            a11y, obj = providers.accessible(path)
        # Reset the processor cache
        processor.cache = None
        if obj is None:
            log.warning("Attempt of executing action of non-accessible")
            return False
        if action == A11Y_ACTION_FOCUS:
            status = a11y.grabFocus(obj)
        else:
            status = a11y.doAction(obj, getattr(a11y.actionset, action, action))
    except:
        log.exception("Execute accessible action error: %s" % path)
        # Reset the processor cache before leaving
        processor.cache = None
        return False
    if not status:
        log.info("Execute accessible action failure: %s" % path)
    return status
Example #23
0
 def _responseExpand(self, response):
     '''
     Expands an accessible tree item from the response.
     '''
     path = response.accessible.path
     log.debug("Expanding accessible tree item: %s" % path)
     item = self._pathItem(path)
     if not item:
         log.warning("EXPAND: Invalid accessible tree path: %s" % path)
         return False
     if not response.status:
         return False
     accessible = response.accessible
     # Update the item
     self._setAccessibleItem(accessible, item)
     item.setDisabled(False)
     # Request for children
     for idx in xrange(accessible.count):
         id = self.device.requestDevice("requestAccessible",
                                        path.child(idx), 0)
         self._registerRequest(id, self._responseAdd)
     for i in xrange(self._COLUMN_COUNT):
         self._treeWidget.resizeColumnToContents(i)
     return True
Example #24
0
 def _responseAdd(self, response):
     '''
     Adds an item to the acccessible tree from the response.
     '''
     path = response.accessible.path
     log.debug("Adding accessible tree item: %s" % path)
     parent = path.parent()
     if parent.tuple:
         parent = self._pathItem(parent)
         if not parent:
             log.warning("Invalid accessible tree path: %s" % path)
             return False
     else:
         parent = self._treeWidget
     accessible = response.accessible
     if response.status:
         self._accessibleItem(accessible, parent)
     else:
         item = HighlightableItem(parent)
         item.setText(0, str(accessible.index))
         item.setDisabled(True)
     for i in xrange(self._COLUMN_COUNT):
         self._treeWidget.resizeColumnToContents(i)
     return True
Example #25
0
def accessibilityExecKeyboard(processor, path, keycode, modifiers):
    '''
    Generates a keyboard event for the given key code using the specified
    modifiers for an accessible of the given path.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path of the accessible
    :type path: tadek.core.accessible.Path
    :param keycode: A code of a key to generate event of
    :type keycode: integer
    :param modifiers:  A list of key codes to use as modifiers
    :type modifiers: list
    :return: True if success, False otherwise
    :rtype: boolean
    '''
    log.debug(str(locals()))
    try:
        # Get object from the processor cache or from the accessible provider
        if processor.cache and processor.cache[-1] == path:
            a11y, obj, path = processor.cache
        else:
            a11y, obj = providers.accessible(path)
        # Reset the processor cache
        processor.cache = None
        if a11y is None:
            log.warning("Attempt of generating keyboard"
                        " event on non-accessible")
            return False
        a11y.keyboardEvent(keycode, modifiers)
    except:
        log.exception("Generate keyboard event error: %s" % path)
        # Reset the processor cache before leaving
        processor.cache = None
        return False
    return True
Example #26
0
 def _responseAdd(self, response):
     '''
     Adds an item to the acccessible tree from the response.
     '''
     path = response.accessible.path
     log.debug("Adding accessible tree item: %s" % path)
     parent = path.parent()
     if parent.tuple:
         parent = self._pathItem(parent)
         if not parent:
             log.warning("Invalid accessible tree path: %s" % path)
             return False
     else:
         parent = self._treeWidget
     accessible = response.accessible
     if response.status:
         self._accessibleItem(accessible, parent)
     else:
         item = HighlightableItem(parent)
         item.setText(0, str(accessible.index))
         item.setDisabled(True)
     for i in xrange(self._COLUMN_COUNT):
         self._treeWidget.resizeColumnToContents(i)
     return True
Example #27
0
 def _responseExpand(self, response):
     '''
     Expands an accessible tree item from the response.
     '''
     path = response.accessible.path
     log.debug("Expanding accessible tree item: %s" % path)
     item = self._pathItem(path)
     if not item:
         log.warning("EXPAND: Invalid accessible tree path: %s" % path)
         return False
     if not response.status:
         return False
     accessible = response.accessible
     # Update the item
     self._setAccessibleItem(accessible, item)
     item.setDisabled(False)
     # Request for children
     for idx in xrange(accessible.count):
         id = self.device.requestDevice("requestAccessible",
                                        path.child(idx), 0)
         self._registerRequest(id, self._responseAdd)
     for i in xrange(self._COLUMN_COUNT):
         self._treeWidget.resizeColumnToContents(i)
     return True
Example #28
0
def accessibilityExecKeyboard(processor, path, keycode, modifiers):
    '''
    Generates a keyboard event for the given key code using the specified
    modifiers for an accessible of the given path.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path of the accessible
    :type path: tadek.core.accessible.Path
    :param keycode: A code of a key to generate event of
    :type keycode: integer
    :param modifiers:  A list of key codes to use as modifiers
    :type modifiers: list
    :return: True if success, False otherwise
    :rtype: boolean
    '''
    log.debug(str(locals()))
    try:
        # Get object from the processor cache or from the accessible provider
        if processor.cache and processor.cache[-1] == path:
            a11y, obj, path = processor.cache
        else:
            a11y, obj = providers.accessible(path)
        # Reset the processor cache
        processor.cache = None
        if a11y is None:
            log.warning("Attempt of generating keyboard"
                        " event on non-accessible")
            return False
        a11y.keyboardEvent(keycode, modifiers)
    except:
        log.exception("Generate keyboard event error: %s" % path)
        # Reset the processor cache before leaving
        processor.cache = None
        return False
    return True