Exemplo n.º 1
0
        class MyInteger:
            new_fn = javabridge.make_new("java/lang/Integer", '(I)V')

            def __init__(self, value):
                self.new_fn(value)

            intValue = javabridge.make_method("intValue", '()I')
Exemplo n.º 2
0
            class OMETiffWriter(IFormatWriter):

                new_fn = javabridge.make_new("loci/formats/out/OMETiffWriter",
                                             "()V")

                def __init__(self):

                    self.new_fn()

                setId = javabridge.make_method("setId",
                                               "(Ljava/lang/String;)V",
                                               "Sets the current file name.")
                saveBytesXYWH = javabridge.make_method(
                    "saveBytes", "(I[BIIII)V",
                    "Saves the given byte array to the current file")
                close = javabridge.make_method(
                    "close", "()V",
                    "Closes currently open file(s) and frees allocated memory."
                )
                setTileSizeX = javabridge.make_method(
                    "setTileSizeX", "(I)I", "Set tile size width in pixels.")
                setTileSizeY = javabridge.make_method(
                    "setTileSizeY", "(I)I", "Set tile size height in pixels.")
                getTileSizeX = javabridge.make_method(
                    "getTileSizeX", "()I", "Set tile size width in pixels.")
                getTileSizeY = javabridge.make_method(
                    "getTileSizeY", "()I", "Set tile size height in pixels.")
                setBigTiff = javabridge.make_method("setBigTiff", "(Z)V",
                                                    "Set the BigTiff flag.")
Exemplo n.º 3
0
    class OMETiffWriter(IFormatWriter):

        new_fn = jutil.make_new('loci/formats/out/OMETiffWriter', '()V')

        def __init__(self):

            self.new_fn()
Exemplo n.º 4
0
def make_format_writer_class(class_name):
    '''Make a FormatWriter wrapper class

    class_name - the name of a class that implements loci.formats.FormatWriter
                 Known names in the loci.formats.out package:
                     APNGWriter, AVIWriter, EPSWriter, ICSWriter, ImageIOWriter,
                     JPEG2000Writer, JPEGWriter, LegacyQTWriter, OMETiffWriter,
                     OMEXMLWriter, QTWriter, TiffWriter
    '''
    new_fn = jutil.make_new(class_name,
                            '(Ljava/lang/String;Ljava/lang/String;)V')
    class FormatWriter(object):
        __doc__ = '''A wrapper for %s implementing loci.formats.FormatWriter
        See http://hudson.openmicroscopy.org.uk/job/LOCI/javadoc/loci/formats/FormatWriter'''%class_name
        def __init__(self):
            self.new_fn()

        canDoStacks = jutil.make_method('canDoStacks','()Z',
                                        'Reports whether the writer can save multiple images to a single file')
        getColorModel = jutil.make_method('getColorModel',
                                          '()Ljava/awt/image/ColorModel;',
                                          'Gets the color model')
        getCompression = jutil.make_method('getCompression',
                                           '()Ljava/lang/String;',
                                           'Gets the current compression type')
        getCompressionTypes = jutil.make_method('getCompressionTypes',
                                                '()[Ljava/lang/String;',
                                                'Gets the available compression types')
        getFramesPerSecond = jutil.make_method('getFramesPerSecond',
                                               '()I', "Gets the frames per second to use when writing")
        getMetadataRetrieve = jutil.make_method('getMetadataRetrieve',
                                                '()Lloci/formats/meta/MetadataRetrieve;',
                                                'Retrieves the current metadata retrieval object for this writer.')

        getPixelTypes = jutil.make_method('getPixelTypes',
                                          '()[I')
        isInterleaved = jutil.make_method('isInterleaved','()Z',
                                          'Gets whether or not the channels in an image are interleaved')
        isSupportedType = jutil.make_method('isSupportedType','(I)Z',
                                            'Checks if the given pixel type is supported')
        saveBytes = jutil.make_method('saveBytes', '([BZ)V',
                                      'Saves the given byte array to the current file')
        setColorModel = jutil.make_method('setColorModel',
                                          '(Ljava/awt/image/ColorModel;)V',
                                          'Sets the color model')
        setCompression = jutil.make_method('setCompression',
                                           '(Ljava/lang/String;)V',
                                           'Sets the current compression type')
        setFramesPerSecond = jutil.make_method('setFramesPerSecond',
                                               '(I)V',
                                               'Sets the frames per second to use when writing')
        setId = jutil.make_method('setId','(Ljava/lang/String;)V',
                                  'Sets the current file name')
        setInterleaved = jutil.make_method('setInterleaved', '(Z)V',
                                           'Sets whether or not the channels in an image are interleaved')
        setMetadataRetrieve = jutil.make_method('setMetadataRetrieve',
                                                '(Lloci/formats/meta/MetadataRetrieve;)V',
                                                'Sets the metadata retrieval object from which to retrieve standardized metadata')
    return FormatWriter
Exemplo n.º 5
0
                class JavaEncoder():
                    new_fn = javabridge.make_new("java/lang/String",
                                                 "([BLjava/lang/String;)V")

                    def __init__(self, i, s):
                        self.new_fn(i, s)

                    toString = javabridge.make_method(
                        "toString", "()Ljava/lang/String;",
                        "Retrieve the integer value")
Exemplo n.º 6
0
    class ReaderWrapper(IFormatReader):
        __doc__ = '''A wrapper for %s

        See http://hudson.openmicroscopy.org.uk/job/LOCI/javadoc/loci/formats/ImageReader.html
        '''%class_name
        new_fn = jutil.make_new(class_name, '(Lloci/formats/IFormatReader;)V')
        def __init__(self, rdr):
            self.new_fn(rdr)

        setId = jutil.make_method('setId', '(Ljava/lang/String;)V',
                                  'Set the name of the data file')
Exemplo n.º 7
0
    class WriterWrapper(IFormatWriter):
        __doc__ = '''A wrapper for %s

        See http://hudson.openmicroscopy.org.uk/job/LOCI/javadoc/loci/formats/ImageWriter.html
        ''' % class_name
        new_fn = jutil.make_new(class_name, '(Lloci/formats/IFormatWriter;)V')

        def __init__(self, writer):
            self.new_fn(writer)

        setId = jutil.make_method('setId', '(Ljava/lang/String;)V',
                                  'Sets the current file name.')
Exemplo n.º 8
0
    def __init__(self, class_name, *args):
        """
        Creates a function decorator for a javabridge function that is
        a constructor for an instantiated class

        Arguments:

        class_name -- The name of the java class, as in path/to/class
        args -- tuples of form (java signature,(python arg types))
                e.g. ("(I)V",(int,))
        """
        self.class_name = class_name
        ## Create signature dictionary of {(python args) -> function}
        self.func_dict = signature_dict()
        for sig, pyargs in args:
            self.func_dict[pyargs] = javabridge.make_new(self.class_name,sig)
Exemplo n.º 9
0
        def __init__(self):
            self.new_fn = jutil.make_new(self.class_name, '()V')
            self.setId = jutil.make_method('setId', '(Ljava/lang/String;)V',
                                           'Sets the current file name.')
            self.close = jutil.make_method(
                'close', '()V',
                'Closes currently open file(s) and frees allocated memory.')
            self.saveBytesIFD = jutil.make_method(
                'saveBytes', '(I[BLloci/formats/tiff/IFD;)V',
                '''save a byte array to an image channel

                index - image index
                bytes - byte array to save
                ifd - a loci.formats.tiff.IFD instance that gives all of the
                IFD values associated with the channel''')

            self.new_fn()
Exemplo n.º 10
0
        def __init__(self):
            self.new_fn = jutil.make_new(self.class_name, '()V')
            self.setId = jutil.make_method('setId', '(Ljava/lang/String;)V',
                                           'Sets the current file name.')
            self.close = jutil.make_method(
                'close','()V',
                'Closes currently open file(s) and frees allocated memory.')
            self.saveBytesIFD = jutil.make_method(
                'saveBytes', '(I[BLloci/formats/tiff/IFD;)V',
                '''save a byte array to an image channel

                index - image index
                bytes - byte array to save
                ifd - a loci.formats.tiff.IFD instance that gives all of the
                IFD values associated with the channel''')

            self.new_fn()
Exemplo n.º 11
0
    class ImageReader(IFormatReader):
        new_fn = jutil.make_new(class_name, '(Lloci/formats/ClassList;)V')

        def __init__(self):
            self.new_fn(class_list.o)

        getFormat = jutil.make_method(
            'getFormat', '()Ljava/lang/String;',
            'Get a string describing the format of this file')
        getReader = jutil.make_method('getReader',
                                      '()Lloci/formats/IFormatReader;')

        def allowOpenToCheckType(self, allow):
            '''Allow the "isThisType" function to open files

            For the cluster, you want to tell potential file formats
            not to open the image file to test if it's their format.
            '''
            if not hasattr(self, "allowOpenToCheckType_method"):
                self.allowOpenToCheckType_method = None
                class_wrapper = jutil.get_class_wrapper(self.o)
                methods = class_wrapper.getMethods()
                for method in jutil.get_env().get_object_array_elements(
                        methods):
                    m = jutil.get_method_wrapper(method)
                    if m.getName() in ('allowOpenToCheckType',
                                       'setAllowOpenFiles'):
                        self.allowOpenToCheckType_method = m
            if self.allowOpenToCheckType_method is not None:
                object_class = env.find_class('java/lang/Object')
                jexception = jutil.get_env().exception_occurred()
                if jexception is not None:
                    raise jutil.JavaException(jexception)

                boolean_value = jutil.make_instance('java/lang/Boolean',
                                                    '(Z)V', allow)
                args = jutil.get_env().make_object_array(1, object_class)
                jexception = jutil.get_env().exception_occurred()
                if jexception is not None:
                    raise jutil.JavaException(jexception)
                jutil.get_env().set_object_array_element(
                    args, 0, boolean_value)
                jexception = jutil.get_env().exception_occurred()
                if jexception is not None:
                    raise jutil.JavaException(jexception)
                self.allowOpenToCheckType_method.invoke(self.o, args)
Exemplo n.º 12
0
    class ImageWriter(IFormatWriter):
        new_fn = jutil.make_new(class_name, '(Lloci/formats/ClassList;)V')

        def __init__(self):
            self.new_fn(class_list)

        setId = jutil.make_method('setId', '(Ljava/lang/String;)V',
                                  'Sets the current file name.')
        addStatusListener = jutil.make_method(
            'addStatusListener', '()Lloci/formats/StatusListener;',
            'Adds a listener for status update events.')
        close = jutil.make_method(
            'close', '()V',
            'Closes currently open file(s) and frees allocated memory.')
        getFormat = jutil.make_method('getFormat', '()Ljava/lang/String;',
                                      'Gets the name of this file format.')
        getNativeDataType = jutil.make_method(
            'getNativeDataType', '()Ljava/lang/Class;',
            'Returns the native data type of image planes for this reader, as returned by IFormatReader.openPlane(int, int, int, int, int) or IFormatWriter#saveData.'
        )
        getStatusListeners = jutil.make_method(
            'getStatusListeners', '()[Lloci/formats/StatusListener;',
            'Gets a list of all registered status update listeners.')
        getSuffixes = jutil.make_method(
            'getSuffixes', '()Ljava/lang/String;',
            'Gets the default file suffixes for this file format.')
        getWriter = jutil.make_method(
            'getWriter', '()Lloci/formats/IFormatWriter;',
            'Gets the writer used to save the current file.')
        #        getWriter = jutil.make_method('getWriter', '(Ljava/lang/Class)Lloci/formats/IFormatWriter;',
        #                                      'Gets the file format writer instance matching the given class.')
        #        getWriter = jutil.make_method('getWriter', '(Ljava/lang/String;)Lloci/formats/IFormatWriter;',
        #                                      'Gets the writer used to save the given file.')
        getWriters = jutil.make_method(
            'getWriters', '()[Lloci/formats/IFormatWriter;',
            'Gets all constituent file format writers.')
        isThisType = jutil.make_method(
            'isThisType', '(Ljava/lang/String;)Z',
            'Checks if the given string is a valid filename for this file format.'
        )
        removeStatusListener = jutil.make_method(
            'removeStatusListener', '(Lloci/formats/StatusListener;)V',
            'Saves the given byte array to the current file.')
Exemplo n.º 13
0
        class MyClass:
            new_fn = javabridge.make_new("java/lang/Object", '()V')

            def __init__(self):
                self.new_fn()
Exemplo n.º 14
0
def make_format_writer_class(class_name):
    '''Make a FormatWriter wrapper class

    class_name - the name of a class that implements loci.formats.FormatWriter
                 Known names in the loci.formats.out package:
                     APNGWriter, AVIWriter, EPSWriter, ICSWriter, ImageIOWriter,
                     JPEG2000Writer, JPEGWriter, LegacyQTWriter, OMETiffWriter,
                     OMEXMLWriter, QTWriter, TiffWriter
    '''
    new_fn = jutil.make_new(class_name,
                            '(Ljava/lang/String;Ljava/lang/String;)V')

    class FormatWriter(object):
        __doc__ = '''A wrapper for %s implementing loci.formats.FormatWriter
        See http://hudson.openmicroscopy.org.uk/job/LOCI/javadoc/loci/formats/FormatWriter''' % class_name

        def __init__(self):
            self.new_fn()

        canDoStacks = jutil.make_method(
            'canDoStacks', '()Z',
            'Reports whether the writer can save multiple images to a single file'
        )
        getColorModel = jutil.make_method('getColorModel',
                                          '()Ljava/awt/image/ColorModel;',
                                          'Gets the color model')
        getCompression = jutil.make_method(
            'getCompression', '()Ljava/lang/String;',
            'Gets the current compression type')
        getCompressionTypes = jutil.make_method(
            'getCompressionTypes', '()[Ljava/lang/String;',
            'Gets the available compression types')
        getFramesPerSecond = jutil.make_method(
            'getFramesPerSecond', '()I',
            "Gets the frames per second to use when writing")
        getMetadataRetrieve = jutil.make_method(
            'getMetadataRetrieve', '()Lloci/formats/meta/MetadataRetrieve;',
            'Retrieves the current metadata retrieval object for this writer.')

        getPixelTypes = jutil.make_method('getPixelTypes', '()[I')
        isInterleaved = jutil.make_method(
            'isInterleaved', '()Z',
            'Gets whether or not the channels in an image are interleaved')
        isSupportedType = jutil.make_method(
            'isSupportedType', '(I)Z',
            'Checks if the given pixel type is supported')
        saveBytes = jutil.make_method(
            'saveBytes', '([BZ)V',
            'Saves the given byte array to the current file')
        setColorModel = jutil.make_method('setColorModel',
                                          '(Ljava/awt/image/ColorModel;)V',
                                          'Sets the color model')
        setCompression = jutil.make_method(
            'setCompression', '(Ljava/lang/String;)V',
            'Sets the current compression type')
        setFramesPerSecond = jutil.make_method(
            'setFramesPerSecond', '(I)V',
            'Sets the frames per second to use when writing')
        setId = jutil.make_method('setId', '(Ljava/lang/String;)V',
                                  'Sets the current file name')
        setInterleaved = jutil.make_method(
            'setInterleaved', '(Z)V',
            'Sets whether or not the channels in an image are interleaved')
        setMetadataRetrieve = jutil.make_method(
            'setMetadataRetrieve', '(Lloci/formats/meta/MetadataRetrieve;)V',
            'Sets the metadata retrieval object from which to retrieve standardized metadata'
        )

    return FormatWriter