[xpost SO] Drag (and drop) file from wx.FileDialog window does not work in MacOS

I posted on StackOverflow with a small bounty :slight_smile:

python - Drag (and drop) file from wx.FileDialog window does not work in MacOS - Stack OverflowDrag (and drop) file from wx.FileDialog window does not work in MacOS

In short, in don`t get the same behaviour (Drag and Drop) for wx.FileDialog under MacOS and Win7.
Also looking for alternative ideas.

*** Copied post below ***

Here is my user story:

After clicking on a particular button, a modal dialog box appears,
containing a single large icon representing a single file, and an OK
button. The header of the dialog box reads: “Please drag and drop this
file onto application APPX, then click OK”. The dialog box disappears
after clicking OK.

Here is what I tried on MacOS 10.9.5, Python 2.7.8, wx 3.0.1.1:

import wx, os
class MyForm(wx.Frame):

···

#----------------------------------------------------------------------
def init(self):
wx.Frame.init(self, None, wx.ID_ANY, “Demo”)
panel = wx.Panel(self, wx.ID_ANY)
openFileDlgBtn = wx.Button(panel, label=“Show FileDialog”)
openFileDlgBtn.Bind(wx.EVT_BUTTON, self.onOpenFile)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(openFileDlgBtn, 0, wx.ALL|wx.CENTER, 5)
panel.SetSizer(sizer)

#----------------------------------------------------------------------
def onOpenFile(self, event):
dlg = wx.FileDialog(
self, message=“Please drag and drop this file onto your favorite text editor, then click OK”,
defaultDir=os.getcwd(),
defaultFile=“.txt",
wildcard="TXT files (
.txt)|*.txt”,
style=wx.OPEN
)
if dlg.ShowModal() == wx.ID_OK:
pass
dlg.Destroy()

#----------------------------------------------------------------------
if name == “main”:
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()


Notes: I have no control on the external application; which will just
open the file. The wxDialog does not completely fit my requirements, since it displays folder navigation elements as well as other (greyed out) files. But that’s not the main issue.

The problem/question:

The wxDialog will not let me drag and drop any file on MacOS. It works well on Windows and Linux (see comments). How to
make it work on MacOS? What else than a FileDialog could I try? Ideally
I’d have a simple frame showing the file to be dragged. Thanks.

On Windows this works, I even tried dragging the file to a command prompt and I get the path surrounded by quotes pasted to the prompt. So I wonder, maybe it is your target program that doesn’t support whatever data the GUI is presuming the application wants to receive. Can you try dragging the file to a terminal window? Does this work from a different program’s open-file dialog (e.g. go to Chrome and hit ctrl-O to bring up their file dialog, then try dragging a text file to your editor and also to the terminal)?

···

On Monday, November 10, 2014 1:38:17 PM UTC-8, Hugues Fontenelle wrote:

After clicking on a particular button, a modal dialog box appears,
containing a single large icon representing a single file, and an OK
button. The header of the dialog box reads: “Please drag and drop this
file onto application APPX, then click OK”. The dialog box disappears
after clicking OK.