ejeschke / ginga

The Ginga astronomical FITS file viewer
BSD 3-Clause "New" or "Revised" License
122 stars 77 forks source link

question: unregister/clear all callbacks for a canvas? #170

Closed stscieisenhamer closed 9 years ago

stscieisenhamer commented 9 years ago

Not sure if this make sense, but if one is working with multiple canvases, is there way to unset the surface or unregister the cursor? I see that these basically just set a bunch of callbacks, so ultimately, is there a way of clearing all callbacks?

pllim commented 9 years ago

In misc/Callback.py, there is a clear_callback() method:

class Callbacks(object):
    def clear_callback(self, name):
        self.cb[name] = []

Does that work for you?

stscieisenhamer commented 9 years ago

It will do the job, but I would need to explicitly destroy each callback. I was wondering if 1) the concepts embodied the set_surface and _registercursor routines have already a reverse implementation and/or 2) whether there is a need regardless?

At the moment, setting/unsetting drawing mode gets the macro effect correct: you can draw/not draw on a canvas. However, that canvas still has a slew of callbacks going. If one is creating multiple canvases, the callback load could potentially get large.

Or maybe not. This may not be something to worry due to other implementation details. Just haven't seen one way or 'nother.

If there is not a reverse-operation version and there is a need for such, I'm more than happy to provide it.

pllim commented 9 years ago

I use Ginga core distribution, which comes preloaded with a bunch of plugins, with my own plugins on top of those. I have not seen any performance impact by not destroying callbacks.

ejeschke commented 9 years ago

@stscieisenhamer, there are two ways in which callbacks are suppressed: 1) if a subcanvas is removed from a canvas, using (e.g.) canvas.removeObject(subcanvas), then UI callbacks registered on that subcanvas will not be delivered. Note that all objects on the subcanvas remain there, and if you add the subcanvas back to the main canvas everything will reappear. 2) If you have a subcanvas on a canvas and you call subcanvas.ui_setActive(False), then no UI callbacks will be delivered for callbacks registered on that subcanvas, even though the contents of that subcanvas will be rendered on the parent's canvas.

If you look at some of the plugins for the reference viewer you can see that they use these two approaches; they add the subcanvas in start() and remove it in stop(), and they enable and disable callbacks in resume() and pause(). The same principles can be applied to any standalone program using ginga canvases and viewers.

ejeschke commented 9 years ago

So basically you should not need to worry about removing callbacks, although as @pllim points out, you can remove them.

stscieisenhamer commented 9 years ago

That was the info I was looking for. Thanks!