Yes the proxy model is generic so it isn't specifically aware of files vs directories and it going to just ask you if any row should be filtered out.
The difference between your modification and the original code is that the original naively assumes directories won't match extensions and will always end up being shown. So it was just files with extensions thag would be subject to exclusion if they match the ext list. When you try and flip the logic you are now saying that even directories that don't have the desired ext should be excluded which means the children are gone too.
What you might want to do is to check if the index is a directory first.
if sourceModel.isDir(idx):
return True
This will get you part of the way there since it will now only exclude files that don't match. But you will be left with empty dirs. There could be a few ways to handle this. One is more manual work since it would require that you perform your own listing on the dir and check all the children to see if it's going to end up empty. If so then you want to return False so it will exclude the dir. Another option is to make the proxy model system do all the work and create a second proxy model that can run a filter pass after the first one removes all the files. That would then let you look for dirs and the source proxy model will tell you if it has children.
Justin