Skip to content

Loading…

qtconsole : allow copy with shortcut in pager #1091

Closed
wants to merge 4 commits into from

2 participants

@Carreau

closes #1088

Carreau added some commits
@Carreau

I also added a little fix that avoid some error message when trying qtconsole with --pure as there won't be user_expressionin message comming from the kernel.

Actually I suspect that some of the gui menu of qtconsole might be broken with --pure

@Carreau

note that we might want to add a warning in the docstring of
console/console_widget.py: def can_copy(self):
Or change the implementation to check wether or not it returns true if selected text is in the pager...

Which way you think is the best ?

@minrk
IPython member

@Carreau - you are right, there are probably quite a few things broken in pure mode. I wish we would remove it, because nobody ever tests it, and there are huge amounts of duplicate code that typically are not updated in tandem with every change.

@minrk minrk commented on the diff
IPython/frontend/qt/console/ipython_widget.py
@@ -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)
@minrk IPython member
minrk added a note

Let's make 'transform_prompt` a widget trait (should be transform_classic_prompt in FrontendWidget, and transform_ipy_prompt in IPythonWidget), then we shouldn't have to override copy() in IPythonWidget at all.

@Carreau
Carreau added a note

I'm not quite comfortable with trait , I can give a shot, bu you'll probably be done before I read enough to do it the right way.

@minrk IPython member
minrk added a note

Sorry, it can just be a class attribute. The traitness is unimportant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@minrk
IPython member

When doing ipython qtconsole --pylab --paging vsplit, and do plot?, I cannot actually copy anything out of the pager area. So it would appear that this does not do what it claims, unless I am mistaken.

@Carreau

hum... I didn't thought of vsplit. I'll take a look.

@Carreau Carreau copy pager also hsplit, vsplit
	check which of the two widget have focus to know from which to copy
594f294
@Carreau

@minrk,
this seem to work with hsplit/vsplit and without splitter

@minrk minrk added a commit that referenced this pull request
@minrk minrk Merge PR #1091 (qtconsole pager copy)
closes #1088
closes #1091
7a144e2
@minrk minrk added a commit that closed this pull request
@minrk minrk Merge PR #1091 (qtconsole pager copy)
closes #1088
closes #1091
7a144e2
@minrk minrk closed this in 7a144e2
@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request
@minrk minrk Merge PR #1091 (qtconsole pager copy)
closes #1088
closes #1091
5ce2c2f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 3, 2011
  1. @Carreau
  2. @Carreau

    qtconsole --pure, avoid 'user_expression'

    Carreau committed
    	'user_expression' does not exist with --pure, be more carefull..
  3. @Carreau

    shorten 32dd9b5 logic for one file

    Carreau committed
Commits on Dec 7, 2011
  1. @Carreau

    copy pager also hsplit, vsplit

    Carreau committed
    	check which of the two widget have focus to know from which to copy
View
2 IPython/frontend/qt/console/console_widget.py
@@ -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
View
19 IPython/frontend/qt/console/frontend_widget.py
@@ -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
@@ -365,7 +370,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])
View
16 IPython/frontend/qt/console/ipython_widget.py
@@ -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._page_control.hasFocus() :
+ self._page_control.copy()
+ elif self._control.hasFocus() :
+ text = self._control.textCursor().selection().toPlainText()
+ if text:
+ lines = map(transform_ipy_prompt, text.splitlines())
+ text = '\n'.join(lines)
+ QtGui.QApplication.clipboard().setText(text)
@minrk IPython member
minrk added a note

Let's make 'transform_prompt` a widget trait (should be transform_classic_prompt in FrontendWidget, and transform_ipy_prompt in IPythonWidget), then we shouldn't have to override copy() in IPythonWidget at all.

@Carreau
Carreau added a note

I'm not quite comfortable with trait , I can give a shot, bu you'll probably be done before I read enough to do it the right way.

@minrk IPython member
minrk added a note

Sorry, it can just be a class attribute. The traitness is unimportant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ else :
+ self.log.debug("ipython_widget : unknown copy taget")
+
#---------------------------------------------------------------------------
# 'FrontendWidget' public interface
View
3 IPython/frontend/qt/console/mainwindow.py
@@ -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()
Something went wrong with that request. Please try again.