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