pythonwindowswxpythonwxwidgets

How can I use a wx.FileDialog to select a file which is locked by another process


I'm trying to use the wx.FileDialog class to select the name of a file. I don't want to open it. This is a minimal example of what I'm trying to do:

import wx

if __name__ == '__main__':
    app = wx.App(redirect=False)
    frame = wx.Frame(None)
    frame.Show()

    dlg = wx.FileDialog(parent=frame, style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST, wildcard="Project (*.ap*)|*.ap*|All files (*.*)|*.*")
    dlg.ShowModal()

    app.MainLoop()

enter image description here

The text is in Swedish and says "File in use. Select a different name of close the file in use in another program".

I'm trying to select the filename of a TIA Portal project file (Siemens PLC programming tool). Unfortunately it seems that TIA Portal locks the file. NOTE: I don't want to open the file. I just need the name.


Solution

  • Unfortunately it looks like this is currently impossible because wxWidgets doesn't set FOS_SHAREAWARE flag and so doesn't customize the default handling of locked files — which is to do what you see. It should be relatively straightforward to implement support for this in wxWidgets itself and, as it's an open source library which is open to contributions, anybody could do it. But somebody would have to do it first, before this functionality becomes accessible in wxPython.