def _on_right_click(self, event):
"""
Copies a cell into clipboard on right click. Unfortunately,
determining the clicked column is not straightforward. This
appraoch is inspired by the TextEditMixin in:
/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/lib/mixins/listctrl.py
More references:
- http://wxpython-users.1045709.n5.nabble.com/Getting-row-col-of-selected-cell-in-ListCtrl-td2360831.html
- https://groups.google.com/forum/#!topic/wxpython-users/7BNl9TA5Y5U
- https://groups.google.com/forum/#!topic/wxpython-users/wyayJIARG8c
"""
if self.HitTest(event.GetPosition()) != wx.NOT_FOUND:
x, y = event.GetPosition()
row, flags = self.HitTest((x, y))
col_locs = [0]
loc = 0
for n in range(self.GetColumnCount()):
loc = loc + self.GetColumnWidth(n)
col_locs.append(loc)
scroll_pos = self.GetScrollPos(wx.HORIZONTAL)
# this is crucial step to get the scroll pixel units
unit_x, unit_y = self.GetMainWindow().GetScrollPixelsPerUnit()
col = bisect(col_locs, x + scroll_pos * unit_x) - 1
value = self.df.iloc[row, col]
# print(row, col, scroll_pos, value)
clipdata = wx.TextDataObject()
clipdata.SetText(str(value))
wx.TheClipboard.Open()
wx.TheClipboard.SetData(clipdata)
wx.TheClipboard.Close()
评论列表
文章目录