A working example:
import wx
class Frame(wx.Frame):
def __init__(self):
super(Frame, self).__init__(None, -1, "List copy test", size=(400, 500))
panel = wx.Panel(self, -1)
self.listCtrl = wx.ListCtrl(panel, -1, size=(200, 400), style=wx.LC_REPORT)
self.listCtrl.InsertColumn(0, "Column 1", width=180)
for i in xrange(10):
self.listCtrl.InsertStringItem(i, "Item %d" % i)
self.listCtrl.Bind(wx.EVT_RIGHT_UP, self.ShowPopup)
def ShowPopup(self, event):
menu = wx.Menu()
menu.Append(1, "Copy selected items")
menu.Bind(wx.EVT_MENU, self.CopyItems, id=1)
self.PopupMenu(menu)
def CopyItems(self, event):
selectedItems = []
for i in xrange(self.listCtrl.GetItemCount()):
if self.listCtrl.IsSelected(i):
selectedItems.append(self.listCtrl.GetItemText(i))
clipdata = wx.TextDataObject()
clipdata.SetText("\n".join(selectedItems))
wx.TheClipboard.Open()
wx.TheClipboard.SetData(clipdata)
wx.TheClipboard.Close()
print "Items are on the clipboard"
app = wx.App(redirect=False)
frame = Frame()
frame.Show()
app.MainLoop()
You mentioned a list control, but if you want to select multiple cells, perhaps a grid control (excel sheet like) might be more suitable. The idea is still the same only the part where the list items (or cell items) are collected is different.