Need help or advice ? Come to the Icy club ! - Every Wenesday morning from 9h30 to 12h30 - Francois Jacob Building - Main hall - Pasteur
Register

Ezplug plugin in Python

by tlecomte / Timothée Lecomte

This script shows how to create a graphical user interface in Python, using the EzPlug SDK.

Writing an Icy plugin with a graphical user interface can either be done in Java (using for example Eclipse), or with the Protocols graphical programming environment inside Icy. Sometimes, it may be desirable to have a solution that is simpler than setting up Eclipse, and more flexible than Protocols (which are very flexible !). This script is a solution to this situation. It can also be seen as a very nice way to prototype a plugin, before writing it in Java for distribution.

version 3 (last version):

download to use and modify in Icy. How do I use scripts ? A Problem ? ask the community.
Changelog for this version: Better class name, cleaner import, replace the getName() method by a dummy plugin descriptor.
from array import array

from java.awt import EventQueue

from icy.main import Icy
from icy.image import IcyBufferedImage
from icy.sequence import Sequence, SequenceUtil
from icy.type import DataType
from icy.plugin.abstract_ import Plugin
from icy.plugin import PluginDescriptor

from plugins.adufour import ezplug

class PythonThresholderExample(ezplug.EzPlug):
    def __init__(self):
        ezplug.EzPlug.__init__(self)
        
        # This plugin is not loaded through the PluginLoader, so it has
        # no descriptor attached, but EzPlug wants one, with a plugin name
        self.descriptor = PluginDescriptor()
        self.descriptor.setName(self.__class__.__name__)
        
        self.inputSelector = ezplug.EzVarSequence("Input")
        self.thresholdSelector = ezplug.EzVarDouble("Threshold value")

    def initialize(self):
        self.addEzComponent(self.inputSelector)
        self.addEzComponent(self.thresholdSelector)

    def execute(self):
        sequence = self.inputSelector.getValue()
        m = self.thresholdSelector.getValue()

        # exit immediately if there is no input sequence
        if sequence == None:
            return

        # convert the data to doubles so that the comparison to the threshold
        # works everytime (it would fail with bytes because of sign issues)
        if sequence.getDataType_() == DataType.DOUBLE:
            doubleSeq = sequence
        else:
            doubleSeq = SequenceUtil.convertToType(sequence, DataType.DOUBLE, False)

        # retrieve the data
        data = doubleSeq.getDataCopyXYAsDouble(0,0,0)

        for i, p in enumerate(data):
            if p

This script has no documentation. A Problem ? ask the community.


Previous versions:


version 2:

download to use and modify in Icy.
Changelog for this version: Wrong file was selected.
from array import array

from  java.awt import EventQueue

from icy.main import Icy
from icy.image import IcyBufferedImage
from icy.sequence import Sequence, SequenceUtil
from icy.type import DataType

import plugins.adufour.ezplug as ezplug

class MyPythonPlugin(ezplug.EzPlug):
	def __init__(self):
		ezplug.EzPlug.__init__(self)
		self.inputSelector = ezplug.EzVarSequence("Input")
		self.thresholdSelector = ezplug.EzVarDouble("Threshold value")

	def getName(self):
		return "Python Thresholder"

	def initialize(self):
		self.addEzComponent(self.inputSelector)
		self.addEzComponent(self.thresholdSelector)

	def execute(self):
		sequence = self.inputSelector.getValue()
		m = self.thresholdSelector.getValue()

		# exit immediately if there is no input sequence
		if sequence == None:
			return

		# convert the data to doubles so that the comparison to the threshold
		# works everytime (it would fail with bytes because of sign issues)
		if sequence.getDataType_() == DataType.DOUBLE:
			doubleSeq = sequence
		else:
			doubleSeq = SequenceUtil.convertToType(sequence, DataType.DOUBLE, False)

		# retrieve the data
		data = doubleSeq.getDataCopyXYAsDouble(0,0,0)

		for i, p in enumerate(data):
			if p

version 1:

download to use and modify in Icy.
Changelog for this version: initial version
from array import array

from  java.awt import EventQueue

from icy.main import Icy
from icy.image import IcyBufferedImage
from icy.sequence import Sequence, SequenceUtil
from icy.type import DataType

import plugins.adufour.ezplug as ezplug

class MyPythonPlugin(ezplug.EzPlug):
	def __init__(self):
		ezplug.EzPlug.__init__(self)
		self.inputSelector = ezplug.EzVarSequence("Input")
		self.thresholdSelector = ezplug.EzVarDouble("Threshold value")

	def getName(self):
		return "Python Thresholder"

	def initialize(self):
		self.addEzComponent(self.inputSelector)
		self.addEzComponent(self.thresholdSelector)

	def execute(self):
		sequence = self.inputSelector.getValue()
		m = self.thresholdSelector.getValue()

		# exit immediately if there is no input sequence
		if sequence == None:
			return

		# convert the data to doubles so that the comparison to the threshold
		# works everytime (it would fail with bytes because of sign issues)
		if sequence.getDataType_() == DataType.DOUBLE:
			doubleSeq = sequence
		else:
			doubleSeq = SequenceUtil.convertToType(sequence, DataType.DOUBLE, False)

		# retrieve the data
		data = doubleSeq.getDataCopyXYAsDouble(0,0,0)

		for i, p in enumerate(data):
			if p


Icy script publication Id : Z8D1T5