This working code calls QFileDialog, prompting the user to select the CSV file:
def load(self,fileName=None):
if not fileName:
fileName=fileDialog.getOpenFileName(caption="Load Existing Radio Log",filter="csv (*.csv)")[0]
...
...
Now, I would like this filter to be more selective. The program saves each project as a set of three CSV files (project.csv, project_fleetsync.csv, project_clueLog.csv), but I want the first (project.csv) to be displayed in the file dialog box to avoid introducing a user with too many variants when only a third of them can be processed by the rest of the load () function.
According to this post , it seems like the solution is to use a proxy model. So, I changed the code to the following (all commented lines in load () are the things I tried in different combinations):
def load(self,fileName=None):
if not fileName:
fileDialog=QFileDialog()
fileDialog.setProxyModel(CSVFileSortFilterProxyModel(self))
...
...
class CSVFileSortFilterProxyModel(QSortFilterProxyModel):
def __init__(self,parent=None):
print("initializing CSVFileSortFilterProxyModel")
super(CSVFileSortFilterProxyModel,self).__init__(parent)
def filterAcceptsRow(self,source_row,source_parent):
print("CSV filterAcceptsRow called")
source_model=self.sourceModel()
index0=source_model.index(source_row,0,source_parent)
if source_model.isDir(index0):
return True
filename=source_model.fileName(index0)
print("testing lowercased filename:"+filename)
if filename.count("_fleetsync.csv")+filename.count("_clueLog.csv")==0:
return True
else:
return False
load(), " CSVFileSortFilterProxyModel" , , -, filterAcceptsRow : "CSV filterAcceptsRow", "output", _fleetsync.csv _clueLog.csv . , - ...?