[IPython-dev] Feasilibity of widgets/layout for mimicking this

Adam Hughes hughesadam87 at gmail.com
Wed Aug 27 13:33:24 EDT 2014


Thanks for the help Nick and Jason, sorry for the late reply.  WIll try out
your suggestions.

PS, the trait notification decorator is standard to Traits but probably not
Traitlets.


On Sat, Aug 23, 2014 at 3:50 PM, Nicholas Bollweg <nick.bollweg at gmail.com>
wrote:

> One way to do this would be to instead of requiring the notebook user to
> understand everything, expose important bits as traitlets, and then
> change/traitlet.link all of them together. In your example, if:
>
>    - Plotting knows to redraw itself when its data changes
>    - Filtering , updates its windowtype, to be, instead of "hamming",
>    scipy.filter.hamming
>
> then suddenly your code is now:
>
>> def change_windowtype(name, old_value, new_value):
>>     plot_ui.data = filtering_ui.windowtype(data)
>> filtering_ui.on_trait_change("windowtype", change_windowtype)
>>
> (I don't think your usage of on_trait_changed as a decorator is legit, but
> that would be awesome!)
>
> That moves a lot of the event stuff into the internal structure of each of
> your GUI components. This pattern would also be much easier to wrap up
> later into a "higher order" GUI. Then, if you want to "hoist" a property,
> you would just use traitlet.link:
>
>> class GUI(widgets.ContainerWidget)
>>     windowtype = traitlets.Any(sync=True)
>>     plot_data = traitlets.Any(sync=True)
>>     data = traitlets.Any(sync=True)
>>
>>     def __init__(self, **kwargs)
>>         super(GUI, self).__init__(**kwargs)
>>
>>         self.filtering_ui = Filtering()
>>         self.plot_ui = Plotting()
>>
>>         self.children = [self.filtering_ui, self.plot_ui]
>>
>>         traitlets.link(self, "plot_data"), (self.plot_ui, "data"),
>>         traitlets.link(self, "windowtype"), (self.filtering_ui,
>> "windowtype"),
>>
>>     def _windowtype_changed(self, name, old_value, new_value):
>>         self.plot_data = self.windowtype(self.data)
>>
> And now the notebook user would still be able to inspect and change the
> important parts of even deeply nested settings with simple assignment.
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140827/af15baa6/attachment.html>


More information about the IPython-dev mailing list