Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

4 participants

y-p Bradley M. Froehle klonuo Matthias Bussonnier
y-p
y-p commented

previously, a function with a long argument list would produce
a very wide tooltip, hurting readability.

Since the width of the docstring body is chosen by the developer
whereas the formatting of the argument list is currently not, it's
reasonable to wrap the argument list width to the maximum of
a) 80 characters, or b) maximum length of a line in the docstring body.

This improves readability, without unduly affecting the appearence
of the docstring body itself.

closes #2661

I'm happy to add any additional tests or make any changes required to get this merged.

y-p y-p qtconsole: wrap argument list in tooltip to match width of text body
previously, a function with a long argument list would produce
a very wide tooltip, hurting readability.

Since the width of the docstring body is chosen by the developer
whereas the formatting of the argument list is currently not, it's
reasonable to wrap the argument list width to the maximum of
a) 80 characters, or b) maximum length of a line in the docstring body.

This improved readability, without unduly affecting the appearence
of the docstring body itself.

closes #2661
2b49db1
Bradley M. Froehle
Collaborator

Great! Thanks for tackling this. Why not just wrap all lines at something like 80 characters? As you point out this may impact the formatting... but this is just a tooltip so nobody expects perfection.

y-p
y-p commented

I've had no issues with bodies being too wide, they are generally PEP8-ish.
Even If there is some overflow, it's usually fine on most screens.
And if you don't wrap at 80, whatever number you choose is wrong somehow.

"if the dev did a reasonably good job, it should look reasonably good"

klonuo

closes the same reported issue: #2540

y-p

bump. Is there anything I can do to help get this in?

Matthias Bussonnier
Owner
Matthias Bussonnier
Owner

I'm going to merge this as it is simple enough.

Matthias Bussonnier Carreau merged commit 3f09b76 into from
Min RK minrk referenced this pull request from a commit
Min RK minrk Backport PR #2662: qtconsole: wrap argument list in tooltip to match …
…width of text body

previously, a function with a long argument list would produce
a very wide tooltip, hurting readability.

Since the width of the docstring body is chosen by the developer
whereas the formatting of the argument list is currently not, it's
reasonable to wrap the argument list width to the maximum of
a) 80 characters, or b) maximum length of a line in the docstring body.

This improves readability, without unduly affecting the appearence
of the docstring body itself.

closes #2661

I'm happy to add any additional tests or make any changes required to get this merged.
43e0fc2
y-p y-p deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 6, 2012
  1. y-p

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

    y-p authored
    previously, a function with a long argument list would produce
    a very wide tooltip, hurting readability.
    
    Since the width of the docstring body is chosen by the developer
    whereas the formatting of the argument list is currently not, it's
    reasonable to wrap the argument list width to the maximum of
    a) 80 characters, or b) maximum length of a line in the docstring body.
    
    This improved readability, without unduly affecting the appearence
    of the docstring body itself.
    
    closes #2661
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 1 deletion.
  1. +12 −1 IPython/frontend/qt/console/call_tip_widget.py
13 IPython/frontend/qt/console/call_tip_widget.py
View
@@ -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.
@@ -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):
Something went wrong with that request. Please try again.