On Tue, 18 Sep 2012 05:59:59 -0700 (PDT)
felix74 <
hju...@googlemail.com> wrote:
> Terry,
>
> Thanks for your help with this it was very helpful and a lot simpler than I
> feared. I have managed to get a matplotlib graph embedded within a pane in
> leo as a widget. I now need some help with how to interact with the
> widget using scripts in leo. I am unsure about the following:
>
> *1/ How do I expose the widget within th leo python environment?*
If you were only going to have one and you weren't going to destroy it,
you could just do something simple like c._matplot = self in its
constrictor (assuming c was passed to the constructor).
If you're going to have more than one and they may be destroyed, it
might be simplest to let the free_layout / nested_splitter system manage
them.
ts = c.free_layout.get_top_splitter()
matplotters = ts.findChildren(myMatplotWidget)
should return a list of the widgets of your class in the layout, but
only if they're in the main window, widgets in extra windows opened
from the "Open window" context menu item would be missed, I can add a
find_children() method to complement the find_child() method the
splitters already have to account for this.
Detail: the above is just using Qt's QObject.findChildren(), the
nested_splitter find_child() and (not yet written) find_children()
versions search the extra windows as well.
> Here I have created a self.mat in your MatplotPaneProvider class to make
> the windget accessible but it doesn't feel like the correct way to do this.
It should probably provide a fresh myMatplotWidget every time it's
called, so don't construct one in the Provider's init, but in the
ns_provide method.
> from PyQt4 import QtGui
> class MatplotPaneProvider:
> def __init__(self, c):
> self.c = c
> * self.mat = myMatplotWidget()*
> if hasattr(c, 'free_layout'):
[snip]
> *2/I would also like to make the widget accessible from any script within
> leo. What's the leo way of doing this?*
See above.
> *3/ If I create more than 1 pane containing these widgest. How do I switch
> between them in scripts?*
Above again :-)
> *4/ Running this script more than once creates multiple items for Add
> Matplot when pressing the Action button. How do I stop this from happening?
> I have alrewady tried returning a unique integer in * ns_provider_id *but
> that did not work.*
The value returned by ns_provider_id should be unique for the provider
class, but constant. So it can just return "matplotlib provider ver 1"
or something.
Cheers -Terry