Пример #1
0
 def copy_without_prompts(self):
     """Copy text to clipboard without prompts"""
     text = self.get_selected_text()
     lines = text.split(os.linesep)
     for index, line in enumerate(lines):
         if line.startswith('>>> ') or line.startswith('... '):
             lines[index] = line[4:]
     text = os.linesep.join(lines)
     QApplication.clipboard().setText(text)
Пример #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)
Пример #3
0
 def mousePressEvent(self, event):
     """Reimplement Qt method"""
     if sys.platform.startswith('linux') and event.button() == Qt.MidButton:
         self.calltip_widget.hide()
         if self.has_selected_text():
             self.remove_selected_text()
         self.setFocus()
         event = QMouseEvent(QEvent.MouseButtonPress, event.pos(),
                             Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
         QPlainTextEdit.mousePressEvent(self, event)
         QPlainTextEdit.mouseReleaseEvent(self, event)
         # Send selection text to clipboard to be able to use
         # the paste method and avoid the strange Issue 1445
         #
         # Note: This issue seems a focusing problem but it
         # seems really hard to track
         mode_clip = QClipboard.Clipboard
         mode_sel = QClipboard.Selection
         text_clip = QApplication.clipboard().text(mode=mode_clip)
         text_sel = QApplication.clipboard().text(mode=mode_sel)
         QApplication.clipboard().setText(text_sel, mode=mode_clip)
         self.paste()
         QApplication.clipboard().setText(text_clip, mode=mode_clip)
     else:
         self.calltip_widget.hide()
         QPlainTextEdit.mousePressEvent(self, event)
Пример #4
0
 def paste(self):
     """Reimplemented slot to handle multiline paste action"""
     text = to_text_string(QApplication.clipboard().text())
     if len(text.splitlines()) > 1:
         # Multiline paste
         if self.new_input_line:
             self.on_new_line()
         self.remove_selected_text() # Remove selection, eventually
         end = self.get_current_line_from_cursor()
         lines = self.get_current_line_to_cursor() + text + end
         self.clear_line()
         self.execute_lines(lines)
         self.move_cursor(-len(end))
     else:
         # Standard paste
         ShellBaseWidget.paste(self)
Пример #5
0
 def copy(self, index=False, header=False):
     """Copy text to clipboard"""
     (row_min, row_max,
      col_min, col_max) = get_idx_rect(self.selectedIndexes())
     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 df.shape[0] == row_max+1 and row_min == 0:
             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)
         contents = output.getvalue()
         output.close()
     clipboard = QApplication.clipboard()
     clipboard.setText(contents)
Пример #6
0
 def copy(self):
     """Copy text to clipboard"""
     (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)
         contents = output.getvalue()
         output.close()
     clipboard = QApplication.clipboard()
     clipboard.setText(contents)
Пример #7
0
 def mousePressEvent(self, event):
     """Reimplement Qt method"""
     if sys.platform.startswith('linux') and event.button() == Qt.MidButton:
         self.calltip_widget.hide()
         self.setFocus()
         event = QMouseEvent(QEvent.MouseButtonPress, event.pos(),
                             Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
         QPlainTextEdit.mousePressEvent(self, event)
         QPlainTextEdit.mouseReleaseEvent(self, event)
         # Send selection text to clipboard to be able to use
         # the paste method and avoid the strange Issue 1445
         # NOTE: This issue seems a focusing problem but it
         # seems really hard to track
         mode_clip = QClipboard.Clipboard
         mode_sel = QClipboard.Selection
         text_clip = QApplication.clipboard().text(mode=mode_clip)
         text_sel = QApplication.clipboard().text(mode=mode_sel)
         QApplication.clipboard().setText(text_sel, mode=mode_clip)
         self.paste()
         QApplication.clipboard().setText(text_clip, mode=mode_clip)
     else:
         self.calltip_widget.hide()
         QPlainTextEdit.mousePressEvent(self, event)
Пример #8
0
 def copy(self):
     """Copy text to clipboard"""
     cliptxt = self._sel_to_text( self.selectedIndexes() )
     clipboard = QApplication.clipboard()
     clipboard.setText(cliptxt)
Пример #9
0
 def copy(self):
     """
     Reimplement Qt method
     Copy text to clipboard with correct EOL chars
     """
     QApplication.clipboard().setText(self.get_selected_text())
Пример #10
0
 def paste(self):
     """Reimplement Qt method"""
     if self.has_selected_text():
         self.remove_selected_text()
     self.insert_text(QApplication.clipboard().text())
Пример #11
0
 def copy_to_clipboard(self):
     from spyderlib.dependencies import status
     QApplication.clipboard().setText(status())
Пример #12
0
 def copy(self):
     """Copy text to clipboard"""
     cliptxt = self._sel_to_text(self.selectedIndexes())
     clipboard = QApplication.clipboard()
     clipboard.setText(cliptxt)
Пример #13
0
 def copy_to_clipboard(self):
     from spyderlib.dependencies import status
     QApplication.clipboard().setText(status())
Пример #14
0
 def copy(self):
     """
     Reimplement Qt method
     Copy text to clipboard with correct EOL chars
     """
     QApplication.clipboard().setText(self.get_selected_text())
Пример #15
0
 def paste(self):
     """Reimplement Qt method"""
     if self.has_selected_text():
         self.remove_selected_text()
     self.insert_text(QApplication.clipboard().text())