[IPython-dev] [IPython-User] Runtime selection of the default pretty display
Matthias Bussonnier
bussonniermatthias at gmail.com
Sun Jun 1 16:11:02 EDT 2014
Hi Akim.
>>> So what I'd like is a means to control which _repr_ IPython's
>>> display will chose. Is there such a feature?
>>
>> No, there is not.
>
> Do you think that would be useful?
No it is by design. If you need the functionality, you are probably misunderstanding the way it works.
As a library author you shouldn't decide for the user, if the user really want to change, he/she import
display_whatever from IPython.display and call it on your object. Any tentative to do something else,
will break things in weird ways.
>> You cannot, the last syntactic block of code has a value, it will be displayed.
>
> Well, I'm not really an expect Python programmer, so maybe you
> thought I would have thought of another means and rejected it,
> but no, I did not :) So yes, I can have what I was asking for,
> provided I avoid the outer lambda (lambdas are so sadly poor in
> Python :-/):
>
>> # Requires IPython 2.0.
>> def _automaton_interact(self):
>> """Display automaton `self` with a local menu to the select
>> the display mode. Pay attention to not displaying large
>> automata by default.
>> """
>> from IPython.html.widgets import interact
>> if 20 < self.state_number():
>> modes = ['info', 'dot']
>> else:
>> modes = ['dot', 'info']
>> modes += ['info,detailed', 'tooltip', 'type', 'dot2tex']
>> interact(lambda mode: _automaton_display(self, mode), mode = modes)
>>
>> automaton.display = _automaton_interact
>
> This does exactly what I want.
>
>> Il might get better if you fix your above problem of foo.display(), maybe using `_repr_mime_` in ipython
>> but i do not remember if you can do it with widgets.
>
> I have not found a means to use _repr_mime_ here
>
>> Keep in mind that widget are still at the beginning, so missing pieces might still arise.
>
> Sure. I'd like to suggest something like _repr_widget_ or
> whatever that would allow to provide an interactive widget
> as representation. That would be really awesome.
Widget are not my area of expertise, I haven't played a lot with them, so I'll let other respond.
--
M
> Cheers,
>
> Akim
>
> _______________________________________________
> IPython-User mailing list
> IPython-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
More information about the IPython-dev
mailing list