-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clickable links #2467
Clickable links #2467
Changes from 5 commits
9891d07
18bdda9
450c790
3160cc0
fe14a7b
2bfb3b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import sys | ||
from textwrap import dedent | ||
from unicodedata import category | ||
import webbrowser | ||
|
||
# System library imports | ||
from IPython.external.qt import QtCore, QtGui | ||
|
@@ -264,6 +265,7 @@ def __init__(self, parent=None, **kw): | |
elif self.gui_completion == 'plain': | ||
self._completion_widget = CompletionPlain(self) | ||
|
||
self._anchor = None | ||
self._continuation_prompt = '> ' | ||
self._continuation_prompt_html = None | ||
self._executing = False | ||
|
@@ -432,6 +434,16 @@ def eventFilter(self, obj, event): | |
obj == self._page_control: | ||
self._page_control.repaint() | ||
return True | ||
|
||
elif etype == QtCore.QEvent.MouseMove: | ||
anchor = self._control.anchorAt(event.pos()) | ||
if len(anchor) == 0: | ||
self._anchor = None | ||
QtGui.QToolTip.hideText() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this in any way expensive? I.e., should this become: if self._anchor:
self._anchor = None
QtGui.QToolTip.hideText() No idea, it's certainly simpler as-is, but the other way might be more performant? |
||
elif anchor != self._anchor: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test temporary variable anchor to see if the pointer moved over a different anchor. |
||
self._anchor = anchor | ||
QtGui.QToolTip.showText(event.globalPos(), self._anchor) | ||
|
||
return super(ConsoleWidget, self).eventFilter(obj, event) | ||
|
||
#--------------------------------------------------------------------------- | ||
|
@@ -511,6 +523,12 @@ def copy(self): | |
""" | ||
self.layout().currentWidget().copy() | ||
|
||
def copy_anchor(self): | ||
""" Copy anchor text to the clipboard | ||
""" | ||
if self._anchor: | ||
QtGui.QApplication.clipboard().setText(self._anchor) | ||
|
||
def cut(self): | ||
""" Copy the currently selected text to the clipboard and delete it | ||
if it's inside the input buffer. | ||
|
@@ -678,6 +696,12 @@ def _set_font(self, font): | |
|
||
font = property(_get_font, _set_font) | ||
|
||
def open_anchor(self): | ||
""" Open selected anchor in the default webbrowser | ||
""" | ||
if self._anchor: | ||
webbrowser.open( self._anchor ) | ||
|
||
def paste(self, mode=QtGui.QClipboard.Clipboard): | ||
""" Paste the contents of the clipboard into the input region. | ||
|
||
|
@@ -971,6 +995,13 @@ def _context_menu_make(self, pos): | |
self.paste_action.setEnabled(self.can_paste()) | ||
self.paste_action.setShortcut(QtGui.QKeySequence.Paste) | ||
|
||
if self._anchor: | ||
menu.addSeparator() | ||
self.copy_link_action = menu.addAction('Copy Link Address', | ||
self.copy_anchor) | ||
self.open_link_action = menu.addAction('Open Link', | ||
self.open_anchor) | ||
|
||
menu.addSeparator() | ||
menu.addAction(self.select_all_action) | ||
|
||
|
@@ -1009,6 +1040,7 @@ def _create_control(self): | |
elif self.kind == 'rich': | ||
control = QtGui.QTextEdit() | ||
control.setAcceptRichText(False) | ||
control.setMouseTracking(True) | ||
|
||
# Install event filters. The filter on the viewport is needed for | ||
# mouse events and drag events. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as
if not anchor
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bet it'd work, I'm just not used to the "if not anchor:" idiom so tend to be uncertain if the empty string is false.