can't copy regular files to clipboard

method one:

wx.TheClipboard.Open():
wx.TheClipboard.Clear()
obj = wx.TextDataObject("/home/myhome/file")
wx.TheClipboard.SetData(obj)
wx.TheClipboard.Close()

method two:

wx.TheClipboard.Open():
wx.TheClipboard.Clear()
self.temp = wx.FileDataObject()
self.temp.AddFile("/home/myhome/file")
wx.TheClipboard.SetData(self.temp)
wx.TheClipboard.Close()

method one just copy the file address, i can paste it on a text editor
but i can't in the filemanager
method two does nothing, i can't paste anything in the texteditor nor
in the filemanager (although rightclicking on a "terminal" i can see
"paste filenames" but not "paste", anyway still does not paste
anything)
any ideas? (i'm using nautilus on gnome)
thanks

Hi,

copy-and-paste.py (1.37 KB)

···

On Fri, Oct 9, 2009 at 11:56 AM, Notch-1 notch1@gmail.com wrote:

method one:

wx.TheClipboard.Open():

wx.TheClipboard.Clear()

obj = wx.TextDataObject("/home/myhome/file")

wx.TheClipboard.SetData(obj)

wx.TheClipboard.Close()

method two:

wx.TheClipboard.Open():

wx.TheClipboard.Clear()

self.temp = wx.FileDataObject()

self.temp.AddFile("/home/myhome/file")

wx.TheClipboard.SetData(self.temp)

wx.TheClipboard.Close()

method one just copy the file address, i can paste it on a text editor

but i can’t in the filemanager

method two does nothing, i can’t paste anything in the texteditor nor

in the filemanager (although rightclicking on a “terminal” i can see

“paste filenames” but not “paste”, anyway still does not paste

anything)

any ideas? (i’m using nautilus on gnome)

thanks

I don’t know if this is what you’re looking for or not, but I’ve attached one way of doing it.


Mike Driscoll

Blog: http://blog.pythonlibrary.org

nope, i can only paste into the texteditor, i need to copy & paste a
file (to the filemanager)...
thank you anyway

Mike Driscoll ha scritto:

···

Hi,

On Fri, Oct 9, 2009 at 11:56 AM, Notch-1 <notch1@gmail.com> wrote:

>
> method one:
>
> wx.TheClipboard.Open():
> wx.TheClipboard.Clear()
> obj = wx.TextDataObject("/home/myhome/file")
> wx.TheClipboard.SetData(obj)
> wx.TheClipboard.Close()
>
>
> method two:
>
> wx.TheClipboard.Open():
> wx.TheClipboard.Clear()
> self.temp = wx.FileDataObject()
> self.temp.AddFile("/home/myhome/file")
> wx.TheClipboard.SetData(self.temp)
> wx.TheClipboard.Close()
>
> method one just copy the file address, i can paste it on a text editor
> but i can't in the filemanager
> method two does nothing, i can't paste anything in the texteditor nor
> in the filemanager (although rightclicking on a "terminal" i can see
> "paste filenames" but not "paste", anyway still does not paste
> anything)
> any ideas? (i'm using nautilus on gnome)
> thanks
>

I don't know if this is what you're looking for or not, but I've attached
one way of doing it.

-----------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Looks like it is working the other direction (copy in nautilus and GetData in wx to paste) so the data object and data format are correct. Code like the above works on Windows. So my guess is that there is a bug in wxGTK specific code, (although I suppose there is a slight chance the bug is in nautilus which can be checked by trying it with some other file manager.)

You may want to ask about this on wx-users where people more familiar with GTK will see it and may know of a workaround, and also create a ticket about it at wxTrac.

···

On 10/9/09 9:56 AM, Notch-1 wrote:

method two:

wx.TheClipboard.Open():
wx.TheClipboard.Clear()
self.temp = wx.FileDataObject()
self.temp.AddFile("/home/myhome/file")
wx.TheClipboard.SetData(self.temp)
wx.TheClipboard.Close()

method one just copy the file address, i can paste it on a text editor
but i can't in the filemanager
method two does nothing, i can't paste anything in the texteditor nor
in the filemanager (although rightclicking on a "terminal" i can see
"paste filenames" but not "paste", anyway still does not paste
anything)
any ideas? (i'm using nautilus on gnome)

--
Robin Dunn
Software Craftsman
http://wxPython.org

are you saying that on windows if you copy the file name you can past
the file itself, instead of getting pasted only the filename? if so
this is indeed a bug...
could somebody test this on other systems, like kde?

Robin Dunn ha scritto:

···

On 10/9/09 9:56 AM, Notch-1 wrote:

> method two:
>
> wx.TheClipboard.Open():
> wx.TheClipboard.Clear()
> self.temp = wx.FileDataObject()
> self.temp.AddFile("/home/myhome/file")
> wx.TheClipboard.SetData(self.temp)
> wx.TheClipboard.Close()
>
> method one just copy the file address, i can paste it on a text editor
> but i can't in the filemanager
> method two does nothing, i can't paste anything in the texteditor nor
> in the filemanager (although rightclicking on a "terminal" i can see
> "paste filenames" but not "paste", anyway still does not paste
> anything)
> any ideas? (i'm using nautilus on gnome)

Looks like it is working the other direction (copy in nautilus and
GetData in wx to paste) so the data object and data format are correct.
  Code like the above works on Windows. So my guess is that there is a
bug in wxGTK specific code, (although I suppose there is a slight chance
the bug is in nautilus which can be checked by trying it with some other
file manager.)

You may want to ask about this on wx-users where people more familiar
with GTK will see it and may know of a workaround, and also create a
ticket about it at wxTrac.

--
Robin Dunn
Software Craftsman
http://wxPython.org

i figured out that with a wx.Sleep(60) in the end of each method i can
get the "Paste" menu item to be active (so there is indeed a
availability problem), but anyway when i click on it i get an error
message in the status bar (something like "the clipboard contains no
data")...
did anyone ever successfully copied a file to the clipboard?
thanks

new tests:
1) if i copy a file by hand (on nautilus) and then read the clipboard,
clear it and add a file with method two and re-read the clipboard, i
can't see any difference between the 2 readings;
2) i even tried to copy a file with nautilus and add a new file with
python... if i read the clipboard with GetData() i get the 2 files,
but still can't paste them...
3) on kde i never even got the "paste" menu item enabled...

complete updated code to reproduce (only for method two, but i think
it's quite the same):

#!/usr/bin/env python

import wxversion
wxversion.select('2.8.0.1')
import wx, wx.html

def main():
  app = wx.PySimpleApp(False)
  app.MainLoop()

  print "CLIP1", wx.TheClipboard.Open(), wx.TheClipboard.Clear()

  do1 = wx.FileDataObject()
  print do1.AddFile("/home/a-file")
  print "CLIP2",wx.TheClipboard.SetData(do1), do1

  do2 = wx.FileDataObject()
  print "CLIP3",wx.TheClipboard.GetData(do2), do2
  print "CLIP4",do2.GetDataHere()

  wx.Sleep(60) #DO NOT REMOVE THIS ONE

  return 0

if __name__ == '__main__': main()

filed a bug on http://trac.wxwidgets.org/ticket/11354
any workarounds?

Hello,

new tests:
1) if i copy a file by hand (on nautilus) and then read the clipboard,
clear it and add a file with method two and re-read the clipboard, i
can't see any difference between the 2 readings;
2) i even tried to copy a file with nautilus and add a new file with
python... if i read the clipboard with GetData() i get the 2 files,
but still can't paste them...
3) on kde i never even got the "paste" menu item enabled...

complete updated code to reproduce (only for method two, but i think
it's quite the same):

#!/usr/bin/env python

import wxversion
wxversion.select('2.8.0.1')
import wx, wx.html

def main():
app = wx.PySimpleApp(False)
app.MainLoop()

   print &quot;CLIP1&quot;, wx\.TheClipboard\.Open\(\), wx\.TheClipboard\.Clear\(\)

   do1 = wx\.FileDataObject\(\)
   print do1\.AddFile\(&quot;/home/a\-file&quot;\)
   print &quot;CLIP2&quot;,wx\.TheClipboard\.SetData\(do1\), do1

   do2 = wx\.FileDataObject\(\)
   print &quot;CLIP3&quot;,wx\.TheClipboard\.GetData\(do2\), do2
   print &quot;CLIP4&quot;,do2\.GetDataHere\(\)

   wx\.Sleep\(60\) \#DO NOT REMOVE THIS ONE

   return 0

if __name__ == '__main__': main()

When wx exits it clears its clipboard data, that is why you can see it
shortly when you have this sleep in.

I don't think it should clear the data but there have been discussions
about this on wx-dev a few times in the past and they always ended in
saying that it should be cleared. You can try searching the wx-dev
archives for these messages.

Cody

···

On Mon, Oct 19, 2009 at 12:00 PM, Notch-1 <notch1@gmail.com> wrote:

yes but while i can see the files in the clipboard with python i still
can't paste them on nautilus...
i saw other posts like you said, but i think my problem is different:
i've never been able to paste other than text.
i agree that with this code when i close the app i can't access
anymore the data on the clipboard, but it's another problem... maybe
solvable with the flush() function, i don't know/care jet...

···

On 19 Ott, 19:41, Cody Precord <codyprec...@gmail.com> wrote:

Hello,

On Mon, Oct 19, 2009 at 12:00 PM, Notch-1 <not...@gmail.com> wrote:

> new tests:
> 1) if i copy a file by hand (on nautilus) and then read the clipboard,
> clear it and add a file with method two and re-read the clipboard, i
> can't see any difference between the 2 readings;
> 2) i even tried to copy a file with nautilus and add a new file with
> python... if i read the clipboard with GetData() i get the 2 files,
> but still can't paste them...
> 3) on kde i never even got the "paste" menu item enabled...

> complete updated code to reproduce (only for method two, but i think
> it's quite the same):

> #!/usr/bin/env python

> import wxversion
> wxversion.select('2.8.0.1')
> import wx, wx.html

> def main():
> app = wx.PySimpleApp(False)
> app.MainLoop()

> print "CLIP1", wx.TheClipboard.Open(), wx.TheClipboard.Clear()

> do1 = wx.FileDataObject()
> print do1.AddFile("/home/a-file")
> print "CLIP2",wx.TheClipboard.SetData(do1), do1

> do2 = wx.FileDataObject()
> print "CLIP3",wx.TheClipboard.GetData(do2), do2
> print "CLIP4",do2.GetDataHere()

> wx.Sleep(60) #DO NOT REMOVE THIS ONE

> return 0

> if __name__ == '__main__': main()

When wx exits it clears its clipboard data, that is why you can see it
shortly when you have this sleep in.

I don't think it should clear the data but there have been discussions
about this on wx-dev a few times in the past and they always ended in
saying that it should be cleared. You can try searching the wx-dev
archives for these messages.

Cody