コード例 #1
0
ファイル: checkboxes.py プロジェクト: karlmicha/rguils
 def update_element(self, element_index):
     """Updates the specified element with its true state.
     """
     region = Region(self.element_regions[element_index])
     # add some space since images may have slightly different size
     marginx = int(region.getW() * 0.2)
     marginy = int(region.getH() * 0.2)
     extendRegion(region, left = marginx, right = marginx, top = marginy,
             bottom = marginy)
     best_checked_score = 0
     best_unchecked_score = 0
     try:
         best_checked = bestMatch(self.images['checked'], region = region,
                 minOverlap = 0.5)
         if best_checked is not None:
             best_checked_score = best_checked[1].getScore()
     except FindFailed:
         pass
     try:
         best_unchecked = bestMatch(self.images['unchecked'],
                 region = region, minOverlap = 0.5)
         if best_unchecked is not None:
             best_unchecked_score = best_unchecked[1].getScore()
     except FindFailed:
         pass
     if best_checked_score == best_unchecked_score:
         if best_checked_score == 0:
             raise Exception('no %s found in region %d' %
                     (self.element_types, element_index))
         raise Exception('score tie: cannot decide whether %s %d is checked or unchecked (score=%f)' %
                 (self.element_type, element_index, best_checked_score))
     state = best_checked_score > best_unchecked_score
     if state != self.is_checked(element_index):
         self._toggle_state(element_index)
コード例 #2
0
ファイル: window.py プロジェクト: karlmicha/rguils
class Window:
    """A window has a title bar that contains buttons to minimize, maximize and
       close the window in the upper right.
       A window can get focus by clicking on its title bar.
    """

    def __init__(self, region, title):
        """Creates a new window that covers the specified region. The region
           includes the title bar.
        """
        self.region = region
        self.title = title
        self.titlebar_region = Region(region.getX(), region.getY(),
                region.getW(), windowflavor.WINDOW_TITLEBAR_HEIGHT)
        self.minimize_button = self.getButtonLocation(
                windowflavor.WINDOW_TITLEBAR_MINIMIZE_BUTTON_OFFSET)
        self.maximize_button = self.getButtonLocation(
                windowflavor.WINDOW_TITLEBAR_MAXIMIZE_BUTTON_OFFSET)
        self.close_button = self.getButtonLocation(
                windowflavor.WINDOW_TITLEBAR_CLOSE_BUTTON_OFFSET)

    def getButtonLocation(self, button_offset):
        """Returns a Location instance at the specified horizontal offset in
           the title bar, vertically centered in the title bar.
        """
        if button_offset > 0:
            button_x = self.titlebar_region.getX() + button_offset
        else:
            button_x = self.titlebar_region.getX() \
                    + self.titlebar_region.getW() + button_offset
        return Location(button_x, self.titlebar_region.getY()
                + windowflavor.WINDOW_TITLEBAR_HEIGHT / 2)

    def setFocus(self):
        """Clicks on the center of this window's title bar."""
        _LOGGER.debug('setFocus: %s', self.title)
        SCREEN.click(self.titlebar_region)

    def minimize(self):
        """Clicks on the minimize button in this window's title bar."""
        _LOGGER.debug('minimize window: %s', self.title)
        SCREEN.click(self.minimize_button)

    def maximize(self):
        """Clicks on the maximize button in this window's title bar."""
        _LOGGER.debug('maximize window: %s', self.title)
        SCREEN.click(self.maximize_button)

    def close(self):
        """Clicks on the close button in this window's title bar."""
        _LOGGER.debug('close window: %s', self.title)
        SCREEN.click(self.close_button)

    def kill(self):
        """Attempts to kill the process that owns this window, using the window
           title.
        """
        _LOGGER.debug('kill window: %s', self.title)
        closeApp(self.title)
コード例 #3
0
 def update_element(self, element_index):
     """Updates the specified element with its true state.
     """
     region = Region(self.element_regions[element_index])
     # add some space since images may have slightly different size
     marginx = int(region.getW() * 0.2)
     marginy = int(region.getH() * 0.2)
     extendRegion(region,
                  left=marginx,
                  right=marginx,
                  top=marginy,
                  bottom=marginy)
     best_checked_score = 0
     best_unchecked_score = 0
     try:
         best_checked = bestMatch(self.images['checked'],
                                  region=region,
                                  minOverlap=0.5)
         if best_checked is not None:
             best_checked_score = best_checked[1].getScore()
     except FindFailed:
         pass
     try:
         best_unchecked = bestMatch(self.images['unchecked'],
                                    region=region,
                                    minOverlap=0.5)
         if best_unchecked is not None:
             best_unchecked_score = best_unchecked[1].getScore()
     except FindFailed:
         pass
     if best_checked_score == best_unchecked_score:
         if best_checked_score == 0:
             raise Exception('no %s found in region %d' %
                             (self.element_types, element_index))
         raise Exception(
             'score tie: cannot decide whether %s %d is checked or unchecked (score=%f)'
             % (self.element_type, element_index, best_checked_score))
     state = best_checked_score > best_unchecked_score
     if state != self.is_checked(element_index):
         self._toggle_state(element_index)
コード例 #4
0
class Window:
    """A window has a title bar that contains buttons to minimize, maximize and
       close the window in the upper right.
       A window can get focus by clicking on its title bar.
    """
    def __init__(self, region, title):
        """Creates a new window that covers the specified region. The region
           includes the title bar.
        """
        self.region = region
        self.title = title
        self.titlebar_region = Region(region.getX(), region.getY(),
                                      region.getW(),
                                      windowflavor.WINDOW_TITLEBAR_HEIGHT)
        self.minimize_button = self.getButtonLocation(
            windowflavor.WINDOW_TITLEBAR_MINIMIZE_BUTTON_OFFSET)
        self.maximize_button = self.getButtonLocation(
            windowflavor.WINDOW_TITLEBAR_MAXIMIZE_BUTTON_OFFSET)
        self.close_button = self.getButtonLocation(
            windowflavor.WINDOW_TITLEBAR_CLOSE_BUTTON_OFFSET)

    def getButtonLocation(self, button_offset):
        """Returns a Location instance at the specified horizontal offset in
           the title bar, vertically centered in the title bar.
        """
        if button_offset > 0:
            button_x = self.titlebar_region.getX() + button_offset
        else:
            button_x = self.titlebar_region.getX() \
                    + self.titlebar_region.getW() + button_offset
        return Location(
            button_x,
            self.titlebar_region.getY() +
            windowflavor.WINDOW_TITLEBAR_HEIGHT / 2)

    def setFocus(self):
        """Clicks on the center of this window's title bar."""
        _LOGGER.debug('setFocus: %s', self.title)
        SCREEN.click(self.titlebar_region)

    def minimize(self):
        """Clicks on the minimize button in this window's title bar."""
        _LOGGER.debug('minimize window: %s', self.title)
        SCREEN.click(self.minimize_button)

    def maximize(self):
        """Clicks on the maximize button in this window's title bar."""
        _LOGGER.debug('maximize window: %s', self.title)
        SCREEN.click(self.maximize_button)

    def close(self):
        """Clicks on the close button in this window's title bar."""
        _LOGGER.debug('close window: %s', self.title)
        SCREEN.click(self.close_button)

    def kill(self):
        """Attempts to kill the process that owns this window, using the window
           title.
        """
        _LOGGER.debug('kill window: %s', self.title)
        closeApp(self.title)