Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Open qtconsole hyperlinks. #2459
It would be really nice if the output of:
could be browsed. (One of the things I like about gnome-terminal is that it has an open links context menu for things it detects as a URL).
The QTextEdit widget has a function "anchorAt(pos)" that will return a URL for a given mouse pos. As a rough proof of concept I tried conditionally adding a "open %s" % (url,) to the right-click context menu as the patch fragment below shows.
Given some of your conventions for the rest of the menu. Should it be present and grayed out? Is there a better way of passing user data to a signal handler than a lambda function?
Should there be a limit to how much URL is put in the menu? (I wanted some way of showing what the URL actually was instead of its display text). And yes Long URLs do ugly things to the context menu.
-- a/IPython/frontend/qt/console/console_widget.py +++ b/IPython/frontend/qt/console/console_widget.py @@ -27,6 +27,7 @@ from completion_plain import CompletionPlain from kill_ring import QtKillRing +import webbrowser #----------------------------------------------------------------------------- # Functions @@ -971,6 +973,11 @@ def _context_menu_make(self, pos): self.paste_action.setEnabled(self.can_paste()) self.paste_action.setShortcut(QtGui.QKeySequence.Paste) + anchor = self._control.anchorAt(pos) + if len(anchor) > 0: + self.open_action = menu.addAction('Open %s' % (anchor,), + lambda : webbrowser.open(anchor)) + menu.addSeparator() menu.addAction(self.select_all_action)
Browsers spent a lot of effort tying to make sure a user could see the actual destination of a link so they wouldn't be surprised by clicking on it. I think that's a good idea and was trying to keep that behaviour in a non-intrusive way.
I can think of 3 ways of giving access to the URL destination before going there.
I think I'd be annoyed by using the copy-link method to verify a link.
I do think having a copy link in the menu is also a good idea.
So a menu bar might be
What would be more used between cut-paste and url handling?
I think the hover handler is then the only way to go, as otherwise the menu would be absurdly large.
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
Still learning about how to use github, so I'm not sure if I should do a pull request.
I have my basic implementation & test code on a branch https://github.com/detrout/ipython/tree/clickable-links
The commit message should be meaningful enough. Though I added test code as a second commit.