Пример #1
0
    def __init__(self,
                 parent,
                 overlayList,
                 displayCtx,
                 title=None,
                 style=None):
        """Create an ``OrthoDialog``.

        :arg parent:      A :mod:`wx` parent object.

        :arg overlayList: An :class:`.OverlayList` instance.

        :arg displayCtx:  A :class:`.DisplayContext` instance.

        :arg title:       Dialog title.

        :arg style:       Dialog style - defaults to
                          ``wx.DEFAULT_DIALOG_STYLE``.
        """

        if style is None:
            style = wx.DEFAULT_DIALOG_STYLE

        wx.Dialog.__init__(self, parent, title=title, style=style)

        fslgl.getGLContext()
        fslgl.bootstrap()

        self.panel = OrthoPanel(self, overlayList, displayCtx, None)
        self.Layout()
Пример #2
0
def fsleyes_embed(parent=None, make_fsleyesframe=True, **kwargs):
    """Initialise FSLeyes and create a :class:`.FSLeyesFrame`, when
    running within another application.
    .. note:: If a ``wx.App`` does not exist, one is created.
    :arg parent: ``wx`` parent object
    :arg make_fsleyesframe: bool, default is True to make a new :class:`.FSLeyesFrame`
    :returns:    A tuple containing:
                    - The :class:`.OverlayList`
                    - The master :class:`.DisplayContext`
                    - The :class:`.FSLeyesFrame` or None if make_fsleyesframe=False
    All other arguments are passed to :meth:`.FSLeyesFrame.__init__`.
    """

    import fsleyes_props as props
    import fsleyes.gl as fslgl
    import fsleyes.frame as fslframe
    import fsleyes.overlay as fsloverlay
    import fsleyes.displaycontext as fsldc

    app = wx.GetApp()
    ownapp = app is None
    if ownapp:
        app = FSLeyesApp()

    fsleyes.initialise()
    colourmaps.init()
    props.initGUI()

    called = [False]
    ret = [None]

    def until():
        return called[0]

    def ready():
        frame = None
        fslgl.bootstrap()

        overlayList = fsloverlay.OverlayList()
        displayCtx = fsldc.DisplayContext(overlayList)
        if make_fsleyesframe:
            frame = fslframe.FSLeyesFrame(parent, overlayList, displayCtx,
                                          **kwargs)

        if ownapp:
            app.SetOverlayListAndDisplayContext(overlayList, displayCtx)
            # Keep a ref to prevent the app from being GC'd
            if make_fsleyesframe:
                frame._embed_app = app

        called[0] = True
        ret[0] = (overlayList, displayCtx, frame)

    fslgl.getGLContext(ready=ready, raiseErrors=True)
    idle.block(10, until=until)

    if ret[0] is None:
        raise RuntimeError('Failed to start FSLeyes')
    return ret[0]
Пример #3
0
def main(args=None):
    """Entry point for ``render``.

    Creates and renders an OpenGL scene, and saves it to a file, according
    to the specified command line arguments (which default to
    ``sys.argv[1:]``).
    """

    if args is None:
        args = sys.argv[1:]

    # Initialise FSLeyes and implement hacks.
    # This must come first as, amongst other
    # things, it sets the fsleyes.assetDir.
    fsleyes.initialise()

    # Initialise colour maps module
    fslcm.init()

    # Create a GL context
    fslgl.getGLContext(offscreen=True, createApp=True)

    # Now that GL inititalisation is over,
    # make sure that the idle loop executes
    # all tasks synchronously, instead of
    # trying to schedule them on the wx
    # event loop. And make sure image textures
    # don't use separate threads for data
    # processing.
    with idle.idleLoop.synchronous(), \
         imagetexture.ImageTexture.enableThreading(False):

        # Parse arguments, and
        # configure logging/debugging
        namespace = parseArgs(args)
        fsleyes.configLogging(namespace.verbose, namespace.noisy)

        # Initialise the fsleyes.gl modules
        fslgl.bootstrap(namespace.glversion)

        # Create a description of the scene
        overlayList, displayCtx, sceneOpts = makeDisplayContext(namespace)

        import matplotlib.image as mplimg

        # Render that scene, and save it to file
        bitmap, bg = render(namespace, overlayList, displayCtx, sceneOpts)

        if namespace.crop is not None:
            bitmap = autocrop(bitmap, bg, namespace.crop)
        mplimg.imsave(namespace.outfile, bitmap)
Пример #4
0
    def __init__(self, parent, overlayList, displayCtx, title=None):
        """Create an ``OrthoFrame``.

        :arg parent:      A :mod:`wx` parent object.

        :arg overlayList: An :class:`.OverlayList` instance.

        :arg displayCtx:  A :class:`.DisplayContext` instance.

        :arg title:       Dialog title.
        """

        wx.Frame.__init__(self, parent, title=title)

        fslgl.getGLContext()
        fslgl.bootstrap()

        self.panel = OrthoPanel(self, overlayList, displayCtx, None)
        self.Layout()
Пример #5
0
def main(args=None):
    """Entry point for ``render``.

    Creates and renders an OpenGL scene, and saves it to a file, according
    to the specified command line arguments (which default to
    ``sys.argv[1:]``).
    """

    if args is None:
        args = sys.argv[1:]

    # Initialise FSLeyes and implement hacks.
    # This must come first as, amongst other
    # things, it sets the fsleyes.assetDir.
    fsleyes.initialise()

    # Initialise colour maps module
    fslcm.init()

    # Create a GL context
    fslgl.getGLContext(offscreen=True, createApp=True)

    # Parse arguments, and
    # configure logging/debugging
    namespace = parseArgs(args)
    fsleyes.configLogging(namespace.verbose, namespace.noisy)

    # Initialise the fsleyes.gl modules
    fslgl.bootstrap(namespace.glversion)

    # Create a description of the scene
    overlayList, displayCtx, sceneOpts = makeDisplayContext(namespace)

    import matplotlib.image as mplimg

    # Render that scene, and save it to file
    bitmap, bg = render(namespace, overlayList, displayCtx, sceneOpts)

    if namespace.crop is not None:
        bitmap = autocrop(bitmap, bg, namespace.crop)
    mplimg.imsave(namespace.outfile, bitmap)
Пример #6
0
def main(args=None):
    """Entry point for ``render``.

    Creates and renders an OpenGL scene, and saves it to a file, according
    to the specified command line arguments (which default to
    ``sys.argv[1:]``).
    """

    if args is None:
        args = sys.argv[1:]

    # Create a GL context
    fslgl.getGLContext(offscreen=True, createApp=True)

    # Initialise FSLeyes and implement hacks
    fsleyes.initialise()
    fsleyesmain.hacksAndWorkarounds()

    # Initialise colour maps module
    fslcm.init()

    # Parse arguments, and
    # configure logging/debugging
    namespace = parseArgs(args)
    fsleyes.configLogging(namespace)

    # Initialise the fsleyes.gl modules
    fslgl.bootstrap(namespace.glversion)

    # Create a description of the scene
    overlayList, displayCtx, sceneOpts = makeDisplayContext(namespace)

    import matplotlib.image as mplimg

    # Render that scene, and save it to file
    bitmap = render(namespace, overlayList, displayCtx, sceneOpts)
    mplimg.imsave(namespace.outfile, bitmap)
Пример #7
0
def embed(parent, callback=None, **kwargs):
    """Initialise FSLeyes and create a :class:`.FSLeyesFrame`, when
    running within another application.

    :arg parent:   ``wx`` parent object
    :arg callback: A function which will be called when FSLeyes
                   is ready. Must accept three positional arguments:
                     - The :class:`.OverlayList`
                     - The master :class:`.DisplayContext`
                     - The :class:`.FSLeyesFrame`

    All other arguments are passed to :meth:`.FSLeyesFrame.__init__`.
    """

    import fsleyes_props          as props
    import fsleyes.gl             as fslgl
    import fsleyes.frame          as fslframe
    import fsleyes.overlay        as fsloverlay
    import fsleyes.displaycontext as fsldc

    fsleyes.initialise()
    colourmaps.init()
    props.initGUI()

    def ready():
        fslgl.bootstrap()

        overlayList = fsloverlay.OverlayList()
        displayCtx  = fsldc.DisplayContext(overlayList)

        frame = fslframe.FSLeyesFrame(
            parent, overlayList, displayCtx, **kwargs)

        if callback is not None:
            callback(overlayList, displayCtx, frame)

    fslgl.getGLContext(parent=parent, ready=ready)
Пример #8
0
def initialise(splash, namespace, callback):
    """Called by :func:`main`. Bootstraps/Initialises various parts of
    *FSLeyes*.

    The ``callback`` function is asynchronously called when the initialisation
    is complete.

    :arg splash:    The :class:`.FSLeyesSplash` screen.

    :arg namespace: The ``argparse.Namespace`` object containing parsed
                    command line arguments.

    :arg callback:  Function which is called when initialisation is done.
    """

    import fsl.utils.settings as fslsettings
    import fsleyes_props as props
    import fsleyes.gl as fslgl

    props.initGUI()

    # The save/load directory defaults
    # to the current working directory.
    curDir = op.normpath(os.getcwd())

    # But if we are running as a frozen application, check to
    # see if FSLeyes has been started by the system (e.g.
    # double-clicking instead of being called from the CLI).
    #
    # If so, we set the save/load directory
    # to the user's home directory instead.
    if fwidgets.frozen():

        fsleyesDir = op.dirname(__file__)

        # If we're a frozen OSX application,
        # we need to adjust the FSLeyes dir
        # (which will be:
        #   [install_dir]/FSLeyes.app/Contents/MacOS/fsleyes/),
        #
        # Because the cwd will default to:
        #   [install_dir]/

        if fslplatform.os == 'Darwin':

            fsleyesDir = op.normpath(
                op.join(fsleyesDir, '..', '..', '..', '..'))

        # Similar adjustment for linux
        elif fslplatform.os == 'Linux':
            fsleyesDir = op.normpath(op.join(fsleyesDir, '..'))

        if curDir == fsleyesDir:
            curDir = op.expanduser('~')

    fslsettings.write('loadSaveOverlayDir', curDir)

    # Initialise silly things
    if namespace.bumMode:
        import fsleyes.icons as icons
        icons.BUM_MODE = True

    # Set notebook server port
    fslsettings.write('fsleyes.notebook.port', namespace.notebookPort)

    # This is called by fsleyes.gl.getGLContext
    # when the GL context is ready to be used.
    def realCallback():
        fslgl.bootstrap(namespace.glversion)
        callback()

    try:
        # Force the creation of a wx.glcanvas.GLContext object,
        # and initialise OpenGL version-specific module loads.
        fslgl.getGLContext(ready=realCallback)

    except Exception:
        log.error('Unable to initialise OpenGL!', exc_info=True)
        splash.Destroy()
        sys.exit(1)
Пример #9
0
def embed(mkFrame=True, **kwargs):
    """Initialise FSLeyes and create a :class:`.FSLeyesFrame`, when
    running within another application.

    .. note:: In most cases, this function must be called from the
              ``wx.MainLoop``.

    :arg mkFrame: Defaults to ``True``. If ``False``, FSLeyes is
                  initialised, but a :class:`.FSLeyesFrame` is not created.
                  If you set this to ``False``, you must ensure that a
                  ``wx.App`` object exists before calling this function.

    :returns:     A tuple containing:

                   - The :class:`.OverlayList`
                   - The master :class:`.DisplayContext`
                   - The :class:`.FSLeyesFrame` (or ``None``, if
                     ``makeFrame is False``).

    All other arguments are passed to :meth:`.FSLeyesFrame.__init__`.
    """

    import fsleyes_props as props
    import fsleyes.gl as fslgl
    import fsleyes.frame as fslframe
    import fsleyes.overlay as fsloverlay
    import fsleyes.displaycontext as fsldc

    # initialise must be called before
    # a FSLeyesApp gets created, as it
    # tries to access app_icon.png
    fsleyes.initialise()

    app = wx.GetApp()
    ownapp = app is None

    if ownapp and (mkFrame is False):
        raise RuntimeError('If mkFrame is False, you '
                           'must create a wx.App before '
                           'calling fsleyes.main.embed')
    if ownapp:
        app = FSLeyesApp()

    colourmaps.init()
    props.initGUI()

    called = [False]
    ret = [None]

    def until():
        return called[0]

    def ready():
        fslgl.bootstrap()

        overlayList = fsloverlay.OverlayList()
        displayCtx = fsldc.DisplayContext(overlayList)

        if mkFrame:
            frame = fslframe.FSLeyesFrame(None, overlayList, displayCtx,
                                          **kwargs)
        else:
            frame = None

        if ownapp:
            app.SetOverlayListAndDisplayContext(overlayList, displayCtx)
            # Keep a ref to prevent the app from being GC'd
            frame._embed_app = app

        called[0] = True
        ret[0] = (overlayList, displayCtx, frame)

    fslgl.getGLContext(ready=ready, raiseErrors=True)
    idle.block(10, until=until)

    if ret[0] is None:
        raise RuntimeError('Failed to start FSLeyes')
    return ret[0]