ejeschke / ginga

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

Goal: Inter-plugin operability #214

Closed stscieisenhamer closed 9 years ago

stscieisenhamer commented 9 years ago

Today I am experimenting with having two plugins interact. In this case it would be the MultiImage one I'm working on and the Pick plugin.

In the current short foray, I have learned about the PluginManger. However, information such as is_active does not seem to include the local plugins and there isn't clear indication as to why.

I will be continuing on, but thoughts/pointers will be appreciated.

jde

pllim commented 9 years ago

I wonder if you can use self.gui_up as an indication. Every plugin has one.

pllim commented 9 years ago

From looking at Control.py, this could be the solution (theoretically):

chname = self.fv.get_channelName(self.fitsimage)
chinfo = self.fv.get_channelInfo(chname)
opmon = chinfo.opmon
try:
    plugin_obj = opmon.getPlugin(desired_local_plugin_name)
except Exception as e:
    self.logger.error('Failed to update plugin: {0}'.format(str(e)))
else:
    plugin_obj.do_something(...)
stscieisenhamer commented 9 years ago

oh, that looks promising...

stscieisenhamer commented 9 years ago

yep, that was the key. thanks!

ejeschke commented 9 years ago

Good sleuthing, @pllim! Yes, that is the way to grab the instance of a plugin for the the same channel. You can set your own variables in the plugin (e.g. gui_up) to indicate that it is "open" and I think there may be (should be?) a method or variable you can look at (via the opmon object shown above) to query whether it is active.

ejeschke commented 9 years ago

BTW, if you are developing plugins and you haven't yet discovered the Debug plugin, now might be the time to get to know it. You can start it from the Plugins menu. The most useful feature of it is being able to reload a plugin without restarting ginga.

Let's say you are developing a local plugin. You've found a bug and already edited the plugin code. You have a viewer full of data that will be a hassle to reload. Just close all instances of that plugin, open Debug, and in the box labelled "Local plugin:" type the class name of the plugin (capitalized as in the code). Press "Reload" and it will reload the module and reinstantiate the plugin object. You should now be able to open the plugin again from the "Operations" menu.

There are some limitations to this, including that if you are editing modules that are imported by the plugin this won't reload those. But I have found it invaluable to quickly iterating the debug cycle on a plugin.

stscieisenhamer commented 9 years ago

Yep, know all about the Debug :+1:

And ya, with the finding that the opmon's are channel-local (I'm still not getting my head around this), the inter-plugin operation is going fine. I dare say that by COB, one "killer-app" of a plugin combo should be done. Well, start-of-week anyways...

stscieisenhamer commented 9 years ago

@ejeschke So, the latest master of stginga has an implementation of the MultiImage plugin and a modified Pick plugin, MIPick, that now work in conjunction.

ejeschke commented 9 years ago

Cool! I'll take a look.

pllim commented 9 years ago

@stscieisenhamer , just nitpicking here... I would prefer MPick over MIPick. That "I" is easily missed and can sometimes look like the number one or lowercase "L".

stscieisenhamer commented 9 years ago

Well, the real hope is that once some more refactoring and final functionality, such as image deletion, are handled, everything will get merged into main reference viewer, and there will be no need for a separate Pick plugin. Just did this for demonstration purposes.