Skip to content
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

qtconsole: wrap argument list in tooltip to match width of text body #2662

Merged
merged 1 commit into from Dec 14, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion IPython/frontend/qt/console/call_tip_widget.py
Expand Up @@ -137,7 +137,7 @@ def show_call_info(self, call_line=None, doc=None, maxlines=20):

if call_line:
doc = '\n\n'.join([call_line, doc])
return self.show_tip(doc)
return self.show_tip(self._format_tooltip(doc))

def show_tip(self, tip):
""" Attempts to show the specified tip at the current cursor location.
Expand Down Expand Up @@ -248,6 +248,17 @@ def _leave_event_hide(self):
QtGui.qApp.topLevelAt(QtGui.QCursor.pos()) != self):
self._hide_timer.start(300, self)

def _format_tooltip(self,doc):
import textwrap

# make sure a long argument list does not make
# the first row overflow the width of the actual tip body
rows = doc.split("\n")
max_text_width = max(80, max([len(x) for x in rows[1:]]))
rows= textwrap.wrap(rows[0],max_text_width) + rows[1:]
doc = "\n".join(rows)
return doc

#------ Signal handlers ----------------------------------------------------

def _cursor_position_changed(self):
Expand Down