Skip to content

Commit

Permalink
qtconsole : allow copy with shortcut in pager
Browse files Browse the repository at this point in the history
	closes ipython#1088
  • Loading branch information
Carreau committed Dec 3, 2011
1 parent beb2bd6 commit b071c87
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
7 changes: 6 additions & 1 deletion IPython/frontend/qt/console/console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,12 @@ def clear(self, keep_input=True):
def copy(self):
""" Copy the currently selected text to the clipboard.
"""
self._control.copy()
if self.layout().currentWidget() == self._page_control :
self._page_control.copy()
elif self.layout().currentWidget() == self._control :
self._control.copy()
else :
self.log.debug("console widget: unknown copy target")

def cut(self):
""" Copy the currently selected text to the clipboard and delete it
Expand Down
15 changes: 10 additions & 5 deletions IPython/frontend/qt/console/frontend_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,16 @@ def __init__(self, *args, **kw):
def copy(self):
""" Copy the currently selected text to the clipboard, removing prompts.
"""
text = self._control.textCursor().selection().toPlainText()
if text:
lines = map(transform_classic_prompt, text.splitlines())
text = '\n'.join(lines)
QtGui.QApplication.clipboard().setText(text)
if self.layout().currentWidget() == self._page_control :
self._page_control.copy()
elif self.layout().currentWidget() == self._control :
text = self._control.textCursor().selection().toPlainText()
if text:
lines = map(transform_classic_prompt, text.splitlines())
text = '\n'.join(lines)
QtGui.QApplication.clipboard().setText(text)
else:
self.log.debug("frontend widget : unknown copy target")

#---------------------------------------------------------------------------
# 'ConsoleWidget' abstract interface
Expand Down
16 changes: 11 additions & 5 deletions IPython/frontend/qt/console/ipython_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,17 @@ def copy(self):
""" Copy the currently selected text to the clipboard, removing prompts
if possible.
"""
text = self._control.textCursor().selection().toPlainText()
if text:
lines = map(transform_ipy_prompt, text.splitlines())
text = '\n'.join(lines)
QtGui.QApplication.clipboard().setText(text)
if self.layout().currentWidget() == self._page_control :
self._page_control.copy()
elif self.layout().currentWidget() == self._control :
text = self._control.textCursor().selection().toPlainText()
if text:
lines = map(transform_ipy_prompt, text.splitlines())
text = '\n'.join(lines)
QtGui.QApplication.clipboard().setText(text)
else :
self.log.debug("ipython_widget : unknown copy taget")


#---------------------------------------------------------------------------
# 'FrontendWidget' public interface
Expand Down
3 changes: 1 addition & 2 deletions IPython/frontend/qt/console/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,7 @@ def cut_active_frontend(self):

def copy_active_frontend(self):
widget = self.active_frontend
if widget.can_copy():
widget.copy()
widget.copy()

def copy_raw_active_frontend(self):
self.active_frontend._copy_raw_action.trigger()
Expand Down

0 comments on commit b071c87

Please sign in to comment.