Example #1
0
 def grabFocus(self):
     '''
     Dialogs are not focusable, so emulate the behavior by finding the first
     focusable child of this Dialog and calling grabFocus on it
     '''
     try:
         utils.findDescendant(self, lambda x: x.focusable and x.showing).grabFocus()
     except:
         pass
Example #2
0
    def select(self, name, logName=None, log=True):
        'Select a tab'

        # we don't use self.findPageTab or self.__getattr__('findPageTab')
        # here because findPageTab tries to promote tabs to specific classes
        # which may have constructors that look for widgets that are
        # lazy-loaded, causing bogus searchErrors.
        tab = utils.findDescendant(self, lambda x: x.role == pyatspi.ROLE_PAGE_TAB and utils.equalsOrMatches(x.name, name) and x.showing, \
            recursive=False)

        # do the work of actually selecting the tab.  this should cause
        # lazy-loaded widgets to be loaded.
        self.selectChild(tab.getIndexInParent())

        # now search for the tab as if we haven't done any of the above, but
        # don't do any logging
        tab = self.findPageTab(name, logName=logName)

        # now that we have the (possibly promoted) tab, do the logging
        if log:  # we need to log after the find() because the tab might be promoted and have a different logName
            procedurelogger.action('Select the %s.' % tab, self)

        sleep(config.MEDIUM_DELAY)

        return tab
Example #3
0
    def select(self, name, logName=None, log=True):
        'Select a tab'

        # we don't use self.findPageTab or self.__getattr__('findPageTab') 
        # here because findPageTab tries to promote tabs to specific classes 
        # which may have constructors that look for widgets that are 
        # lazy-loaded, causing bogus searchErrors.
        tab = utils.findDescendant(self, lambda x: x.role == pyatspi.ROLE_PAGE_TAB and utils.equalsOrMatches(x.name, name) and x.showing, \
            recursive=False)

        # do the work of actually selecting the tab.  this should cause
        # lazy-loaded widgets to be loaded.
        self.selectChild(tab.getIndexInParent())

        # now search for the tab as if we haven't done any of the above, but 
        # don't do any logging
        tab = self.findPageTab(name, logName=logName)

        # now that we have the (possibly promoted) tab, do the logging
        if log: # we need to log after the find() because the tab might be promoted and have a different logName
            procedurelogger.action('Select the %s.' % tab, self)

        sleep(config.MEDIUM_DELAY)

        return tab
Example #4
0
    def _open(self, path):
        'Open a menu without any logging'

        parent = self
        for menu in path:
            parent = utils.findDescendant(parent, lambda x: (x.role == pyatspi.ROLE_MENU or x.role == pyatspi.ROLE_MENU_ITEM) and \
                utils.equalsOrMatches(x.name, menu) and x.showing, recursive=False)
            parent.click() # open the menu so that the children are showing

        return parent # return the last menu
Example #5
0
    def select(self, path, log=True):
        '''
        Select a menu item

        Path must be an array of strings; regular expressions are not supported.
        '''

        if log:
            procedurelogger.action('Under the %s menu, select %s.' % (' => '.join(path[0:-1]), path[-1].replace('...', '')), self)

        parent = self._open(path[0:-1]) # the last item in the path is excluded because we're going to click that item

        item = utils.findDescendant(parent, lambda x: (x.role == pyatspi.ROLE_MENU_ITEM or x.role == pyatspi.ROLE_CHECK_MENU_ITEM) \
            and utils.equalsOrMatches(x.name, path[-1]) and x.showing, recursive=False)
        item.click()

        return item
Example #6
0
    def findAlert(self, text, logText=None, retry=True, raiseException=True):
        '''
        Search for an alert

        Alerts typically have no name, so we have to search for them by their content. 
        We look for alerts that are showing and have within them a label that contains 
        the given text.
        '''

        if logText is None:
            logText = text

        if raiseException:
            procedurelogger.expectedResult('An alert appears: %s' % logText)

        def alertHasLabelContainingText(alert):
            return alert.role == pyatspi.ROLE_ALERT and alert.showing and \
                alert.findLabel(text, retry=False, recursive=True, raiseException=False) is not None

        return utils.findDescendant(self, alertHasLabelContainingText, retry=retry, recursive=False, raiseException=raiseException)
Example #7
0
    def select(self, path, log=True):
        '''
        Select a menu item

        Path must be an array of strings; regular expressions are not supported.
        '''

        if log:
            procedurelogger.action(
                'Under the %s menu, select %s.' %
                (' => '.join(path[0:-1]), path[-1].replace('...', '')), self)

        parent = self._open(
            path[0:-1]
        )  # the last item in the path is excluded because we're going to click that item

        item = utils.findDescendant(parent, lambda x: (x.role == pyatspi.ROLE_MENU_ITEM or x.role == pyatspi.ROLE_CHECK_MENU_ITEM) \
            and utils.equalsOrMatches(x.name, path[-1]) and x.showing, recursive=False)
        item.click()

        return item
Example #8
0
    def findAlert(self, text, logText=None, retry=True, raiseException=True):
        '''
        Search for an alert

        Alerts typically have no name, so we have to search for them by their content. 
        We look for alerts that are showing and have within them a label that contains 
        the given text.
        '''

        if logText is None:
            logText = text

        if raiseException:
            procedurelogger.expectedResult('An alert appears: %s' % logText)

        def alertHasLabelContainingText(alert):
            return alert.role == pyatspi.ROLE_ALERT and alert.showing and \
                alert.findLabel(text, retry=False, recursive=True, raiseException=False) is not None

        return utils.findDescendant(self,
                                    alertHasLabelContainingText,
                                    retry=retry,
                                    recursive=False,
                                    raiseException=raiseException)
Example #9
0
 def descendantFound():
     dontCheckShowing = not checkShowing
     return utils.findDescendant(self, lambda x: x.role == v[a] and utils.equalsOrMatches(x.name, name) and (dontCheckShowing or x.showing), \
         retry=retry, recursive=recursive, breadthFirst=breadthFirst, raiseException=raiseException) != None
Example #10
0
                    def findMethod(name,
                                   logName=None,
                                   checkShowing=True,
                                   retry=True,
                                   recursive=True,
                                   breadthFirst=True,
                                   raiseException=True,
                                   setReference=False):
                        dontCheckShowing = not checkShowing
                        y = utils.findDescendant(self, lambda x: x.role == v[a] and utils.equalsOrMatches(x.name, name) and (dontCheckShowing or x.showing), \
                            retry=retry, recursive=recursive, breadthFirst=breadthFirst, raiseException=raiseException)

                        # don't try promoting y if it's None
                        if not raiseException and y is None:
                            return y

                        # look in the widget cache first
                        try:
                            return cache.getWidget(y)
                        except KeyError:
                            pass  # not in cache

                        # if the logName isn't given, set it to the name (unless the name is a regex)
                        if logName is None and type(name) is not type(
                                re.compile('r')):
                            logName = name

                        # if we still don't have a logname, just grab the name of the accessible
                        if logName is None:
                            logName = y.name

                        # at this point, we have a logName.  next, we look for a class named
                        # logName + roleName in moduleName.  if such a class can be found, we promote
                        # the widget to that class, cache the instance, and return it.
                        #
                        # if no such class can be found, and the logName is different than the name
                        # of the widget, set the widget's log name and cache the widget.  if the logName
                        # is the same as the widget's logName, there's no need to cache the widget.

                        # if the logName is 'Preferences' and roleName of the widget is 'Dialog',
                        # the name of the class to look for is 'PreferencesDialog'
                        className = utils.toClassName(
                            logName) + utils.toClassName(y.roleName)

                        # the module prefix is the module of this class.  so if we had a widget that had
                        # a class medsphere.openvistacis.OpenVistaCIS, and we call findDialog('Preferences')
                        # on it, the module prefix would be medsphere.openvistacis.  we append the name of
                        # the class we're looking for to the module prefix to get the name of the module.
                        # so continuing with the example, the full module name would be
                        # medsphere.openvistacis.preferencesdialog.  (In the medsphere.openvistacis.preferencesdialog
                        # module, we would look for 'PreferencesDialog' - that code is a few lines down)
                        moduleName = self.__class__.__module__ + '.' + className.lower(
                        )

                        try:
                            # import the module, grab the class, and make an instance of it, then cache the instance
                            module = __import__(moduleName, globals(), None,
                                                [className])
                            klass = vars(module)[className]
                            z = klass(y)
                            cache.addWidget(z)
                        except (ImportError, KeyError):
                            # if the found widget's logName isn't the same as the logName
                            # we were given, set the widget's logName and cache the widget
                            if y.name != logName:
                                y.logName = logName
                                cache.addWidget(
                                    y
                                )  # make the log name stick by caching the object with the logName property set on it
                            z = y

                        # set self.preferencesDialog = the widget we just found/promoted/cached
                        if setReference:
                            self.__setattr__(
                                utils.toVarName(logName) +
                                utils.toClassName(z.roleName), z)

                        return z
Example #11
0
 def descendantFound():
     dontCheckShowing = not checkShowing
     return utils.findDescendant(self, lambda x: x.role == v[a] and utils.equalsOrMatches(x.name, name) and (dontCheckShowing or x.showing), \
         retry=retry, recursive=recursive, breadthFirst=breadthFirst, raiseException=raiseException) != None
Example #12
0
                    def findMethod(name, logName=None, checkShowing=True, retry=True, recursive=True, breadthFirst=True, raiseException=True, setReference=False):
                        dontCheckShowing = not checkShowing
                        y = utils.findDescendant(self, lambda x: x.role == v[a] and utils.equalsOrMatches(x.name, name) and (dontCheckShowing or x.showing), \
                            retry=retry, recursive=recursive, breadthFirst=breadthFirst, raiseException=raiseException)

                        # don't try promoting y if it's None
                        if not raiseException and y is None:
                            return y

                        # look in the widget cache first
                        try:
                            return cache.getWidget(y)
                        except KeyError:
                            pass # not in cache

                        # if the logName isn't given, set it to the name (unless the name is a regex)
                        if logName is None and type(name) is not type(re.compile('r')):
                            logName = name

                        # if we still don't have a logname, just grab the name of the accessible
                        if logName is None:
                            logName = y.name

                        # at this point, we have a logName.  next, we look for a class named 
                        # logName + roleName in moduleName.  if such a class can be found, we promote 
                        # the widget to that class, cache the instance, and return it.  
                        #
                        # if no such class can be found, and the logName is different than the name 
                        # of the widget, set the widget's log name and cache the widget.  if the logName 
                        # is the same as the widget's logName, there's no need to cache the widget.  

                        # if the logName is 'Preferences' and roleName of the widget is 'Dialog', 
                        # the name of the class to look for is 'PreferencesDialog'
                        className = utils.toClassName(logName) + utils.toClassName(y.roleName)

                        # the module prefix is the module of this class.  so if we had a widget that had 
                        # a class medsphere.openvistacis.OpenVistaCIS, and we call findDialog('Preferences') 
                        # on it, the module prefix would be medsphere.openvistacis.  we append the name of 
                        # the class we're looking for to the module prefix to get the name of the module.
                        # so continuing with the example, the full module name would be 
                        # medsphere.openvistacis.preferencesdialog.  (In the medsphere.openvistacis.preferencesdialog 
                        # module, we would look for 'PreferencesDialog' - that code is a few lines down)
                        moduleName = self.__class__.__module__ + '.' + className.lower()

                        try:
                            # import the module, grab the class, and make an instance of it, then cache the instance
                            module = __import__(moduleName, globals(), None, [className])
                            klass = vars(module)[className]
                            z = klass(y)
                            cache.addWidget(z)
                        except (ImportError, KeyError):
                            # if the found widget's logName isn't the same as the logName 
                            # we were given, set the widget's logName and cache the widget
                            if y.name != logName:
                                y.logName = logName
                                cache.addWidget(y) # make the log name stick by caching the object with the logName property set on it
                            z = y

                        # set self.preferencesDialog = the widget we just found/promoted/cached
                        if setReference:
                            self.__setattr__(utils.toVarName(logName) + utils.toClassName(z.roleName), z)

                        return z