Skip to content

Commit

Permalink
Fixed more display issues in LapCountDisplay.
Browse files Browse the repository at this point in the history
  • Loading branch information
esitarski committed Aug 15, 2024
1 parent fe97bea commit 72f9641
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 64 deletions.
40 changes: 22 additions & 18 deletions LapsToGoCount.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,17 @@ def __exit__(self, *args):
else:
getattr( self.dc, funcName )( vNew )

@Model.memoize
def LapsToGoCount( t=None ):
ltgc = {} # dict indexed by category with a list of (lapsToGo, count).
sc = {} # dict index by category with counts of each status.

race = Model.race
if not race or race.isUnstarted() or race.isFinished():
if not race or race.isUnstarted():
return ltgc, sc

if not t:
t = race.curRaceTime()
t = race.curRaceTime() if race.isRunning() else float('inf')

Finisher = Model.Rider.Finisher
lapsToGoCountCategory = defaultdict( int )
Expand Down Expand Up @@ -175,7 +176,6 @@ def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,

super().__init__(parent, id, pos, size, style, validator, name)

#self.barBrushes = [wx.Brush(wx.Colour( int(c[:2],16), int(c[2:4],16), int(c[4:],16)), wx.SOLID) for c in ('D8E6AD', 'E6ADD8', 'ADD8E6')]
self.barBrushes = [wx.Brush(wx.Colour( int(c[:2],16), int(c[2:4],16), int(c[4:],16)), wx.SOLID) for c in ('A0A0A0', 'D3D3D3', 'E5E4E2')]
self.statusKeys = sorted( (k for k in Model.Rider.statusSortSeq.keys() if isinstance(k, int)), key=lambda k: Model.Rider.statusSortSeq[k] )

Expand Down Expand Up @@ -239,7 +239,7 @@ def Draw( self, dc ):
xLeft = 0

xRight = width - xLeft
yBottom = height - yTop
yBottom = height

catHeight = int( (yBottom-yTop) / len(categories) )

Expand All @@ -262,17 +262,18 @@ def statusCountStr( sc, lap0Count ):
onCourseCount = count - lap0Count
sName = translate(statusNames[status].replace('Finisher','Competing'))
t.append( f'{count}={sName}' )
return f"{onCourseCount}={_('OnCourse')} | " + ' | '.join( t )
return f"{onCourseCount}={_('OnCourse')}" + (" | " if t else '') + ' | '.join( t )

titleStyle = DCStyle( dc, Font=catLabelFontBold )
chartLineStyle = DCStyle( dc, Pen=greyPen, Brush=wx.TRANSPARENT_BRUSH )

lap0Total = finisherTotal = 0
yCur = yTop
for cat in categories:
# Draw the chart lines.
with chartLineStyle:
dc.DrawRectangle( xLeft, yCur, xRight-xLeft, catFieldHeight )
if barFieldHeight >= catLabelFontHeight:
# Draw the chart lines.
with chartLineStyle:
dc.DrawRectangle( xLeft, yCur, xRight-xLeft, catFieldHeight )

# Draw the lap bars.
ltg = lapsToGoCount[cat]
Expand Down Expand Up @@ -301,31 +302,34 @@ def statusCountStr( sc, lap0Count ):
s = f'{lap}'
tWidth = dc.GetTextExtent( s ).width
else:
lap0Count = lap
lap0Total += lap
lap0Count = count
lap0Total += count
s = f'{_("Finished")}'
tWidth = dc.GetTextExtent( s ).width
if tWidth >= barTextWidth:
s = f'{_("Fin")}'
tWidth = dc.GetTextExtent( s ).width

barHeight = round( barFieldHeight * count / countTotal )
if barHeight < catLabelFontHeight:
if barFieldHeight < catLabelFontHeight:
continue

barHeight = round( barFieldHeight * count / countTotal )

i = ltg[0][0] - lap
dc.SetBrush( self.barBrushes[lap%len(self.barBrushes)] )
dc.DrawRectangle( barX[i], yCur + catFieldHeight - barHeight, barX[i+1] - barX[i], barHeight )

y = yCur + catHeight - catLabelMargin - catLabelFontHeight
x = barX[i] + (barX[i+1] - barX[i] - tWidth) // 2
dc.DrawText( s, x, y )
if tWidth < barTextWidth:
y = yCur + catHeight - catLabelMargin - catLabelFontHeight
x = barX[i] + (barX[i+1] - barX[i] - tWidth) // 2
dc.DrawText( s, x, y )

s = f'{count}'
tWidth = dc.GetTextExtent( s ).width
y = min( yCur + catFieldHeight - catLabelFontHeight- catLabelFontHeight//4, yCur + catFieldHeight - barHeight + catLabelFontHeight//2 )
x = barX[i] + (barX[i+1] - barX[i] - tWidth) // 2
dc.DrawText( s, x, y )
if tWidth < barTextWidth:
y = min( yCur + catFieldHeight - catLabelFontHeight- catLabelFontHeight//4, yCur + catFieldHeight - barHeight + catLabelFontHeight//2 )
x = barX[i] + (barX[i+1] - barX[i] - tWidth) // 2
dc.DrawText( s, x, y )

# Draw the category label with the status totals.
with titleStyle:
Expand Down
48 changes: 3 additions & 45 deletions NumKeypad.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,18 +420,8 @@ def __init__( self, parent, id = wx.ID_ANY ):
#------------------------------------------------------------------------------
# Rider Lap Count.
rcVertical = wx.BoxSizer( wx.VERTICAL )
'''
rcVertical.AddSpacer( 32 )
self.categoryStatsList = wx.ListCtrl( panel, wx.ID_ANY, style = wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_HRULES|wx.BORDER_NONE )
self.categoryStatsList.SetFont( wx.Font(int(fontSize*0.9), wx.DEFAULT, wx.NORMAL, wx.NORMAL) )
self.categoryStatsList.AppendColumn( _('Category'), wx.LIST_FORMAT_LEFT, 140 )
self.categoryStatsList.AppendColumn( _('Composition'), wx.LIST_FORMAT_LEFT, 130 )
self.categoryStatsList.SetColumnWidth( 0, wx.LIST_AUTOSIZE_USEHEADER )
self.categoryStatsList.SetColumnWidth( 1, wx.LIST_AUTOSIZE_USEHEADER )
'''
self.categoryStatsList = LapsToGoCountGraph( panel )
rcVertical.Add( self.categoryStatsList, 1, flag=wx.EXPAND|wx.TOP|wx.RIGHT, border = 4 )
self.lapsToGoCountGraph = LapsToGoCountGraph( panel )
rcVertical.Add( self.lapsToGoCountGraph, 1, flag=wx.EXPAND|wx.TOP|wx.RIGHT, border = 4 )

horizontalMainSizer.Add( rcVertical, 1, flag=wx.EXPAND|wx.LEFT, border = 4 )
self.horizontalMainSizer = horizontalMainSizer
Expand Down Expand Up @@ -667,39 +657,7 @@ def refreshLaps( self ):
wx.CallAfter( self.refreshRaceHUD )

def refreshRiderCategoryStatsList( self ):
self.categoryStatsList.Refresh()
'''
self.categoryStatsList.DeleteAllItems()
race = Model.race
if not race:
return
def appendListRow( row = tuple(), colour = None, bold = None ):
r = self.categoryStatsList.InsertItem( self.categoryStatsList.GetItemCount(), '{}'.format(row[0]) if row else '' )
for c in range(1, len(row)):
self.categoryStatsList.SetItem( r, c, '{}'.format(row[c]) )
if colour is not None:
item = self.categoryStatsList.GetItem( r )
item.SetTextColour( colour )
self.categoryStatsList.SetItem( item )
if bold is not None:
item = self.categoryStatsList.GetItem( r )
font = self.categoryStatsList.GetFont()
font.SetWeight( wx.FONTWEIGHT_BOLD )
item.SetFont( font )
self.categoryStatsList.SetItem( item )
return r
for catStat in getCategoryStats():
if catStat[0] == _('All'):
colour, bold = wx.BLUE, None
else:
colour = bold = None
appendListRow( catStat, colour, bold )
self.categoryStatsList.SetColumnWidth( 0, wx.LIST_AUTOSIZE_USEHEADER )
self.categoryStatsList.SetColumnWidth( 1, wx.LIST_AUTOSIZE_USEHEADER )
'''
self.lapsToGoCountGraph.Refresh()

def refreshLastRiderOnCourse( self ):
race = Model.race
Expand Down
2 changes: 1 addition & 1 deletion Version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
AppVerName="CrossMgr 3.1.61-private"
AppVerName="CrossMgr 3.1.62-private"

0 comments on commit 72f9641

Please sign in to comment.