示例#1
0
 def _itemPath(self, item):
     '''
     Returns a path to the given accessible item.
     '''
     path = []
     parent = item.parent()
     while parent:
         path.insert(0, parent.indexOfChild(item))
         item = parent
         parent = item.parent()
     path.insert(0, self._treeWidget.indexOfTopLevelItem(item))
     return accessible.Path(*path)
示例#2
0
 def expandAll(self):
     '''
     Expands all accessible items recursively.
     '''
     if not self._active:
         return
     log.debug("Expanding all accessible items recursively: %s" %
               self.device)
     path = accessible.Path()
     id = self.device.requestDevice("requestAccessible", path, -1)
     self._registerRequest(id, self._responseExpandAll)
     self._runProgress(id,
                       "Expanding path: %s" % path,
                       timeout=self._TIMEOUT_EXPAND_ALL)
示例#3
0
    def moveMouseTo(self, device, x, y):
        '''
        Simulates a mouse absolute motion to the given x and y coordinates.

        :param device: A device to perform the operation on
        :type device: tadek.connection.device.Device
        :param x: A left-hand oriented horizontal coordinate
        :type x: integer
        :param y: A left-hand oriented vertical coordinate
        :type y: integer
        :return: Event completion status
        :rtype: boolean
        '''
        if not isinstance(x, int) or not isinstance(y, int):
            raise TypeError
        return device.mouseEvent(accessible.Path(0), x, y, "LEFT",
                                 "ABSOLUTE_MOTION")
示例#4
0
 def saveAll(self):
     '''
     Sends a recursive request for root accessible that will be dumped
     to file.
     '''
     if not self._active:
         return
     filePath = dialogs.runSaveFile("XML files (*.xml);;All files (*)")
     if filePath is None:
         return
     path = accessible.Path()
     log.debug("Dumping accessible %s to file '%s'" % (path, filePath))
     id = self.device.requestDevice("requestAccessible", path, -1, all=True)
     self._registerRequest(id, self._responseSave, filePath)
     self._runProgress(id,
                       "Dumping path: %s" % path,
                       timeout=self._TIMEOUT_DUMP_ALL)
示例#5
0
 def refreshAll(self):
     '''
     Refreshes all accessible trees.
     '''
     if not self._active:
         return
     log.debug("Refreshing device accessible tree: %s" % self.device)
     self._manualSelect = True
     self._treeWidget.clear()
     self._view.clear()
     path = accessible.Path()
     id = self.device.requestDevice("requestAccessible", path, 0)
     self._registerRequest(id, self._responseRefreshAll)
     self._runProgress(id,
                       "Refreshing path: %s" % path,
                       timeout=self._TIMEOUT_REFRESH)
     self._manualSelect = False
示例#6
0
    def pressMouseAt(self, device, x, y, button="LEFT"):
        '''
        Simulates a mouse press at the given x and y coordinates.

        :param device: A device to perform the operation on
        :type device: tadek.connection.device.Device
        :param x: A left-hand oriented horizontal coordinate
        :type x: integer
        :param y: A left-hand oriented vertical coordinate
        :type y: integer
        :param button: A mouse button simulating the event
        :type button: string
        :return: Event completion status
        :rtype: boolean
        '''
        if not isinstance(x, int) or not isinstance(y, int):
            raise TypeError
        return device.mouseEvent(accessible.Path(0), x, y, button, "PRESS")
示例#7
0
    def search(self, device):
        '''
        Performs a searching of a widget pointed by the path.

        :param device: A device to perform the operation on
        :type device: tadek.connection.device.Device
        :return: A searching widget or None if fails
        :rtype: Widget or NoneType
        '''
        if self._base is None:
            acc = accessible.Accessible(accessible.Path())
            acc.device = device
        else:
            acc = self._base.getPath().search(device)
        for searcher in self._searchers:
            if acc is None:
                return None
            acc = searcher.find(acc)
        return acc
示例#8
0
    def generateKey(self, device, key, modifiers=()):
        '''
        Generates a keyboard event for the given key.

        :param device: A device to perform the operation on
        :type device: tadek.connection.device.Device
        :param key: A key code or string representation
        :type key: integer or string
        :param modifiers: A list of modifier key codes or names
        :type modifiers: list or tuple
        :return: Event completion status
        :rtype: boolean
        '''
        if isinstance(key, basestring):
            key = constants.KEY_SYMS.get(key) or ord(key)
        codes = []
        for mkey in modifiers:
            if isinstance(mkey, basestring):
                mkey = constants.KEY_CODES.get(mkey)
            codes.append(mkey)
        return device.keyboardEvent(accessible.Path(0), key, codes)
示例#9
0
def performRequest(device, options):
    '''
    Performs a request on the given device using the specified options.

    :param device: A device to perform the request on
    :type device: tadek.connection.device.Device
    :param options: Options representing the request
    :type params: dictionary
    '''
    log.debug("Perform a request on '%s' device using options: %s" %
              (device, options))
    path = accessible.Path(*options.pop("path").split('/')[1:])
    device.connect()
    try:
        if "action" in options:
            status = device.doAccessible(path, options["action"])
        elif "set-text" in options:
            text = options["set-text"]
            status = device.setAccessible(path, text=text)
        elif "set-text-file" in options:
            fn = options["set-text-file"]
            if not os.path.isfile(fn):
                exitWithError("There is no such file: %s" % fn)
            fd = None
            try:
                fd = open(fn)
                text = fd.read()
            finally:
                if fd:
                    fd.close()
            status = device.setAccessible(path, text=text)
        elif "set-value" in options:
            value = float(options["set-value"])
            status = device.setAccessible(path, value=value)
        elif "mouse-click" in options:
            x, y = options["mouse-click"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y), button, "CLICK")
        elif "mouse-double-click" in options:
            x, y = options["mouse-double-click"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y), button,
                                       "DOUBLE_CLICK")
        elif "mouse-press" in options:
            x, y = options["mouse-press"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y), button, "PRESS")
        elif "mouse-release" in options:
            x, y = options["mouse-release"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y), button, "RELEASE")
        elif "mouse-absolute-motion" in options:
            x, y = options["mouse-absolute-motion"]
            status = device.mouseEvent(path, int(x), int(y), '',
                                       "ABSOLUTE_MOTION")
        elif "mouse-relative-motion" in options:
            x, y = options["mouse-relative-motion"]
            status = device.mouseEvent(path, int(x), int(y), '',
                                       "RELATIVE_MOTION")
        elif "key" in options:
            key = options["key"].upper()
            if key in constants.KEY_SYMS:
                key = constants.KEY_SYMS[key]
            elif len(key) == 1:
                key = ord(key)
            elif key.startswith("0X"):
                key = int(key, 16)
            else:
                key = int(key)
            if "modifiers" in options:
                modifiers = [
                    constants.KEY_CODES[mod] for mod in options["modifiers"]
                ]
            else:
                modifiers = []
            status = device.keyboardEvent(path, key, modifiers)
        elif "dump" in options or "dump-all" in options:
            all = False
            if "dump" in options:
                depth = int(options["dump"])
            else:
                depth = -1
            if "output" in options:
                fn = options["output"]
                all = True
            obj = device.getAccessible(path, depth, all=all)
            if obj is None:
                exitWithStatus("There is no such path: %s" % path, 1)
            if all:
                printSeparator()
                utils.saveXml(obj.marshal(), fn)
                exitWithStatus("Dump saved to file: %s" % fn)
            else:
                printAccessibleTree(obj)
                exitWithStatus()
        else:
            for name in (["all"] + [attr[0] for attr in _ATTRS_EXTRA]):
                if name in options:
                    break
            else:
                exitWithError("Invalid request options: %s" % options)
            obj = device.getAccessible(path, 0, **{name: True})
            if obj is None:
                exitWithStatus("There is no such path: %s" % path, 1)
            printAccessibleDetails(obj, name)
            exitWithStatus()
    finally:
        if device.isConnected():
            device.disconnect()
    printSeparator()
    if status:
        exitWithStatus("SUCCESS")
    else:
        exitWithStatus("FAILURE", 1)