copy-to-clipboard problem

I'm trying (simply!) to copy selected text (in a childSTC) to the system clipboard. This is Mac 10.3.6, wxPython 2.5.3.1.) I've followed the docs far enough to make the following code *think* it's working. But nothing is showing up in the clipboard. What am I doing wrong?

···

============================
def CopySelection(self, evt):
  if not wx.TheClipboard.Open(): return
  seltxt = self.mySTC.GetSelectedText()
  if len(seltxt) > 0:
    clipdata = wx.CustomDataObject()
    clipdata.SetData(seltxt)
    wx.TheClipboard.SetData(clipdata)
  wx.TheClipboard.Close()

Charles Hartman
Professor of English, Poet in Residence
http://cherry.conncoll.edu/cohar
http://villex.blogspot.com

Also, take a look at the Shell class in the shell.py file of the Py module. The Copy() and Paste() methods of that class copy and put data -other than the selected text- from and to the clipboard. Here is a transcript.

To copy text to the clipboard:

  t = wx.TextDataObject(text)
  c = wx.TheClipboard
  if c.Open():
     c.UsePrimarySelection(False)
     c.SetData(t)
     c.Flush()
     c.Close()

To get text from the clipboard:

  text = None
  c = wx.TheClipboard
  if c.Open():
     if c.IsSupported(wx.DataFormat(wx.DF_TEXT)):
        t = wx.TextDataObject()
        if c.GetData(t):
           text = t.GetText()
     c.Close()

/Jean Brouwers

Robin Dunn wrote:

···

Charles Hartman wrote:

I'm trying (simply!) to copy selected text (in a childSTC) to the system clipboard. This is Mac 10.3.6, wxPython 2.5.3.1.) I've followed the docs far enough to make the following code *think* it's working. But nothing is showing up in the clipboard. What am I doing wrong?

============================
def CopySelection(self, evt):
    if not wx.TheClipboard.Open(): return
    seltxt = self.mySTC.GetSelectedText()
    if len(seltxt) > 0:
        clipdata = wx.CustomDataObject()
        clipdata.SetData(seltxt)
        wx.TheClipboard.SetData(clipdata)
    wx.TheClipboard.Close()

The wxSTC can already handle the clipboard itself, just call self.mySTC.Copy()