diff --git a/IPython/frontend/qt/console/console_widget.py b/IPython/frontend/qt/console/console_widget.py index 2f776e9..c96cf78 100644 --- a/IPython/frontend/qt/console/console_widget.py +++ b/IPython/frontend/qt/console/console_widget.py @@ -441,7 +441,7 @@ class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): 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 diff --git a/IPython/frontend/qt/console/frontend_widget.py b/IPython/frontend/qt/console/frontend_widget.py index 1fca694..ea503ad 100644 --- a/IPython/frontend/qt/console/frontend_widget.py +++ b/IPython/frontend/qt/console/frontend_widget.py @@ -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 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): 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 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): """ - 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]) diff --git a/IPython/frontend/qt/console/ipython_widget.py b/IPython/frontend/qt/console/ipython_widget.py index 5147139..a2cef79 100644 --- a/IPython/frontend/qt/console/ipython_widget.py +++ b/IPython/frontend/qt/console/ipython_widget.py @@ -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 @@ class IPythonWidget(FrontendWidget): # '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 #--------------------------------------------------------------------------- diff --git a/IPython/frontend/qt/console/mainwindow.py b/IPython/frontend/qt/console/mainwindow.py index 7cf24a7..6563dd7 100644 --- a/IPython/frontend/qt/console/mainwindow.py +++ b/IPython/frontend/qt/console/mainwindow.py @@ -795,8 +795,7 @@ class MainWindow(QtGui.QMainWindow): 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()