'Sanitizes code from interactive window, removing prompts and output,
and inserts it in the clipboard.'

def OnEditCopyCode(self, command, code):

    code = self.GetSelText()
    lines = code.splitlines()
    out_lines = []
    for line in lines:
        if line.startswith(sys.ps1):
            line = line[len(sys.ps1):]
            out_lines.append(line)
        elif line.startswith(sys.ps2):
            line = line[len(sys.ps2):]
            out_lines.append(line)
    out_code = os.linesep.join(out_lines)
    win32clipboard.OpenClipboard()
    try:
        win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, unicode(out_code))
    finally:
        win32clipboard.CloseClipboard()
