[Phoenix] Clipboard issues

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

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 anthony.tuininga@gmail.com wrote:

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

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

···

On Wednesday, May 7, 2014 10:44:30 PM UTC-6, Anthony Tuininga wrote:

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 anthony.tuininga@gmail.com wrote:

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

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.

···

On Wednesday, May 7, 2014 10:44:30 PM UTC-6, Anthony Tuininga wrote:

Hi,

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

Anthony

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. wxTrac has been migrated to GitHub Issues - wxWidgets
     """

     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

···

On 15.05.2014 22:39, Metallicow wrote:

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.

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.

···

On Thursday, May 15, 2014 3:04:09 PM UTC-6, greek0 wrote:

On 15.05.2014 22:39, Metallicow wrote:

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](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

Metallicow wrote:

     > 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. wxTrac has been migrated to GitHub Issues - wxWidgets
    <wxTrac has been migrated to GitHub Issues - wxWidgets;
    """

    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

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.

···

On Thursday, May 15, 2014 3:04:09 PM UTC-6, greek0 wrote:
    On 15.05.2014 22:39, Metallicow wrote:

--
Robin Dunn
Software Craftsman

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.

···

On Saturday, May 17, 2014 9:32:48 PM UTC-6, Robin Dunn wrote:

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