how to put multiple objects in the clipboard : Clipboard « wxPython « Python Tutorial






import wx
import cPickle
import pprint

class TestFrame(wx.Frame):
    fieldNames = ["name", "addr1", "addr2","city", "state", "zip", "phone", "email"]

    def __init__(self):
        fieldData = {}
        for name in self.fieldNames:
            tc = getattr(self, name)
            fieldData[name] = tc.GetValue()

        cdo = wx.CustomDataObject("ContactDictFormat")
        cdo.SetData(cPickle.dumps(fieldData))

        tdo = wx.TextDataObject(pprint.pformat(fieldData))

        dataobj = wx.DataObjectComposite()
        dataobj.Add(cdo)
        dataobj.Add(tdo)
        if wx.TheClipboard.Open():
            wx.TheClipboard.SetData(dataobj)
            wx.TheClipboard.Close()

        
        cdo = wx.CustomDataObject("ContactDictFormat")
        if wx.TheClipboard.Open():
            success = wx.TheClipboard.GetData(cdo)
            wx.TheClipboard.Close()
        if success:
            data = cdo.GetData()
            fieldData = cPickle.loads(data)
            for name in self.fieldNames:
                tc = getattr(self, name)
                tc.SetValue(fieldData[name])

app = wx.PySimpleApp()
app.MainLoop()








19.5.Clipboard
19.5.1.work with Clipboard
19.5.2.how to put multiple objects in the clipboard