示例#1
0
 def copy(self):
     """Copy text to clipboard"""
     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:  # To copy indices
         contents = '\n'.join(
             map(str,
                 df.index.tolist()[slice(row_min, row_max + 1)]))
     else:  # To copy DataFrame
         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='\t', 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)
示例#2
0
 def copy(self):
     """Copy text to clipboard"""
     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:  # To copy indices
         contents = '\n'.join(map(str, df.index.tolist()[slice(row_min,
                                                         row_max+1)]))
     else:  # To copy DataFrame
         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='\t', 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)
 def copy(self):
     """Copy text to clipboard"""
     if not self.selectedIndexes():
         return
     (row_min, row_max, col_min,
      col_max) = get_idx_rect(self.selectedIndexes())
     index = header = False
     df = self.model().df
     obj = df.iloc[slice(row_min, row_max + 1), slice(col_min, col_max + 1)]
     output = io.StringIO()
     obj.to_csv(output, sep='\t', 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)