python-microscopy / pyme-plugin

Template for making plug-ins for the Python-Microscopy Environment (PYME)
http://www.python-microscopy.org/
BSD 2-Clause "Simplified" License
3 stars 2 forks source link

[ENHANCEMENT] add simple plugin stubs to this repo #12

Open csoeller opened 3 years ago

csoeller commented 3 years ago

The suggestion

We need some info/examples on plugin strategies IMHO.

It has become clear to me that we need a bit of info how to do

Rather than having long doc diatribes I would suggest adding stub templates according to current wisdom to this repo, including adding an example init file with a plugin example for PYMEAcquire and an associated install example. This should encapsulate current best practice and be updated with PYME refinements/changes over time.

I cannot think of a better place than this repo but feel free to suggest alternatives.

Current stub ideas

Here are a couple of stubs that could do with David's input for improvement where necessary, e.g. should some of these be derived from the plugin base class etc?

They could probably show off a little more functionality but this could be a starting point.

I will be happy to create a PR if there is general agreement that is could be a reasonable idea.

dh5view_template_plugin.py:

class MyPlugin:
    def __init__(self, dsviewer):
        self.dsviewer = dsviewer

        dsviewer.AddMenuItem('Experimental>MyMenuSection', "Do something", self.OnDoSomething)

    def OnDoSomething(self, event):
        pass

def Plug(dsviewer):
    """Plugs this module into the gui"""
    MyPlugin(dsviewer)

visgui_template_plugin.py:

# import numpy as np

class MyPlugin:
    def __init__(self, visFr):
        self.visFr = visFr

        visFr.AddMenuItem('Experimental>MyMenuSection', "Do something", self.OnDoSomething)

    def OnDoSomething(self, event):
        pass

def Plug(visFr):
    """Plugs this module into the gui"""
    MyPlugin(visFr)
csoeller commented 3 years ago

PS - If it is thought that it may be better to keep this repo just an empty shell I am happy to create a pyme-plugin-example repo that has some simple examples as described above. Still would not mind some feedback how to properly write these plugins either way.

zacsimile commented 3 years ago

I think it makes sense to include a stubs or examples folder. The alternative is to include these in their respective sections in the docs (e.g. https://python-microscopy.org/doc/ExtendingVisGUI.html and https://python-microscopy.org/doc/ExtendingDsviewer.html). It would be neat if we can also include a PYMEAcquire example.

csoeller commented 3 years ago

Great, would be good to get @barentine's view on this as I can either (a) make a PR against this repo or (b) fork this repo into something like pyme-plugin-example that gets the example minimal plugins. The upside would be that it keeps this repo clean but it may also create maintenance issues down the line.

barentine commented 3 years ago

Would certainly be great to get more of this into the formal docs.

I think it's probably helpful to keep stubs somewhere in this repo if we can, otherwise we add maintenance as you say and also it gets harder to see what the advantage is over just looking at another existing plugin.

I'm not a huge fan of an examples folder - it's not a big deal, but I think even our existing pyme-plugin/package_name/plugins/ filetree stuff that we copy into the right location during install_plugin feels a little superfluous and maybe messier than just adding filenames to a dict in install_plugin itself or so which people already have to edit.

As far as where to put the stubs, I could see putting them all in readme.md, or just in an example.py directly in the folder they're supposed to go in so they can just be edited/file renamed like an actual template.

Thanks both for thinking about this/working on it - sorry I'm a bit MIA at the moment - submitting my thesis in a couple weeks.