def Copy(self):
#print "Copy method"
# Number of rows and cols
rows = self.grid_1.GetSelectionBlockBottomRight()[0][0] - self.grid_1.GetSelectionBlockTopLeft()[0][0] + 1
cols = self.grid_1.GetSelectionBlockBottomRight()[0][1] - self.grid_1.GetSelectionBlockTopLeft()[0][1] + 1
# data variable contain text that must be set in the clipboard
data = ''
# For each cell in selected range append the cell value in the data variable
# Tabs '\t' for cols and '\r' for rows
for r in range(rows):
for c in range(cols):
data = data + str(self.grid_1.GetCellValue(self.grid_1.GetSelectionBlockTopLeft()[0][0] + r, self.grid_1.GetSelectionBlockTopLeft()[0][1] + c))
if c < cols - 1:
data = data + '\t'
data = data + '\n'
#print data
# Create text data object
clipboard = wx.TextDataObject()
# Set data object value
clipboard.SetText(data)
# Put the data in the clipboard
if wx.TheClipboard.Open():
wx.TheClipboard.SetData(clipboard)
wx.TheClipboard.Close()
else:
wx.MessageBox("Can't open the clipboard", "Error")
评论列表
文章目录