Exemple #1
0
    def _loadState(self):
        """
        Loads window's settings from configuration.
        """
        log.debug("Loading main window's settings")
        if self._views:
            index = config.getInt(self._NAME, "views", "last", 0)
            view = self._views[0]
            try:
                view = self._views[index]
            except IndexError:
                log.error("Failed to load view #%d" % index)
            view.activate()

        section = "geometry"
        self.window.setGeometry(
            config.getInt(self._NAME, section, "window_x", 50),
            config.getInt(self._NAME, section, "window_y", 50),
            config.getInt(self._NAME, section, "window_w", 800),
            config.getInt(self._NAME, section, "window_h", 600),
        )
        state = config.get(self._NAME, section, "window_state")
        if state:
            byteData = QtCore.QByteArray.fromBase64(state)
            self.window.restoreState(byteData)
Exemple #2
0
def runError(message, title="Error"):
    '''
    Runs an error 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, "Error" is set
    :type title: string
    '''
    log.error(message)
    return QtGui.QMessageBox.critical(utils.window(), title, message)
Exemple #3
0
 def _errorOccurred(self):
     '''
     Disconnects a device in case of a ConnectionLostError.
     '''
     dev = self.sender()
     err = dev.getError()
     log.error("Error occurred in '%s' device: %s" % (dev.name, err))
     if isinstance(err, client.ConnectionLostError):
         try:
             dialogs.runError("'%s' device disconnected:\n%s" %
                              (dev.name, err))
             self._errors[dev] = err
             self._updateConnectionState(False, dev)
         except ConnectionError, ex:
             log.error("Connection Error (%s): %s" % (dev, ex))
Exemple #4
0
 def _errorOccurred(self):
     '''
     Disconnects a device in case of a ConnectionLostError.
     '''
     dev = self.sender()
     err = dev.getError()
     log.error("Error occurred in '%s' device: %s" % (dev.name, err))
     if isinstance(err, client.ConnectionLostError):
         try:
             dialogs.runError("'%s' device disconnected:\n%s"
                              % (dev.name, err))
             self._errors[dev] = err
             self._updateConnectionState(False, dev)
         except ConnectionError, ex:
             log.error("Connection Error (%s): %s" % (dev, ex))
Exemple #5
0
    def onRequest(self, data):
        '''
        Processes the received request data and returns an appropriate response.

        :param data: Request data
        :type data: string
        :return: Processed request and generated response instances
        :rtype: tuple
        '''
        log.debug("Handling request:\n%s", data)
        request, response = server.Handler.onRequest(self, data)
        if response is None:
            try:
                if request.type != protocol.MSG_TYPE_REQUEST:
                    raise protocol.UnsupportedMessageError(
                        request.type, request.target, request.name,
                        *request.getParams())
                response = self._processor(request)
            except protocol.UnsupportedMessageError, err:
                log.error(err)
            except:
Exemple #6
0
    def onRequest(self, data):
        '''
        Processes the received request data and returns an appropriate response.

        :param data: Request data
        :type data: string
        :return: Processed request and generated response instances
        :rtype: tuple
        '''
        log.debug("Handling request:\n%s", data)
        request, response = server.Handler.onRequest(self, data)
        if response is None:
            try:
                if request.type != protocol.MSG_TYPE_REQUEST:
                    raise protocol.UnsupportedMessageError(request.type,
                                                           request.target,
                                                           request.name,
                                                           *request.getParams())
                response = self._processor(request)
            except protocol.UnsupportedMessageError, err:
                log.error(err)
            except:
Exemple #7
0
    def _loadState(self):
        '''
        Loads window's settings from configuration.
        '''
        log.debug("Loading main window's settings")
        if self._views:
            index = config.getInt(self._NAME, "views", "last", 0)
            view = self._views[0]
            try:
                view = self._views[index]
            except IndexError:
                log.error("Failed to load view #%d" % index)
            view.activate()

        section = "geometry"
        self.window.setGeometry(
            config.getInt(self._NAME, section, "window_x", 50),
            config.getInt(self._NAME, section, "window_y", 50),
            config.getInt(self._NAME, section, "window_w", 800),
            config.getInt(self._NAME, section, "window_h", 600))
        state = config.get(self._NAME, section, "window_state")
        if state:
            byteData = QtCore.QByteArray.fromBase64(state)
            self.window.restoreState(byteData)
def accessibilitySearch(processor,
                        path,
                        method,
                        name=None,
                        description=None,
                        role=None,
                        index=None,
                        count=None,
                        action=None,
                        relation=None,
                        state=None,
                        text=None,
                        nth=0):
    '''
    Searches an accessible using the given method according to specified
    accessible parameters.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path of a demanded accessible
    :type path: tadek.core.accessible.Path
    :param method: A search method of accessible
    :type method: string
    :param name: A name of searched accessible or None
    :type name: string or NoneType
    :param description: A description of searched accessible or None
    :type description: string or NoneType
    :param role: A role of searched accessible or None
    :type role: string or NoneType
    :param index: An index of searched accessible or None
    :type index: integer or NoneType
    :param count: A child count of searched accessible or None
    :type count: string or NoneType
    :param action: An action of searched accessible or None
    :type action: string or NoneType
    :param relation: A relation of searched accessible or None
    :type relation: string or NoneType
    :param state: A state of searched accessible or None
    :type state: string or NoneType
    :param text: Text of searched accessible or None
    :type text: string or NoneType
    :param nth: A nth matched accessible
    :type nth: integer
    :return: A searching accessible status and an accessible of the given path
    :rtype: tuple
    '''
    log.debug(str(locals()))

    def matchString(pattern, string):
        '''
        Checks if the give string matches the regular expression pattern.
        '''
        if string is None:
            return False
        match = pattern.match(string)
        return match is not None and match.span() == (0, len(string))

    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 and path.tuple:
            log.info("Accessible of requested path not found: %s" % path)
            return False, Accessible(path)
        if method == protocol.MHD_SEARCH_SIMPLE:
            provider = providers.Children
        elif method == protocol.MHD_SEARCH_BACKWARDS:
            provider = providers.ChildrenBackwards
        elif method == protocol.MHD_SEARCH_DEEP:
            provider = providers.Descendants
        else:
            log.error("Unknown search method: %s" % method)
            return False, Accessible(Path())
        if name and name[0] == '&':
            name = re.compile(name[1:], re.DOTALL)
            cmpName = matchString
        else:
            cmpName = lambda pattern, string: pattern == string
        if description and description[0] == '&':
            description = re.compile(description[1:], re.DOTALL)
            cmpDesc = matchString
        else:
            cmpDesc = lambda pattern, string: pattern == string
        if text and text[0] == '&':
            text = re.compile(text[1:], re.DOTALL)
            cmpText = matchString
        else:
            cmpText = lambda pattern, string: pattern == string
        i = 0
        for a11y, obj, path in provider(a11y, obj, path):
            if index is not None and index != path.index():
                continue
            if obj is None:
                if name is not None and not cmpName(name, a11y.name):
                    continue
                if count is not None and a11y.countChildren() != count:
                    continue
            else:
                if name is not None and not cmpName(name, a11y.getName(obj)):
                    continue
                if (description is not None and
                        not cmpDesc(description, a11y.getDescription(obj))):
                    continue
                if role is not None and a11y.getRoleName(obj) != role:
                    continue
                if count is not None and a11y.countChildren(obj) != count:
                    continue
                if action is not None:
                    found = False
                    for act in a11y.actionNames(obj):
                        if action == act:
                            found = True
                            break
                    if not found:
                        continue
                if relation is not None:
                    found = False
                    for rel in a11y.relationNames(obj):
                        if relation == rel:
                            found = True
                            break
                    if not found:
                        continue
                if (state is not None and not a11y.inState(
                        obj, getattr(a11y.stateset, state, None))):
                    continue
                if text is not None and not cmpText(text, a11y.getText(obj)):
                    continue
            i += 1
            if nth < i:
                processor.cache = (a11y, obj, path)
                return True, dumpAccessible(a11y,
                                            obj,
                                            path,
                                            depth=0,
                                            name=True,
                                            description=True,
                                            role=True,
                                            count=True,
                                            position=True,
                                            size=True,
                                            text=True,
                                            value=True,
                                            actions=True,
                                            states=True,
                                            attributes=True,
                                            relations=True)
    except:
        log.exception("Search an accessible of specified parmaters error")
        # Reset the processor cache before leaving
        processor.cache = None
        return False, Accessible(path)
    log.info("Search an accessible of specified parmaters failure")
    return False, Accessible(path)
Exemple #9
0
def accessibilitySearch(processor, path, method, name=None, description=None,
                        role=None, index=None, count=None, action=None,
                        relation=None, state=None, text=None, nth=0):
    '''
    Searches an accessible using the given method according to specified
    accessible parameters.

    :param processor: A processor object calling the function
    :type processor: Processor
    :param path: A path of a demanded accessible
    :type path: tadek.core.accessible.Path
    :param method: A search method of accessible
    :type method: string
    :param name: A name of searched accessible or None
    :type name: string or NoneType
    :param description: A description of searched accessible or None
    :type description: string or NoneType
    :param role: A role of searched accessible or None
    :type role: string or NoneType
    :param index: An index of searched accessible or None
    :type index: integer or NoneType
    :param count: A child count of searched accessible or None
    :type count: string or NoneType
    :param action: An action of searched accessible or None
    :type action: string or NoneType
    :param relation: A relation of searched accessible or None
    :type relation: string or NoneType
    :param state: A state of searched accessible or None
    :type state: string or NoneType
    :param text: Text of searched accessible or None
    :type text: string or NoneType
    :param nth: A nth matched accessible
    :type nth: integer
    :return: A searching accessible status and an accessible of the given path
    :rtype: tuple
    '''
    log.debug(str(locals()))
    def matchString(pattern, string):
        '''
        Checks if the give string matches the regular expression pattern.
        '''
        if string is None:
            return False
        match = pattern.match(string)
        return match is not None and match.span() == (0, len(string))
    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 and path.tuple:
            log.info("Accessible of requested path not found: %s" % path)
            return False, Accessible(path)
        if method == protocol.MHD_SEARCH_SIMPLE:
            provider = providers.Children
        elif method == protocol.MHD_SEARCH_BACKWARDS:
            provider = providers.ChildrenBackwards
        elif method == protocol.MHD_SEARCH_DEEP:
            provider = providers.Descendants
        else:
            log.error("Unknown search method: %s" % method)
            return False, Accessible(Path())
        if name and name[0] == '&':
            name = re.compile(name[1:], re.DOTALL)
            cmpName = matchString
        else:
            cmpName = lambda pattern, string: pattern == string
        if description and description[0] == '&':
            description = re.compile(description[1:], re.DOTALL)
            cmpDesc = matchString
        else:
            cmpDesc = lambda pattern, string: pattern == string
        if text and text[0] == '&':
            text = re.compile(text[1:], re.DOTALL)
            cmpText = matchString
        else:
            cmpText = lambda pattern, string: pattern == string
        i = 0
        for a11y, obj, path in provider(a11y, obj, path):
            if index is not None and index != path.index():
                continue
            if obj is None:
                if name is not None and not cmpName(name, a11y.name):
                    continue
                if count is not None and a11y.countChildren() != count:
                    continue
            else:
                if name is not None and not cmpName(name, a11y.getName(obj)):
                    continue
                if (description is not None and not
                    cmpDesc(description, a11y.getDescription(obj))):
                    continue
                if role is not None and a11y.getRoleName(obj) != role:
                    continue
                if count is not None and a11y.countChildren(obj) != count:
                    continue
                if action is not None:
                    found = False
                    for act in a11y.actionNames(obj):
                        if action == act:
                            found = True
                            break
                    if not found:
                        continue
                if relation is not None:
                    found = False
                    for rel in a11y.relationNames(obj):
                        if relation == rel:
                            found = True
                            break
                    if not found:
                        continue
                if (state is not None and not
                    a11y.inState(obj, getattr(a11y.stateset, state, None))):
                    continue
                if text is not None and not cmpText(text, a11y.getText(obj)):
                    continue
            i += 1
            if nth < i:
                processor.cache = (a11y, obj, path)
                return True, dumpAccessible(a11y, obj, path, depth=0, name=True,
                                        description=True, role=True, count=True,
                                        position=True, size=True, text=True,
                                        value=True, actions=True, states=True,
                                        attributes=True, relations=True)
    except:
        log.exception("Search an accessible of specified parmaters error")
        # Reset the processor cache before leaving
        processor.cache = None
        return False, Accessible(path)
    log.info("Search an accessible of specified parmaters failure")
    return False, Accessible(path)