예제 #1
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)
예제 #2
0
파일: buttons.py 프로젝트: karlmicha/rguils
 def update_button(self, name):
     """Updates the specified button so that this button set reflects the
        current state of the button.
     """
     _LOGGER.debug("%sgetting current state of '%s' button",
             self._debugprefix, name)
     i, match = self._button_matches[name]
     button_region = Region(match).nearby(15)
     images = []
     images.extend(self._buttons[name])
     if self._disabled_buttons is not None and \
             name in self._disabled_buttons:
         images.extend(self._disabled_buttons[name])
     i_best, m_best = bestMatch(images, region = button_region,
             minOverlap = 0.5)
     disabled = i_best >= len(self._buttons[name])
     if disabled:
         _LOGGER.info("'%s' button (image %d) is disabled",
                 name, i_best -len(self._buttons[name]))
         s = self._disabled_button_index[name]
         self._button_matches[name] = \
                 (s + i_best - len(self._buttons[name]), m_best)
     else:
         _LOGGER.info("'%s' button (image %d) is enabled", name, i_best)
         s = self._button_index[name]
         self._button_matches[name] = (s + i_best, m_best)
예제 #3
0
 def update_button(self, name):
     """Updates the specified button so that this button set reflects the
        current state of the button.
     """
     _LOGGER.debug("%sgetting current state of '%s' button",
                   self._debugprefix, name)
     i, match = self._button_matches[name]
     button_region = Region(match).nearby(15)
     images = []
     images.extend(self._buttons[name])
     if self._disabled_buttons is not None and \
             name in self._disabled_buttons:
         images.extend(self._disabled_buttons[name])
     i_best, m_best = bestMatch(images,
                                region=button_region,
                                minOverlap=0.5)
     disabled = i_best >= len(self._buttons[name])
     if disabled:
         _LOGGER.info("'%s' button (image %d) is disabled", name,
                      i_best - len(self._buttons[name]))
         s = self._disabled_button_index[name]
         self._button_matches[name] = \
                 (s + i_best - len(self._buttons[name]), m_best)
     else:
         _LOGGER.info("'%s' button (image %d) is enabled", name, i_best)
         s = self._button_index[name]
         self._button_matches[name] = (s + i_best, m_best)
예제 #4
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)