diff --git a/IPython/frontend/qt/console/call_tip_widget.py b/IPython/frontend/qt/console/call_tip_widget.py index c918737..838f03e 100644 --- a/IPython/frontend/qt/console/call_tip_widget.py +++ b/IPython/frontend/qt/console/call_tip_widget.py @@ -137,7 +137,7 @@ class CallTipWidget(QtGui.QLabel): 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. @@ -248,6 +248,17 @@ class CallTipWidget(QtGui.QLabel): 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):