def init(): fsleyes.initialise() props.initGUI() colourmaps.init() initialised[0] = True fslgl.bootstrap(glver) wx.CallAfter(run)
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]
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)
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)
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]
def setup_module(): props.initGUI()