擅长:python、mysql、java
<p>如果有人感兴趣,最后的代码是:</p>
<pre><code>from eventbase import EventBase
import win32clipboard as clipboard
import os
import wx
class CopyEvent(EventBase):
TYPE = wx.NewEventType()
ID = wx.NewId()
BINDER = wx.PyEventBinder(TYPE, 1)
SHORTCUT_MODIFIER = wx.ACCEL_CTRL
SHORTCUT_KEY = ord('C')
def __init__(self, variable=None):
EventBase.__init__(self)
self._variable = variable
def execute(self, viewmodel, parent):
clipboard.OpenClipboard()
clipboard.EmptyClipboard()
text = self._convert_variable_to_text(self._variable)
clipboard.SetClipboardText(text)
clipboard.CloseClipboard()
self.logger.info("Copying variable to clipboard")
def _convert_variable_to_text(self, variable) :
lines = []
lines.append("\t".join(variable.column_names))
for row_nbr in variable.row_numbers:
lines.append("\t".join([repr(i) for i in variable.get_row_as_tuple(row_nbr)]))
return os.linesep.join(lines)
</code></pre>