Drag and Drop from app to OS

Hey,

I’m try to find a way to drag and drop files from the app to the OS.

I found this article by Mike Driscoll which was helpful. I have a ListCtrl in my app as well with the files in. The issue i’m having is that the entries in the ListCtrl represent a view of files in a remote location. So when I drag and drop they will need to download to the location.

wx.FileDataObject and it’s siblings all seem to require the file data, or file path etc. but can’t see a way of providing a file object

Is there a way I can provide a file stream to a DataObject? Or is there a way I can get the path of the drop location, then I can do all the work downloading etc. myself?

Out of curiosity also, the example in the article is confusing me a little. The way it’s bound to EVT_LIST_BEGIN_DRAG - How does that work?? How can it know where to copy before the drag has finished?

Thanks!

Paul

Hi Paul.

Hey,

I’m try to find a way to drag and drop files from the app to the OS.

I found this article by Mike Driscoll which was helpful. I have a ListCtrl in my app as well with the files in. The issue i’m having is that the entries in the ListCtrl represent a view of files in a remote location. So when I drag and drop they will need to download to the location.

I’m glad you found it helpful.

wx.FileDataObject and it’s siblings all seem to require the file data, or file path etc. but can’t see a way of providing a file object

Is there a way I can provide a file stream to a DataObject? Or is there a way I can get the path of the drop location, then I can do all the work downloading etc. myself?

Out of curiosity also, the example in the article is confusing me a little. The way it’s bound to EVT_LIST_BEGIN_DRAG - How does that work?? How can it know where to copy before the drag has finished?

That event just catches when the user selects an item from the list control and then starts dragging it.

Thanks!

Paul

I think you’ll need to use paramiko to do the actual downloading of the file. You can get that here: http://www.lag.net/paramiko/ (or on PyPI - paramiko · PyPI)

I also found an ftp app that’s written in wxPython that might help you, although it’s a little complex: FtpCube - Download page

The drop source doesn’t know anything about the file system, so there doesn’t appear to be a way that I can find that tells you what the drop target was if you drag outside of your application. You can read more here: python - Drag and drop application-created file to explorer window - Stack Overflow

However, if you create a folder-tree in your application (like Filezilla), then you can control the drop target and know where something was dropped.

  • Mike
···

On Thursday, November 14, 2013 5:50:30 AM UTC-6, Paul wrote:

Hi Paul.

Hey,

I'm try to find a way to drag and drop files from the app to the OS.

I found this article<http://www.blog.pythonlibrary.org/2012/08/01/wxpython-how-to-drag-and-drop-a-file-from-your-app-to-the-os/&gt;by Mike Driscoll which was helpful. I have a ListCtrl in my app as well
with the files in. The issue i'm having is that the entries in the ListCtrl
represent a view of files in a remote location. So when I drag and drop
they will need to download to the location.

I'm glad you found it helpful.

wx.FileDataObject and it's siblings all seem to require the file data, or
file path etc. but can't see a way of providing a file object

Is there a way I can provide a file stream to a DataObject? Or is there a
way I can get the path of the drop location, then I can do all the work
downloading etc. myself?

Out of curiosity also, the example in the article is confusing me a
little. The way it's bound to EVT_LIST_BEGIN_DRAG - How does that work??
How can it know where to copy before the drag has finished?

That event just catches when the user selects an item from the list
control and then starts dragging it.

Thanks!

Paul

I think you'll need to use paramiko to do the actual downloading of the
file. You can get that here: http://www.lag.net/paramiko/ (or on PyPI -
paramiko · PyPI)

Thanks for the reply Mike!

Getting the files is ok, I'm actually interacting with an API to list
folders and files, which I'm displaying in the wxpython app, and the actual
files download over http - sorry I should have perhaps explained that to
begin with. This part isn't a problem.

I also found an ftp app that's written in wxPython that might help you,
although it's a little complex:
FtpCube - Download page

I'll check that out now :slight_smile:

The drop source doesn't know anything about the file system, so there
doesn't appear to be a way that I can find that tells you what the drop
target was if you drag outside of your application. You can read more here:
python - Drag and drop application-created file to explorer window - Stack Overflow

If the drop source doesn't know anything about the file system how is it
able to copy files to the drop location as per the example in your article?

However, if you create a folder-tree in your application (like Filezilla),
then you can control the drop target and know where something was dropped.

Unfortunately I'm not able to put a file system tree into the application
like FileZilla, I'll need to be able to copy items out of the app into the
native file browser.

The problem I have is that the DropSource requires a DataObject, which
needs a local file path or the data in a string which I wont have yet, just
a urllib.urlopen or requests.get stream or something. I guess if I can't
get the target drop location to download to I'll need to get / create a
DataObject than accepts a stream/file object and generates it's data that
way - am I correct in thinking this? and is there a way to currently do
this you know of?

Paul

···

On 14 November 2013 16:09, Mike Driscoll <kyosohma@gmail.com> wrote:

On Thursday, November 14, 2013 5:50:30 AM UTC-6, Paul wrote:

- Mike

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Paul,

Thanks for the reply Mike!

Getting the files is ok, I’m actually interacting with an API to list folders and files, which I’m displaying in the wxpython app, and the actual files download over http - sorry I should have perhaps explained that to begin with. This part isn’t a problem.

I also found an ftp app that’s written in wxPython that might help you, although it’s a little complex: http://ftpcube.sourceforge.net/download.html

I’ll check that out now :slight_smile:

The drop source doesn’t know anything about the file system, so there doesn’t appear to be a way that I can find that tells you what the drop target was if you drag outside of your application. You can read more here: http://stackoverflow.com/questions/13128328/drag-and-drop-application-created-file-to-explorer-window

If the drop source doesn’t know anything about the file system how is it able to copy files to the drop location as per the example in your article?

Yeah, I don’t quite understand how that works either. Somehow Windows Explorer (or whatever the local file manager is) can detect that a file has been dropped on it and just writes it. I think Robin explained this to me once, but I can’t find my notes on it. Hopefully he will drop in soon and let us know.

However, if you create a folder-tree in your application (like Filezilla), then you can control the drop target and know where something was dropped.

Unfortunately I’m not able to put a file system tree into the application like FileZilla, I’ll need to be able to copy items out of the app into the native file browser.

The problem I have is that the DropSource requires a DataObject, which needs a local file path or the data in a string which I wont have yet, just a urllib.urlopen or requests.get stream or something. I guess if I can’t get the target drop location to download to I’ll need to get / create a DataObject than accepts a stream/file object and generates it’s data that way - am I correct in thinking this? and is there a way to currently do this you know of?

Paul

Yeah, I was actually thinking along the same lines. You’ll probably have to download the file to some temp location before creating the DataObject. Then after the copy job is finished, you can delete the file from the temp location. You might be able to write the file to memory using something like StringIO and pass that to the DataObject.

  • Mike

Hi Paul,

Thanks for the reply Mike!

Getting the files is ok, I'm actually interacting with an API to list
folders and files, which I'm displaying in the wxpython app, and the actual
files download over http - sorry I should have perhaps explained that to
begin with. This part isn't a problem.

I also found an ftp app that's written in wxPython that might help you,
although it's a little complex: http://ftpcube.sourceforge.
net/download.html

I'll check that out now :slight_smile:

The drop source doesn't know anything about the file system, so there
doesn't appear to be a way that I can find that tells you what the drop
target was if you drag outside of your application. You can read more here:
python - Drag and drop application-created file to explorer window - Stack Overflow
drop-application-created-file-to-explorer-window

If the drop source doesn't know anything about the file system how is it
able to copy files to the drop location as per the example in your article?

Yeah, I don't quite understand how that works either. Somehow Windows
Explorer (or whatever the local file manager is) can detect that a file has
been dropped on it and just writes it. I think Robin explained this to me
once, but I can't find my notes on it. Hopefully he will drop in soon and
let us know.

However, if you create a folder-tree in your application (like
Filezilla), then you can control the drop target and know where something
was dropped.

Unfortunately I'm not able to put a file system tree into the application
like FileZilla, I'll need to be able to copy items out of the app into the
native file browser.

The problem I have is that the DropSource requires a DataObject, which
needs a local file path or the data in a string which I wont have yet, just
a urllib.urlopen or requests.get stream or something. I guess if I can't
get the target drop location to download to I'll need to get / create a
DataObject than accepts a stream/file object and generates it's data that
way - am I correct in thinking this? and is there a way to currently do
this you know of?

Paul

Yeah, I was actually thinking along the same lines. You'll probably have
to download the file to some temp location before creating the DataObject.
Then after the copy job is finished, you can delete the file from the temp
location. You might be able to write the file to memory using something
like StringIO and pass that to the DataObject.

I thought about this, I can download it to a temp location fine. The issue
is when the download completes I wont know where to move the file to.

And I think from my understanding the DataObject needs to have the file
data ready for when the user drops, which wont be possible if I have to
download it (plus I don't really want all the file data in memory as
there's no limit to how large these files can be).

- Mike

···

On 14 November 2013 19:13, Mike Driscoll <kyosohma@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

You may have to represent the computer’s flie system within your app and handle the drop internally instead of going out to an external application to handle the drop. At least, that’s what I did to handle sFTP file transfer in my application.

Applications can only handle drops for DataObject types they know. There are system data types for plain text (wx.TextDataObject()), images (wx.BitmapDataObject()) and file objects (wx.FileDataObject()), which are also built int wx. There are also “standard” types for things like formatted text which you can create using wx.CustomDataObject() and wx.DataObjectComposite() objects. (At least, I’ve cracked RTF transfer on Windows and OS X, but not Linux.) But you don’t have any of those things.

External apps won’t know how to handle your custom data type, which is really a reference to a file on an external system if I understand correctly rather than a reference to a file on the local file system. So you have to write your own OnDrop code that knows how to handle the reference you pass to it, transferring the file in your preferred way to your preferred location. I’m afraid you can’t count on others to have written that type of drop functionality for you.

Your other option would be to split your action into two parts – have the user download the file to your temporary location, and once that’s done, then it’s available for dragging to another application using a wx.FileDataObject() because then it’s just a local file which is a known type.

Hope that helps.

David

···

On Fri, Nov 15, 2013 at 5:53 AM, Paul Wiseman poalman@gmail.com wrote:

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

On 14 November 2013 19:13, Mike Driscoll kyosohma@gmail.com wrote:

Hi Paul,

Thanks for the reply Mike!

Getting the files is ok, I’m actually interacting with an API to list folders and files, which I’m displaying in the wxpython app, and the actual files download over http - sorry I should have perhaps explained that to begin with. This part isn’t a problem.

I also found an ftp app that’s written in wxPython that might help you, although it’s a little complex: http://ftpcube.sourceforge.net/download.html

I’ll check that out now :slight_smile:

The drop source doesn’t know anything about the file system, so there doesn’t appear to be a way that I can find that tells you what the drop target was if you drag outside of your application. You can read more here: http://stackoverflow.com/questions/13128328/drag-and-drop-application-created-file-to-explorer-window

If the drop source doesn’t know anything about the file system how is it able to copy files to the drop location as per the example in your article?

Yeah, I don’t quite understand how that works either. Somehow Windows Explorer (or whatever the local file manager is) can detect that a file has been dropped on it and just writes it. I think Robin explained this to me once, but I can’t find my notes on it. Hopefully he will drop in soon and let us know.

However, if you create a folder-tree in your application (like Filezilla), then you can control the drop target and know where something was dropped.

Unfortunately I’m not able to put a file system tree into the application like FileZilla, I’ll need to be able to copy items out of the app into the native file browser.

The problem I have is that the DropSource requires a DataObject, which needs a local file path or the data in a string which I wont have yet, just a urllib.urlopen or requests.get stream or something. I guess if I can’t get the target drop location to download to I’ll need to get / create a DataObject than accepts a stream/file object and generates it’s data that way - am I correct in thinking this? and is there a way to currently do this you know of?

Paul

Yeah, I was actually thinking along the same lines. You’ll probably have to download the file to some temp location before creating the DataObject. Then after the copy job is finished, you can delete the file from the temp location. You might be able to write the file to memory using something like StringIO and pass that to the DataObject.

I thought about this, I can download it to a temp location fine. The issue is when the download completes I wont know where to move the file to.

And I think from my understanding the DataObject needs to have the file data ready for when the user drops, which wont be possible if I have to download it (plus I don’t really want all the file data in memory as there’s no limit to how large these files can be).

  • Mike

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

You may have to represent the computer's flie system within your app and
handle the drop internally instead of going out to an external application
to handle the drop. At least, that's what I did to handle sFTP file
transfer in my application.

Applications can only handle drops for DataObject types they know. There
are system data types for plain text (wx.TextDataObject()), images
(wx.BitmapDataObject()) and file objects (wx.FileDataObject()), which are
also built int wx. There are also "standard" types for things like
formatted text which you can create using wx.CustomDataObject() and
wx.DataObjectComposite() objects. (At least, I've cracked RTF transfer on
Windows and OS X, but not Linux.) But you don't have any of those things.

External apps won't know how to handle your custom data type, which is
really a reference to a file on an external system if I understand
correctly rather than a reference to a file on the local file system. So
you have to write your own OnDrop code that knows how to handle the
reference you pass to it, transferring the file in your preferred way to
your preferred location. I'm afraid you can't count on others to have
written that type of drop functionality for you.

Your other option would be to split your action into two parts -- have the
user download the file to your temporary location, and once that's done,
then it's available for dragging to another application using a
wx.FileDataObject() because then it's just a local file which is a known
type.

Hope that helps.

David

Thanks for your replys guys.

Looks like this might not be possible for me to do then :frowning:

Is there any way at all to get the target location? Even maybe if I stick
some dummy data / file path into a DataObject and copy that just to get the
target drop location. Then I cloud delete it right after, download the
actual file that was dragged out before moving it to the target location.

···

On 15 November 2013 21:36, David Woods <david@badgerchildhoodcancer.org>wrote:

On Fri, Nov 15, 2013 at 5:53 AM, Paul Wiseman <poalman@gmail.com> wrote:

On 14 November 2013 19:13, Mike Driscoll <kyosohma@gmail.com> wrote:

Hi Paul,

Thanks for the reply Mike!

Getting the files is ok, I'm actually interacting with an API to list
folders and files, which I'm displaying in the wxpython app, and the actual
files download over http - sorry I should have perhaps explained that to
begin with. This part isn't a problem.

I also found an ftp app that's written in wxPython that might help
you, although it's a little complex: http://ftpcube.sourceforge.
net/download.html

I'll check that out now :slight_smile:

The drop source doesn't know anything about the file system, so there
doesn't appear to be a way that I can find that tells you what the drop
target was if you drag outside of your application. You can read more here:
python - Drag and drop application-created file to explorer window - Stack Overflow
drop-application-created-file-to-explorer-window

If the drop source doesn't know anything about the file system how is
it able to copy files to the drop location as per the example in your
article?

Yeah, I don't quite understand how that works either. Somehow Windows
Explorer (or whatever the local file manager is) can detect that a file has
been dropped on it and just writes it. I think Robin explained this to me
once, but I can't find my notes on it. Hopefully he will drop in soon and
let us know.

However, if you create a folder-tree in your application (like
Filezilla), then you can control the drop target and know where something
was dropped.

Unfortunately I'm not able to put a file system tree into the
application like FileZilla, I'll need to be able to copy items out of the
app into the native file browser.

The problem I have is that the DropSource requires a DataObject, which
needs a local file path or the data in a string which I wont have yet, just
a urllib.urlopen or requests.get stream or something. I guess if I can't
get the target drop location to download to I'll need to get / create a
DataObject than accepts a stream/file object and generates it's data that
way - am I correct in thinking this? and is there a way to currently do
this you know of?

Paul

Yeah, I was actually thinking along the same lines. You'll probably have
to download the file to some temp location before creating the DataObject.
Then after the copy job is finished, you can delete the file from the temp
location. You might be able to write the file to memory using something
like StringIO and pass that to the DataObject.

I thought about this, I can download it to a temp location fine. The
issue is when the download completes I wont know where to move the file to.

And I think from my understanding the DataObject needs to have the file
data ready for when the user drops, which wont be possible if I have to
download it (plus I don't really want all the file data in memory as
there's no limit to how large these files can be).

- Mike

--
You received this message because you are subscribed to the Google
Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Paul Wiseman wrote:

Is there any way at all to get the target location?

No. Keep in mind that the target is likely some other application written by some other entity, (Explorer and Microsoft in this case) and that the only communication back from the target to the source is a code indicating error, moved, copied or linked and those are intended to tell the source what to do with the original data object or the thing it represents. By that time it is too late for the source, because the target will already have received the data object and done something with it. From the time you call DoDragDrop it is the target's ball game, and he is just going to want to take the ball and go home.

···

--
Robin Dunn
Software Craftsman

David Woods wrote:

Your other option would be to split your action into two parts -- have
the user download the file to your temporary location, and once that's
done, then it's available for dragging to another application using a
wx.FileDataObject() because then it's just a local file which is a known
type.

That is my suggestion as well.

···

--
Robin Dunn
Software Craftsman