On Tuesday 20 June 2006 11:37, John Hunter wrote:
> >>>>> "Pierre" == Pierre GM <[EMAIL PROTECTED]> writes:
>
>     Pierre> Folks,
>     Pierre> I have a tailor-made subclass of Figure (say, MyFigure) that I'd
>     Pierre> like to use interactively. Ideally, I'd like to have
>     Pierre> pylab.figure() (or an equivalent) create a MyFigure instance,
>     Pierre>     instead of Figure. 
>     Pierre>
>     Pierre> I wrote a myfigure() function based on pylab.figure(), 
>     Pierre> substituting the 
>     Pierre> -----
>     Pierre> figManager = new_figure_manager(num, **figargs)
>     Pierre> -----
>     Pierre> by
>     Pierre> -----
>     Pierre> thisFig = MyFigure(*args, **kwargs)
>     Pierre> canvas = FigureCanvasGTKAgg(thisFig)
>     Pierre> figManager = FigureManagerGTKAgg(canvas, num)
>     Pierre> ----
>     Pierre>
>     Pierre> That seems to give me what I want, as long as I use the
>     Pierre> GTKAgg backend. What should I do to have the same result
>     Pierre> with another backend, without having to rewrite a
>     Pierre> new_figure_manager each time ? Anyway, is it even the way
>     Pierre> to go ?
>
> Note that pylab basically has the same problem, as each backend
> defines their own new_figure_manager function.  The problem is not the
> Figure, but the FigureCanvas, which is backend dependent.  Take a look
> at the "switch_backend" function in pylab
>
> def switch_backend(newbackend):
>     """
>     Calling this command will close all open windows.
>     """
>     close('all')
>     global new_figure_manager, draw_if_interactive, show
>     matplotlib.use(newbackend)
>     reload(backends)
>     from backends import new_figure_manager, draw_if_interactive, show
>
> You could emulate this approach ....

John, 
Thx for your answer. IMHO, the problem lies really with Figure, not Canvas. 
I'd need the Canvas, whatever backend defines it, recognizes that the figure 
is not a classical 'Figure' , but a subclass of it, with its own special 
properties/methods.
I gonna think aloud for a minute

One way would be to add a 'subclass' option to every new_figure_manager,
so that the 
`thisFig = Figure(**figargs)`
would be replaced by
`thisFig = subclass(**figargs)` 
(with subclass set to Figure by default). A bit overkill, eh ?

In fact, as long as my special properties/methods can be accessed Figure 
instance, I should be OK. What would be the better way to have the 
properties/methods of a child recognized by its parent (revered 
inheritance ?)



_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to