Permalink
Browse files

Merge PR #1091 (qtconsole pager copy)

closes #1088
closes #1091
  • Loading branch information...
minrk committed Dec 7, 2011
2 parents bfdb4a1 + a485f35 commit 7a144e2eaab554e833ba2b77bf3a6d945b45d167
@@ -441,7 +441,7 @@ def clear(self, keep_input=True):
def copy(self):
""" Copy the currently selected text to the clipboard.
"""
- self._control.copy()
+ self.layout().currentWidget().copy()
def cut(self):
""" Copy the currently selected text to the clipboard and delete it
@@ -107,6 +107,7 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):
exit_requested = QtCore.Signal(object)
# Protected class variables.
+ _transform_prompt = staticmethod(transform_classic_prompt)
_CallTipRequest = namedtuple('_CallTipRequest', ['id', 'pos'])
_CompletionRequest = namedtuple('_CompletionRequest', ['id', 'pos'])
_ExecutionRequest = namedtuple('_ExecutionRequest', ['id', 'kind'])
@@ -174,11 +175,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._page_control.hasFocus():
+ self._page_control.copy()
+ elif self._control.hasFocus():
+ text = self._control.textCursor().selection().toPlainText()
+ if text:
+ lines = map(self._transform_prompt, text.splitlines())
+ text = '\n'.join(lines)
+ QtGui.QApplication.clipboard().setText(text)
+ else:
+ self.log.debug("frontend widget : unknown copy target")
#---------------------------------------------------------------------------
# 'ConsoleWidget' abstract interface
@@ -365,7 +371,9 @@ def _handle_exec_callback(self, msg):
"""
- user_exp = msg['content']['user_expressions']
+ user_exp = msg['content'].get('user_expressions')
+ if not user_exp:
+ return
for expression in user_exp:
if expression in self._callback_dict:
self._callback_dict.pop(expression)(user_exp[expression])
@@ -98,6 +98,7 @@ class IPythonWidget(FrontendWidget):
# FrontendWidget protected class variables.
_input_splitter_class = IPythonInputSplitter
+ _transform_prompt = staticmethod(transform_ipy_prompt)
# IPythonWidget protected class variables.
_PromptBlock = namedtuple('_PromptBlock', ['block', 'length', 'number'])
@@ -263,16 +264,6 @@ def _started_channels(self):
# 'ConsoleWidget' public interface
#---------------------------------------------------------------------------
- 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)
-
#---------------------------------------------------------------------------
# 'FrontendWidget' public interface
#---------------------------------------------------------------------------
@@ -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()

0 comments on commit 7a144e2

Please sign in to comment.