Ejemplo n.º 1
0
    def _saveScreen(self, filename, random_name=True, tempdir=True):
        # use last snapshot file
        if self._snapshot_file and self._keep_capture:
            return self._snapshot_file

        if random_name:
            filename = base.random_name(filename)
        if tempdir:
            filename = os.path.join(self._tmpdir, filename)

        parent_dir = os.path.dirname(filename) or '.'
        if not os.path.exists(parent_dir):
            base.makedirs(parent_dir)

        self.dev.snapshot(filename)

        if self._device == 'windows':
            return filename
        rotation = self._getRotation()
        # the origin screenshot is UP, so need to rotate it here for human
        if rotation != 'UP':
            angle = dict(RIGHT=Image.ROTATE_90, LEFT=Image.ROTATE_270).get(rotation)
            Image.open(filename).transpose(angle).save(filename)
        self._log(dict(type='snapshot', filename=filename))
        self._snapshot_file = filename
        return filename
Ejemplo n.º 2
0
    def find(self, imgfile):
        '''
        Find image position on screen

        @return (point founded or None if not found)
        '''
        filepath = self._search_image(imgfile)
        
        log.debug('Locate image path: %s', filepath)
        
        screen = self._saveScreen('screen-{t}-XXXX.png'.format(t=time.strftime("%y%m%d%H%M%S")))
        if self._screen_resolution:
            # resize image
            w, h = self._screen_resolution
            (ratew, rateh) = self.width/float(w), self.height/float(h)
            im = Image.open(filepath)
            (rw, rh) = im.size
            new_name = base.random_name('resize-{t}-XXXX.png'.format(t=time.strftime("%y%m%d%H%M%S")))
            new_name = os.path.join(self._tmpdir, new_name)
            im.resize((int(ratew*rw), int(rateh*rh))).save(new_name)
            filepath = new_name
        pt = self._imfind(screen, filepath)
        return pt
Ejemplo n.º 3
0
 def _saveScreen(self, filename):
     filename = base.random_name(filename)
     self.takeSnapshot(filename)
     return filename
Ejemplo n.º 4
0
 def _saveScreen(self, filename):
     filename = os.path.join(self._tmpdir, base.random_name(filename))
     self.takeSnapshot(filename)
     return filename
Ejemplo n.º 5
0
 def _saveScreen(self, filename):
     filename = base.random_name(filename)
     self.takeSnapshot(filename)
     return filename