[IPython-dev] Dynamically changing the prompt from within a magic

David Quigley dpquigl@davequigley....
Fri Aug 3 13:20:55 CDT 2012


On 08/03/2012 13:19, Thomas Kluyver wrote:
> On 3 August 2012 17:44, David Quigley <dpquigl@davequigley.com> 
> wrote:
>> I get the config entry during the __init__ call for my plugin class 
>> and
>> pass it into the class I'm implementing the magic in. Once there I 
>> save
>> it off and then use it later in the magic. The problem I'm having is
>> that 1) unless I set the config.PromptManager.in_template field 
>> first it
>> doesn't exist (no default?) and 2) when I do set that value it 
>> doesn't
>> actually change the prompt.
>>
>> Is there something that I'm missing here?
>
> By the sounds of it, you're changing the config itself. When the
> application is started up, the config is applied to the relevant
> objects, and if there's no value in the config, it uses the default
> values for traits. After that, changing the config will have no
> effect.
>
> You need to change the attribute ip.prompt_manager.in_template
> directly (where ip is the shell object passed into your
> load_ipython_extension() function).
>
> Hope that helps,
> Thomas
> _______________________________________________
> IPython-dev mailing list
> IPython-dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev

That makes sense now. I guess the reason the recipe works is because 
create a new variable to use later and that variable is loaded in as the 
template so we can manipulate it after the fact instead of manipulating 
the config entry. Its good to know that whats passed into config on 
startup should also be in shell instance.


More information about the IPython-dev mailing list