Show More
@@ -10,6 +10,7 b' import re' | |||
|
10 | 10 | import sys |
|
11 | 11 | from textwrap import dedent |
|
12 | 12 | from unicodedata import category |
|
13 | import webbrowser | |
|
13 | 14 | |
|
14 | 15 | # System library imports |
|
15 | 16 | from IPython.external.qt import QtCore, QtGui |
@@ -264,6 +265,7 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||
|
264 | 265 | elif self.gui_completion == 'plain': |
|
265 | 266 | self._completion_widget = CompletionPlain(self) |
|
266 | 267 | |
|
268 | self._anchor = None | |
|
267 | 269 | self._continuation_prompt = '> ' |
|
268 | 270 | self._continuation_prompt_html = None |
|
269 | 271 | self._executing = False |
@@ -511,6 +513,12 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||
|
511 | 513 | """ |
|
512 | 514 | self.layout().currentWidget().copy() |
|
513 | 515 | |
|
516 | def copy_anchor(self): | |
|
517 | """ Copy anchor text to the clipboard | |
|
518 | """ | |
|
519 | if self._anchor: | |
|
520 | QtGui.QApplication.clipboard().setText(self._anchor) | |
|
521 | ||
|
514 | 522 | def cut(self): |
|
515 | 523 | """ Copy the currently selected text to the clipboard and delete it |
|
516 | 524 | if it's inside the input buffer. |
@@ -678,6 +686,12 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||
|
678 | 686 | |
|
679 | 687 | font = property(_get_font, _set_font) |
|
680 | 688 | |
|
689 | def open_anchor(self): | |
|
690 | """ Open selected anchor in the default webbrowser | |
|
691 | """ | |
|
692 | if self._anchor: | |
|
693 | webbrowser.open( self._anchor ) | |
|
694 | ||
|
681 | 695 | def paste(self, mode=QtGui.QClipboard.Clipboard): |
|
682 | 696 | """ Paste the contents of the clipboard into the input region. |
|
683 | 697 | |
@@ -971,6 +985,13 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||
|
971 | 985 | self.paste_action.setEnabled(self.can_paste()) |
|
972 | 986 | self.paste_action.setShortcut(QtGui.QKeySequence.Paste) |
|
973 | 987 | |
|
988 | if self._anchor: | |
|
989 | menu.addSeparator() | |
|
990 | self.copy_link_action = menu.addAction('Copy Link Address', | |
|
991 | self.copy_anchor) | |
|
992 | self.open_link_action = menu.addAction('Open Link', | |
|
993 | self.open_anchor) | |
|
994 | ||
|
974 | 995 | menu.addSeparator() |
|
975 | 996 | menu.addAction(self.select_all_action) |
|
976 | 997 | |
@@ -1009,6 +1030,8 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||
|
1009 | 1030 | elif self.kind == 'rich': |
|
1010 | 1031 | control = QtGui.QTextEdit() |
|
1011 | 1032 | control.setAcceptRichText(False) |
|
1033 | control.setMouseTracking(True) | |
|
1034 | control.mouseMoveEvent = self.mouseMoveEvent | |
|
1012 | 1035 | |
|
1013 | 1036 | # Install event filters. The filter on the viewport is needed for |
|
1014 | 1037 | # mouse events and drag events. |
@@ -1713,6 +1736,18 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||
|
1713 | 1736 | else: |
|
1714 | 1737 | self.input_buffer = '' |
|
1715 | 1738 | |
|
1739 | def mouseMoveEvent(self, event): | |
|
1740 | """ Show tooltip if the mouse is hovering over an anchor | |
|
1741 | """ | |
|
1742 | pos = event.pos() | |
|
1743 | anchor = self._control.anchorAt(pos) | |
|
1744 | if len(anchor) == 0: | |
|
1745 | self._anchor = None | |
|
1746 | QtGui.QToolTip.hideText() | |
|
1747 | elif anchor != self._anchor: | |
|
1748 | self._anchor = anchor | |
|
1749 | QtGui.QToolTip.showText(pos, self._anchor) | |
|
1750 | ||
|
1716 | 1751 | def _page(self, text, html=False): |
|
1717 | 1752 | """ Displays text using the pager if it exceeds the height of the |
|
1718 | 1753 | viewport. |
General Comments 0
You need to be logged in to leave comments.
Login now