Skip to content
This repository

qtconsole : allow copy with shortcut in pager #1091

Closed
wants to merge 4 commits into from

2 participants

Matthias Bussonnier Min RK
Matthias Bussonnier
Collaborator

closes #1088

added some commits December 03, 2011
Matthias Bussonnier
Collaborator

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

Matthias Bussonnier
Collaborator

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 ?

Min RK
Owner

@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.

Min RK minrk commented on the diff December 04, 2011
IPython/frontend/qt/console/ipython_widget.py
@@ -267,11 +267,17 @@ def copy(self):
267 267
         """ Copy the currently selected text to the clipboard, removing prompts
268 268
             if possible.
269 269
         """
270  
-        text = self._control.textCursor().selection().toPlainText()
271  
-        if text:
272  
-            lines = map(transform_ipy_prompt, text.splitlines())
273  
-            text = '\n'.join(lines)
274  
-            QtGui.QApplication.clipboard().setText(text)
  270
+        if self.layout().currentWidget() == self._page_control :
  271
+            self._page_control.copy()
  272
+        elif self.layout().currentWidget() == self._control :
  273
+            text = self._control.textCursor().selection().toPlainText()
  274
+            if text:
  275
+                lines = map(transform_ipy_prompt, text.splitlines())
  276
+                text = '\n'.join(lines)
  277
+                QtGui.QApplication.clipboard().setText(text)
3
Min RK Owner
minrk added a note December 04, 2011

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.

Matthias Bussonnier Collaborator
Carreau added a note December 05, 2011

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.

Min RK Owner
minrk added a note December 05, 2011

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
Min RK
Owner

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.

Matthias Bussonnier
Collaborator

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

Matthias Bussonnier copy pager also hsplit, vsplit
	check which of the two widget have focus to know from which to copy
594f294
Matthias Bussonnier
Collaborator

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

Min RK minrk referenced this pull request from a commit December 07, 2011
Min RK Merge PR #1091 (qtconsole pager copy)
closes #1088
closes #1091
7a144e2
Min RK minrk closed this pull request from a commit December 07, 2011
Min RK Merge PR #1091 (qtconsole pager copy)
closes #1088
closes #1091
7a144e2
Min RK minrk closed this in 7a144e2 December 07, 2011
Brian E. Granger ellisonbg referenced this pull request from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 4 unique commits by 1 author.

Dec 03, 2011
Matthias Bussonnier qtconsole : allow copy with shortcut in pager
	closes #1088
32dd9b5
Matthias Bussonnier qtconsole --pure, avoid 'user_expression'
	'user_expression' does not exist with --pure, be more carefull..
d7c7b66
Matthias Bussonnier shorten 32dd9b5 logic for one file 40533f7
Dec 07, 2011
Matthias Bussonnier copy pager also hsplit, vsplit
	check which of the two widget have focus to know from which to copy
594f294
This page is out of date. Refresh to see the latest.
2  IPython/frontend/qt/console/console_widget.py
@@ -441,7 +441,7 @@ def clear(self, keep_input=True):
441 441
     def copy(self):
442 442
         """ Copy the currently selected text to the clipboard.
443 443
         """
444  
-        self._control.copy()
  444
+        self.layout().currentWidget().copy()
445 445
 
446 446
     def cut(self):
447 447
         """ Copy the currently selected text to the clipboard and delete it
19  IPython/frontend/qt/console/frontend_widget.py
@@ -174,11 +174,16 @@ def __init__(self, *args, **kw):
174 174
     def copy(self):
175 175
         """ Copy the currently selected text to the clipboard, removing prompts.
176 176
         """
177  
-        text = self._control.textCursor().selection().toPlainText()
178  
-        if text:
179  
-            lines = map(transform_classic_prompt, text.splitlines())
180  
-            text = '\n'.join(lines)
181  
-            QtGui.QApplication.clipboard().setText(text)
  177
+        if self.layout().currentWidget() == self._page_control :
  178
+            self._page_control.copy()
  179
+        elif self.layout().currentWidget() == self._control :
  180
+            text = self._control.textCursor().selection().toPlainText()
  181
+            if text:
  182
+                lines = map(transform_classic_prompt, text.splitlines())
  183
+                text = '\n'.join(lines)
  184
+                QtGui.QApplication.clipboard().setText(text)
  185
+        else:
  186
+            self.log.debug("frontend widget : unknown copy target")
182 187
 
183 188
     #---------------------------------------------------------------------------
184 189
     # 'ConsoleWidget' abstract interface
@@ -365,7 +370,9 @@ def _handle_exec_callback(self, msg):
365 370
 
366 371
         """
367 372
 
368  
-        user_exp = msg['content']['user_expressions']
  373
+        user_exp = msg['content'].get('user_expressions')
  374
+        if not user_exp:
  375
+            return
369 376
         for expression in user_exp:
370 377
             if expression in self._callback_dict:
371 378
                 self._callback_dict.pop(expression)(user_exp[expression])
16  IPython/frontend/qt/console/ipython_widget.py
@@ -267,11 +267,17 @@ def copy(self):
267 267
         """ Copy the currently selected text to the clipboard, removing prompts
268 268
             if possible.
269 269
         """
270  
-        text = self._control.textCursor().selection().toPlainText()
271  
-        if text:
272  
-            lines = map(transform_ipy_prompt, text.splitlines())
273  
-            text = '\n'.join(lines)
274  
-            QtGui.QApplication.clipboard().setText(text)
  270
+        if self._page_control.hasFocus() :
  271
+            self._page_control.copy()
  272
+        elif self._control.hasFocus() :
  273
+            text = self._control.textCursor().selection().toPlainText()
  274
+            if text:
  275
+                lines = map(transform_ipy_prompt, text.splitlines())
  276
+                text = '\n'.join(lines)
  277
+                QtGui.QApplication.clipboard().setText(text)
  278
+        else :
  279
+            self.log.debug("ipython_widget : unknown copy taget")
  280
+
275 281
 
276 282
     #---------------------------------------------------------------------------
277 283
     # 'FrontendWidget' public interface
3  IPython/frontend/qt/console/mainwindow.py
@@ -795,8 +795,7 @@ def cut_active_frontend(self):
795 795
 
796 796
     def copy_active_frontend(self):
797 797
         widget = self.active_frontend
798  
-        if widget.can_copy():
799  
-            widget.copy()
  798
+        widget.copy()
800 799
 
801 800
     def copy_raw_active_frontend(self):
802 801
         self.active_frontend._copy_raw_action.trigger()
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.