Example #1
0
    def refresh(self, num=None, t=None, tClosest=None, forceRefresh=False):
        if num:
            self.num = num

        with Model.LockRace() as race:
            if race is None:
                self.clear()
                return

            # Automatically refresh the screen only if the rider showing has last been updated.
            if not forceRefresh and num is None and t is None and race.isRunning(
            ):
                tLast, rLast = race.getLastKnownTimeRider()
                if rLast and rLast.num != self.num:
                    return

        dir = getPhotoDirName(
            Utils.mainWin.fileName
        ) if Utils.mainWin and Utils.mainWin.fileName else 'Photos'
        self.thumbs._scrolled.filePrefix = '' if self.num == self.ShowAllPhotos else 'bib-{:04d}'.format(
            self.num)

        if os.path.isdir(dir):
            self.thumbs.ShowDir(dir)
        else:
            self.clear()
            return

        itemCount = self.thumbs.GetItemCount()
        if not itemCount:
            self.clear()
            return

        if self.num is not None and t is not None:
            # Select the photo specified by the bib and time.
            fnames = [
                os.path.basename(GetPhotoFName(dir, num, t, i))
                for i in xrange(2)
            ]
            for i in xrange(itemCount):
                fnameToMatch = self.thumbs.GetItem(i).GetFileName()
                if any(f in fnameToMatch for f in fnames):
                    break
            self.thumbs.SetSelection(min(i, self.thumbs.GetItemCount() - 1))
        elif tClosest is not None:
            tDeltaBest = 1000.0 * 24.0 * 60.0 * 60.0
            iBest = None
            for i in xrange(itemCount):
                tDelta = abs(
                    getFileKey(self.thumbs.GetItem(i).GetFileName()) -
                    tClosest)
                if tDelta < tDeltaBest:
                    iBest = i
                    tDeltaBest = tDelta
            if iBest is not None:
                self.thumbs.SetSelection(iBest)
        else:
            self.thumbs.SetSelection(self.thumbs.GetItemCount() - 1)

        self.OnSelChanged()
Example #2
0
def hasPhoto( bib, t ):
	global photoCache
	
	race = Model.race
	if not photoCache or not race or not race.enableUSBCamera or not race.startTime:
		return False
		
	try:
		return os.path.basename(GetPhotoFName(getPhotoDirName(Utils.getFileName()), bib, t, 0))[:-6] in photoCache
	except Exception as e:
		return False
Example #3
0
def hasPhoto(bib, t):
    global photoCache

    race = Model.race
    if not photoCache or not race or not race.enableUSBCamera or not race.startTime:
        return False

    try:
        return os.path.basename(
            GetPhotoFName(getPhotoDirName(Utils.getFileName()), bib, t,
                          0))[:-6] in photoCache
    except Exception as e:
        return False
Example #4
0
	def refresh( self, num=None, t=None, tClosest=None, forceRefresh=False ):
		if num:
			self.num = num
		
		with Model.LockRace() as race:
			if race is None:
				self.clear()
				return
				
			# Automatically refresh the screen only if the rider showing has last been updated.
			if not forceRefresh and num is None and t is None and race.isRunning():
				tLast, rLast = race.getLastKnownTimeRider()
				if rLast and rLast.num != self.num:
					return
					
		dir = getPhotoDirName( Utils.mainWin.fileName ) if Utils.mainWin and Utils.mainWin.fileName else 'Photos'
		self.thumbs._scrolled.filePrefix = '' if self.num == self.ShowAllPhotos else 'bib-{:04d}'.format(self.num)
		
		if os.path.isdir(dir):
			self.thumbs.ShowDir( dir )
		else:
			self.clear()
			return
		
		itemCount = self.thumbs.GetItemCount()
		if not itemCount:
			self.clear()
			return
		
		if self.num is not None and t is not None:
			# Select the photo specified by the bib and time.
			fnames = [os.path.basename(GetPhotoFName(dir, num, t, i)) for i in xrange(2)]
			for i in xrange(itemCount):
				fnameToMatch = self.thumbs.GetItem(i).GetFileName()
				if any( f in fnameToMatch for f in fnames ):
					break
			self.thumbs.SetSelection( min(i, self.thumbs.GetItemCount() - 1) )
		elif tClosest is not None:
			tDeltaBest = 1000.0*24.0*60.0*60.0
			iBest = None
			for i in xrange(itemCount):
				tDelta = abs( getFileKey(self.thumbs.GetItem(i).GetFileName()) - tClosest )
				if tDelta < tDeltaBest:
					iBest = i
					tDeltaBest = tDelta
			if iBest is not None:
				self.thumbs.SetSelection( iBest )
		else:
			self.thumbs.SetSelection( self.thumbs.GetItemCount() - 1 )
		
		self.OnSelChanged()
Example #5
0
def updatePhotoFNameCache():
	global photoCache
	
	photoCache = set()
	
	race = Model.race
	if not race or not race.enableUSBCamera or not race.startTime:
		return
	
	photoDir = getPhotoDirName( Utils.getFileName() )
	try:
		photoCache = { fname[:-6] for fname in os.listdir(photoDir) if fname.startswith('bib') and fname.endswith('.jpg')  }
	except Exception as e:
		pass
Example #6
0
def ShowFinishStrip( parent, t=None ):
	race = Model.race
	if not race:
		return
	fsd = FinishStripDialog( parent,
		photoFolder=getPhotoDirName( Utils.mainWin.fileName if Utils.mainWin and Utils.mainWin.fileName else 'Photos' ),
		fps=getattr(race, 'fps', 25.0),
		leftToRight=getattr(race, 'leftToRight', True),
		pixelsPerSec=getattr(race, 'pixelsPerSec', None),
	)
	if t is not None:
		fsd.SetT( t )
	fsd.ShowModal()
	for attr, value in six.iteritems(fsd.GetAttrs()):
		setattr( race, attr, value )
	fsd.Destroy()
Example #7
0
def updatePhotoFNameCache():
    global photoCache

    photoCache = set()

    race = Model.race
    if not race or not race.enableUSBCamera or not race.startTime:
        return

    photoDir = getPhotoDirName(Utils.getFileName())
    try:
        photoCache = {
            fname[:-6]
            for fname in os.listdir(photoDir)
            if fname.startswith('bib') and fname.endswith('.jpg')
        }
    except Exception as e:
        pass
Example #8
0
def DeletePhotos( raceFileName ):
	dirName = getPhotoDirName( raceFileName )
	try:
		shutil.rmtree( dirName, True )
	except Exception as e:
		logException( e, sys.exc_info() )
Example #9
0
	def OnLaunchFileBrowser( self, event ):
		dir = getPhotoDirName( Utils.mainWin.fileName if Utils.mainWin and Utils.mainWin.fileName else 'Photos' )
		LaunchFileBrowser( dir )
Example #10
0
def DeletePhotos(raceFileName):
    dirName = getPhotoDirName(raceFileName)
    try:
        shutil.rmtree(dirName, True)
    except Exception as e:
        logException(e, sys.exc_info())