Skip to content

Commit

Permalink
Added ability to bulk remove races.
Browse files Browse the repository at this point in the history
Fixed bug with passing no races to starmap.
  • Loading branch information
esitarski committed Jul 26, 2024
1 parent 386e023 commit 8322e33
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
34 changes: 26 additions & 8 deletions SeriesMgr/Races.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import wx
import wx.grid as gridlib

Expand Down Expand Up @@ -82,8 +84,8 @@ def __init__(self, parent):
self.addButton = wx.Button( self, wx.ID_ANY, 'Add Races' )
self.addButton.Bind( wx.EVT_BUTTON, self.doAddRace )

self.removeButton = wx.Button( self, wx.ID_ANY, 'Remove Race' )
self.removeButton.Bind( wx.EVT_BUTTON, self.doRemoveRace )
self.removeButton = wx.Button( self, wx.ID_ANY, 'Remove Races' )
self.removeButton.Bind( wx.EVT_BUTTON, self.doRemoveRaces )

fgs = wx.FlexGridSizer( rows=2, cols=2, vgap=2, hgap=2 )
fgs.AddGrowableCol( 1, proportion=1 )
Expand Down Expand Up @@ -136,13 +138,29 @@ def doAddRace( self, event ):
SeriesModel.model.addRace( fileName )
self.refresh()

def doRemoveRace( self, event ):
row = self.grid.GetGridCursorRow()
if row < 0:
Utils.MessageOK(self, 'No Selected Race.\nPlease Select a Race to Remove.', 'No Selected Race')
def doRemoveRaces( self, event ):
selectedRows = set()
selectedRows.update( c.GetRow() for c in self.grid.GetSelectedCells() )
selectedRows.update( self.grid.GetSelectedRows() )
if (row := self.grid.GetGridCursorRow()) >= 0:
selectedRows.add( row )
selectedRows = sorted( selectedRows )

if not selectedRows:
Utils.MessageOK(self, 'No Selected Races.\nPlease Select one or more Races to Remove.', 'No Selected Race')
return
if Utils.MessageOKCancel(self, 'Confirm Remove Race:\n\n {}'.format( self.grid.GetCellValue(row, 0) ), 'Remove Race'):
self.grid.DeleteRows( row )

raceNames = []
for i, r in enumerate(selectedRows, 1):
# Make a name from the last two components of the path.
name = self.grid.GetCellValue(r, 0).replace( '\\', '/' )
rName = os.path.join( *name.split('/')[-2:] )
raceNames.append( f'{i}. {rName}' )
raceList = '\n'.join( raceNames )

if Utils.MessageOKCancel(self, 'Confirm Remove Races:\n\n{}'.format( raceList ), 'Remove Races'):
for r in reversed(selectedRows):
self.grid.DeleteRows( r )
self.commit()

def updatePointsChoices( self ):
Expand Down
9 changes: 7 additions & 2 deletions SeriesMgr/Results.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,16 @@ def write( s ):
} ):
with tag(html, 'span', dict(id='idUpDn{}_{}'.format(iTable,len(headerNames) + iRace)) ):
pass

rName = r[1].replace('\n', '<br/>\n').replace(' ',' ')
if rName.endswith('Finals'):
rName = rName.replace('Finals', 'Final')
rName = escape(rName)
if r[2]:
with tag(html,'a',dict(href='{}?raceCat={}'.format(r[2], quote(categoryName.encode('utf8')))) ):
write( '{}'.format(escape(r[1]).replace('\n', '<br/>\n')) )
write( rName )
else:
write( '{}'.format(escape(r[1]).replace('\n', '<br/>\n')) )
write( rName )
if r[0]:
write( '<br/>' )
with tag(html, 'span', {'class': 'smallFont'}):
Expand Down
7 changes: 5 additions & 2 deletions SeriesMgr/SeriesModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,11 @@ def clearCache( self ):
def _extractAllRaceResultsCore( self ):
with modelUpdateLock:
# Extract all race results in parallel. Arguments are the race info and this series.
with Pool() as p:
p_results = p.starmap( GetModelInfo.ExtractRaceResults, ((r,self) for r in self.races) )
if self.races:
with Pool() as p:
p_results = p.starmap( GetModelInfo.ExtractRaceResults, ((r,self) for r in self.races) )
else:
p_results = []

# Combine all results and record any errors.
raceResults = []
Expand Down
2 changes: 1 addition & 1 deletion SeriesMgr/Version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
AppVerName="SeriesMgr 3.0.38-private"
AppVerName="SeriesMgr 3.0.39-private"

0 comments on commit 8322e33

Please sign in to comment.