'Copy text to clipboard'

@Slot()
def copy(self):

    if (not self.selectedIndexes()):
        return
    (row_min, row_max, col_min, col_max) = get_idx_rect(self.selectedIndexes())
    index = header = False
    if (col_min == 0):
        col_min = 1
        index = True
    df = self.model().df
    if (col_max == 0):
        contents = '\n'.join(map(str, df.index.tolist()[slice(row_min, (row_max + 1))]))
    else:
        if (((col_min == 0) or (col_min == 1)) and (df.shape[1] == col_max)):
            header = True
        obj = df.iloc[(slice(row_min, (row_max + 1)), slice((col_min - 1), col_max))]
        output = io.StringIO()
        obj.to_csv(output, sep=' DCTB ', index=index, header=header)
        if (not PY2):
            contents = output.getvalue()
        else:
            contents = output.getvalue().decode('utf-8')
        output.close()
    clipboard = QApplication.clipboard()
    clipboard.setText(contents)
