def _getLatestImageStringFromFile(self, serialNo, chinBarImageString): #dprint("_getLatestImageStringFromFile") latestImageName = self._getLatestImageFilename(serialNo) #dprint("_getLatestImageStringFromFile: ", latestImageName) tries = 0 successful = False while tries < 3 and not successful: try: image = Image.open(os.path.join(globals_.getUserDocumentsPath(), constants.APP_DIR, latestImageName)) except Exception, e: # Don't know how we'd get here; perhaps the image hasn't been completely written. #dprint("_getLatestImageStringFromFile: exception opening image") #dprint("image exists?:", # os.path.join(globals_.getUserDocumentsPath(), constants.APP_DIR, latestImageName), # " ", # os.path.exists(os.path.join(globals_.getUserDocumentsPath(), constants.APP_DIR, latestImageName))) time.sleep(0.1) else: try: # about 0.01 seconds newImageString = image.tostring() except Exception, e: # I sometimes get an error about a broken PNG chunk here, # and I've found that Image.open(...), image.tostring() # works in this case, so go thru the loop again. # This delay is just a guess; it could be appropriate when the image is # still in the process of being created by the ScreenshotProcess. time.sleep(0.1) else:
def __init__(self, replayProcess, device, orientation): self.replayProcess = replayProcess self.device = device self.orientation = orientation chinBarImageName = constants.CHIN_BAR_IMAGE_TEMPLATE.format(ser=device.serialNo) chinBarImagePath = os.path.join(globals_.getUserDocumentsPath(), constants.APP_DIR, chinBarImageName) if os.path.exists(chinBarImagePath): _image = cv.LoadImage(chinBarImagePath, cv.CV_LOAD_IMAGE_COLOR) self.chinBarImageString = _image.tostring() elif self.device.chinBarImageString: self.chinBarImageString = self.device.chinBarImageString else: self.chinBarImageString = (chr(255) + chr(255) + chr(255)) * self.device.chinBarHeight * self.device.width # Used by _dragSearch to know whether the previous event was a drag and we may need to continue # dragging in the same direction. self.previousInputType = None self.previousDragStartRegion = None self.previousDragRightUnits = None self.previousDragDownUnits = None