FileDialog.py demo app

Can someone tell me why the SetFilterIndex() in the demo app FileDialog.py doesn’t appear to work? Am I using it wrong? It always defaults to index 0 regardless of what you set in the SetFilterIndex() on line 84.

dlg.SetFilterIndex(2)

Thank you…

It’s working for me on Python 3.8.5 + wxPython 4.1.1 gtk3 (phoenix) wxWidgets 3.1.5 + Linux Mint 20.1

I edited the line in the demo code (it’s line 86 in my copy), clicked “Save Changes” and ensured the “Modified” radio button was selected.

Then I clicked the “Create and Show a SAVE FileDialog” and the correct filter was selected.

My apologies. I was looking at the Open dialog which does not have the SetFilterIndex() line. When I added it, it worked fine.

Thank you…

No problem - it made me look at one of my projects again where I found I wasn’t using SetFilterIndex(), so I was able to fix it!

I tried SetFilterIndex() on the demo GenericDirCtrl.py

I added this line to dir3 (on line 25 on my setup):

    dir3.SetFilterIndex(1)

and it did not work. The filter always loaded up with index 0.

I get the same result as you with the demo for GenericDirCtrl.py

The following hack does work for me:

        children = dir3.GetChildren()
        dir_filter = children[1]
        dir_filter.SetSelection(1)

However, relying on the order of the children is probably not a good idea…

That does set the filter index…in this case for *.py files. However, when I open a folder I get all files, instead of just *.py files. It’s like the filter isn’t ‘connected’ back to the tree?

Sorry for not testing that.

How about:

        filter_ctrl = dir3.GetFilterListCtrl()
        filter_ctrl.SetSelection(1)
        dir3.SetFilterIndex(1)

Sorry for all the trouble. Your latest change doesn’t show me any files at all now!