##// END OF EJS Templates
Allow the user to interact with link anchors in the qtconsole...
Diane Trout -
Show More
@@ -10,6 +10,7 b' import re'
10 import sys
10 import sys
11 from textwrap import dedent
11 from textwrap import dedent
12 from unicodedata import category
12 from unicodedata import category
13 import webbrowser
13
14
14 # System library imports
15 # System library imports
15 from IPython.external.qt import QtCore, QtGui
16 from IPython.external.qt import QtCore, QtGui
@@ -264,6 +265,7 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
264 elif self.gui_completion == 'plain':
265 elif self.gui_completion == 'plain':
265 self._completion_widget = CompletionPlain(self)
266 self._completion_widget = CompletionPlain(self)
266
267
268 self._anchor = None
267 self._continuation_prompt = '> '
269 self._continuation_prompt = '> '
268 self._continuation_prompt_html = None
270 self._continuation_prompt_html = None
269 self._executing = False
271 self._executing = False
@@ -511,6 +513,12 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
511 """
513 """
512 self.layout().currentWidget().copy()
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 def cut(self):
522 def cut(self):
515 """ Copy the currently selected text to the clipboard and delete it
523 """ Copy the currently selected text to the clipboard and delete it
516 if it's inside the input buffer.
524 if it's inside the input buffer.
@@ -678,6 +686,12 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
678
686
679 font = property(_get_font, _set_font)
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 def paste(self, mode=QtGui.QClipboard.Clipboard):
695 def paste(self, mode=QtGui.QClipboard.Clipboard):
682 """ Paste the contents of the clipboard into the input region.
696 """ Paste the contents of the clipboard into the input region.
683
697
@@ -971,6 +985,13 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
971 self.paste_action.setEnabled(self.can_paste())
985 self.paste_action.setEnabled(self.can_paste())
972 self.paste_action.setShortcut(QtGui.QKeySequence.Paste)
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 menu.addSeparator()
995 menu.addSeparator()
975 menu.addAction(self.select_all_action)
996 menu.addAction(self.select_all_action)
976
997
@@ -1009,6 +1030,8 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
1009 elif self.kind == 'rich':
1030 elif self.kind == 'rich':
1010 control = QtGui.QTextEdit()
1031 control = QtGui.QTextEdit()
1011 control.setAcceptRichText(False)
1032 control.setAcceptRichText(False)
1033 control.setMouseTracking(True)
1034 control.mouseMoveEvent = self.mouseMoveEvent
1012
1035
1013 # Install event filters. The filter on the viewport is needed for
1036 # Install event filters. The filter on the viewport is needed for
1014 # mouse events and drag events.
1037 # mouse events and drag events.
@@ -1713,6 +1736,18 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):'
1713 else:
1736 else:
1714 self.input_buffer = ''
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 def _page(self, text, html=False):
1751 def _page(self, text, html=False):
1717 """ Displays text using the pager if it exceeds the height of the
1752 """ Displays text using the pager if it exceeds the height of the
1718 viewport.
1753 viewport.
General Comments 0
You need to be logged in to leave comments. Login now