Resize the shortcut as an IPython widget
This is a really trivial problem, but still annoying. I am writing a tool to allow the user to set a set of numerical parameters for analysis in an IPython notebook. I installed it as a bunch FloatTextWidget
in ContainerWidget
. They have rather long labels like "Posture Point Count" or "Background Disk Radius". They don't line up nicely. This has to do with length: as described on this page , "The label of a widget has a fixed minimum width. The label text is always right-aligned and the widget is left-aligned ... If the label is longer than the minimum, the widget is pushed to the right."
My labels are exceeding the "fixed minimum width". I want to know how to change this. I've poked into the source code of the Widget and I can't find it anywhere.
EDIT: In response to @Jakob, here is some code and here is a screenshot
In this example, "Threshold:" is small enough to fit the width of the label, but everyone else is too long.
source to share
Well, I found a narrow answer to my question, the minimum width of the field is defined in site-packages/IPython/html/static/style/ipython.min.css
(located where your python library live - on my Max, that is /Library/Python/2.7/
), which widget-hlabel
is determined by
.widget-hlabel{min-width:10ex;padding-right:8px;padding-top:3px;text-align:right;vertical-align:text-top}
min-width:10ex
is the relevant part.
While this can be overridden for the entire document, I don't see an easy way to change it one widget at a time. This needs to be done on the JavaScript side, since the class FloatTextWidget
does not provide separate python access to the widget label component. This would require developing a custom widget subclass from FloatTextWidget
, which seems too complex for such a simple problem and fragile to load. At least that's the only way I can see it - fixes are welcome.
Instead, I decided to completely eliminate the automatic labeling of widgets with their descriptions and instead build each label as HTMLWidget
, which gives me full control over its appearance. This is what it looks like:
source to share