Discussion:
[Phoenix] Clipboard issues
Anthony Tuininga
2014-05-07 22:25:04 UTC
Permalink
Hi,

I was just trying the latest version of wxPython_Phoenix (3.0.1.dev76465)
and almost all of my code that was developed with 2.8 works perfectly. I
noticed, however, that the clipboard does not appear to work properly. I
cannot retrieve data from the clipboard or put data on the clipboard (that
any other application can use, that is) whereas the same code worked fine
with both 2.8 and 3.0 (classic). This is the code:

import wx

print "VERSION:", wx.version()
dummyApp = wx.App(0)
data = wx.TextDataObject()
clipboard = wx.TheClipboard
if clipboard.Open():
if clipboard.GetData(data):
print "FOUND ON CLIPBOARD:", data.GetText()
clipboard.Close()

This is on Windows 7 with Python 2.7 32-bit. I will try Linux as well and
see if this is a bug that spans platforms and report back -- but can anyone
else verify that this is a problem and why that might be? Thanks.

Anthony
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Anthony Tuininga
2014-05-08 04:44:30 UTC
Permalink
Hi,

Just verified that it works fine on Linux so it appears to be a Windows
specific bug.

Anthony
Post by Anthony Tuininga
Hi,
I was just trying the latest version of wxPython_Phoenix (3.0.1.dev76465)
and almost all of my code that was developed with 2.8 works perfectly. I
noticed, however, that the clipboard does not appear to work properly. I
cannot retrieve data from the clipboard or put data on the clipboard (that
any other application can use, that is) whereas the same code worked fine
import wx
print "VERSION:", wx.version()
dummyApp = wx.App(0)
data = wx.TextDataObject()
clipboard = wx.TheClipboard
print "FOUND ON CLIPBOARD:", data.GetText()
clipboard.Close()
This is on Windows 7 with Python 2.7 32-bit. I will try Linux as well and
see if this is a bug that spans platforms and report back -- but can anyone
else verify that this is a problem and why that might be? Thanks.
Anthony
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Anthony Tuininga
2014-05-08 13:49:18 UTC
Permalink
And here is another tidbit of information. Found out that someone else
experienced this a couple of months ago and found a workaround as well as
filed a bug:

http://trac.wxwidgets.org/ticket/15488
Post by Anthony Tuininga
Hi,
Just verified that it works fine on Linux so it appears to be a Windows
specific bug.
Anthony
On Wed, May 7, 2014 at 4:25 PM, Anthony Tuininga <
Post by Anthony Tuininga
Hi,
I was just trying the latest version of wxPython_Phoenix (3.0.1.dev76465)
and almost all of my code that was developed with 2.8 works perfectly. I
noticed, however, that the clipboard does not appear to work properly. I
cannot retrieve data from the clipboard or put data on the clipboard (that
any other application can use, that is) whereas the same code worked fine
import wx
print "VERSION:", wx.version()
dummyApp = wx.App(0)
data = wx.TextDataObject()
clipboard = wx.TheClipboard
print "FOUND ON CLIPBOARD:", data.GetText()
clipboard.Close()
This is on Windows 7 with Python 2.7 32-bit. I will try Linux as well and
see if this is a bug that spans platforms and report back -- but can anyone
else verify that this is a problem and why that might be? Thanks.
Anthony
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Metallicow
2014-05-15 20:39:54 UTC
Permalink
Post by Anthony Tuininga
Hi,
Just verified that it works fine on Linux so it appears to be a Windows
specific bug.
Anthony
This has been observed for some time now, tho I didn't realize it was OS
specific as I didn't bother checking at the time as I was working on
windows.
I wrote a bit of a hack to work around it(apparently for just windows) in
the mean time until Robin can figure out a fix for it.

Anyway, when I needed to copy something basically the Menu
HotKeys(Ctrl+C/etc) was still working so I just created a hidden STC and
programmatically
copied text/etc to it then used StyledTextCtrl.Copy to get the data onto
the clipboard.
Note: this is just a workaround hack I implemented and not recommended
longterm, but it does work in the meantime until a proper fix is
implemented,
because line enders handling and alot of the other built-in features the
clipboard sometimes does for you by default depending on your settings are
not implemented basically.

Hopefully this fix will come sooner than later(as it is an major usability
irritation), as there is still quite a few (more major crashy)things on the
phoenix TODO list also.
I think this was added recently, so it should at least not be forgotten.
Thanks for reporting it.
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Christian Aichinger
2014-05-15 21:04:09 UTC
Permalink
Post by Metallicow
I wrote a bit of a hack to work around it(apparently for just windows)
in the mean time until Robin can figure out a fix for it.
[...] I just created a hidden STC and programmatically
copied text/etc to it then used StyledTextCtrl.Copy to get the data onto
the clipboard.
Hi!
I also implemented a workaround, based on the suggestion by tizytissy in
bug 15448. Basically, just re-implement class TextDataObject. This seems
like a cleaner approach, even if it's just a temporary workaround.

Python3 example code:

class CustomTextDataObject(wx.DataObjectSimple):
"""Reimplementation of wx.TextDataObject

wx.TextDataObject is currently (2014.05.03) bugged in Phoenix.
Reimplement it until a fix is available.

Cf. http://trac.wxwidgets.org/ticket/15488
"""

def __init__(self, txt=''):
super().__init__()
self.SetFormat(wx.DataFormat(wx.DF_TEXT))
self.SetText(txt)

def GetDataSize(self):
return len(self.value)

def GetDataHere(self, buf):
buf[:] = self.value
return True

def SetData(self, buf):
self.value = buf.tobytes()
return True

def GetText(self):
return str(self.value, 'utf8')

def SetText(self, txt):
self.value = bytes(txt + ' ', 'utf8')

Usage example:
if not wx.TheClipboard.Open():
raise RuntimeError("Failed to open clipboard")
tdo = CustomTextDataObject(text_to_copy)
try:
wx.TheClipboard.SetData(tdo)
finally:
wx.TheClipboard.Close()

Take special care to close TheClipboard again after SetData(), I had
hangs on program exit otherwise, I think.

Best wishes,
Chris
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Metallicow
2014-05-16 06:20:50 UTC
Permalink
Post by Christian Aichinger
Post by Metallicow
I wrote a bit of a hack to work around it(apparently for just windows)
in the mean time until Robin can figure out a fix for it.
[...] I just created a hidden STC and programmatically
copied text/etc to it then used StyledTextCtrl.Copy to get the data onto
the clipboard.
Hi!
I also implemented a workaround, based on the suggestion by tizytissy in
bug 15448. Basically, just re-implement class TextDataObject. This seems
like a cleaner approach, even if it's just a temporary workaround.
"""Reimplementation of wx.TextDataObject
wx.TextDataObject is currently (2014.05.03) bugged in Phoenix.
Reimplement it until a fix is available.
Cf. http://trac.wxwidgets.org/ticket/15488
"""
super().__init__()
self.SetFormat(wx.DataFormat(wx.DF_TEXT))
self.SetText(txt)
return len(self.value)
buf[:] = self.value
return True
self.value = buf.tobytes()
return True
return str(self.value, 'utf8')
self.value = bytes(txt + ' ', 'utf8')
raise RuntimeError("Failed to open clipboard")
tdo = CustomTextDataObject(text_to_copy)
wx.TheClipboard.SetData(tdo)
wx.TheClipboard.Close()
Take special care to close TheClipboard again after SetData(), I had
hangs on program exit otherwise, I think.
Best wishes,
Chris
Yeah, that is a bit cleaner hack overall but still uses TheClipboard which
I believe something in it is part of the problem,
but a real proper workaround/comparable class would use the
win32 bindings or ctypes equivalent if this is a windows only bug.
Not sure if mac is affected also(Robin has a mac, so he could confirm this).
But then again, I was being a bit lazy at the time of writing my hack
hoping for a quick fix a bit sooner.
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robin Dunn
2014-05-18 03:32:48 UTC
Permalink
Post by Metallicow
Post by Metallicow
I wrote a bit of a hack to work around it(apparently for just
windows)
Post by Metallicow
in the mean time until Robin can figure out a fix for it.
[...] I just created a hidden STC and programmatically
copied text/etc to it then used StyledTextCtrl.Copy to get the
data onto
Post by Metallicow
the clipboard.
Hi!
I also implemented a workaround, based on the suggestion by tizytissy in
bug 15448. Basically, just re-implement class TextDataObject. This seems
like a cleaner approach, even if it's just a temporary workaround.
"""Reimplementation of wx.TextDataObject
wx.TextDataObject is currently (2014.05.03) bugged in Phoenix.
Reimplement it until a fix is available.
Cf. http://trac.wxwidgets.org/ticket/15488
<http://trac.wxwidgets.org/ticket/15488>
"""
super().__init__()
self.SetFormat(wx.DataFormat(wx.DF_TEXT))
self.SetText(txt)
return len(self.value)
buf[:] = self.value
return True
self.value = buf.tobytes()
return True
return str(self.value, 'utf8')
self.value = bytes(txt + ' ', 'utf8')
raise RuntimeError("Failed to open clipboard")
tdo = CustomTextDataObject(text_to_copy)
wx.TheClipboard.SetData(tdo)
wx.TheClipboard.Close()
Take special care to close TheClipboard again after SetData(), I had
hangs on program exit otherwise, I think.
Best wishes,
Chris
Yeah, that is a bit cleaner hack overall but still uses TheClipboard
which I believe something in it is part of the problem,
but a real proper workaround/comparable class would use the
win32 bindings or ctypes equivalent if this is a windows only bug.
Not sure if mac is affected also(Robin has a mac, so he could confirm this).
But then again, I was being a bit lazy at the time of writing my hack
hoping for a quick fix a bit sooner.
It should be fixed now, along with some other data object and clipboard
issues. Please try it again in the next build.

There is still an issue on Mac when using a class derived from
wx.DataObject or wx.DataObjectSimple and using the stock wx.DF_TEXT
format, but that will require changes in the wxWidgets code. Hopefully
that should be a much less frequently used use case though, now that
wx.TextDataObject is working.
--
Robin Dunn
Software Craftsman
http://wxPython.org
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Metallicow
2014-05-20 03:34:29 UTC
Permalink
Post by Robin Dunn
It should be fixed now, along with some other data object and clipboard
issues. Please try it again in the next build.
There is still an issue on Mac when using a class derived from
wx.DataObject or wx.DataObjectSimple and using the stock wx.DF_TEXT
format, but that will require changes in the wxWidgets code. Hopefully
that should be a much less frequently used use case though, now that
wx.TextDataObject is working.
--
Robin Dunn
Software Craftsman
http://wxPython.org
Tested and working on
wxPython_Phoenix-3.0.1.dev76577-cp27-none-win32.whl

Thanks Robin.
I guess you know better what the Mac end of the wxWidgets fix would be...,
so besides that everything else seems to be working fine(what I would deem
normal) now for win/linux.
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...