def initgui(): # First thing's first. Create a wx.App, # and initialise the FSLeyes package. app = FSLeyesApp() # Create a splash screen frame splash = fslsplash.FSLeyesSplash(None) return app, splash
def main(args=None): """*FSLeyes* entry point. Shows a :class:`.FSLeyesSplash` screen, parses command line arguments, and shows a :class:`.FSLeyesFrame`. Returns an exit code. """ if args is None: args = sys.argv[1:] # Hack to allow render to # be called via fsleyes.main if len(args) >= 1 and args[0] == 'render': import fsleyes.render as render render.main(args[1:]) sys.exit(0) # Implement various hacks and workarounds hacksAndWorkarounds() # Then, first thing's first. Create a wx.App, # and initialise the FSLeyes package. app = FSLeyesApp() fsleyes.initialise() # Show the splash screen as soon as # possible, unless it looks like the # user is asking for the software # version or command line help. splash = fslsplash.FSLeyesSplash(None) if (len(args) > 0) and (args[0] in ('-V', '-h', '-fh', '--version', '--help', '--fullhelp')): splash.Hide() # We are going do all processing on the # wx.MainLoop, so the GUI can be shown # as soon as possible, and because it is # difficult to force immediate GUI # refreshes when not running on the main # loop - this is important for FSLeyes, # which displays status updates to the # user while it is loading overlays and # setting up the interface. # # All of the work is defined in a series # of functions, which are chained together # via ugly callbacks, but which are # ultimately scheduled and executed on the # wx main loop. # This is a container, shared amongst # the callbacks, which contains the # parsed argparse.Namespace object. namespace = [None] # If argument parsing bombs out, # we put the exit code here and # return it at the bottom. exitCode = [0] def init(splash): # Parse command line arguments. If the # user has asked for help (see above), # the parseargs module will raise # SystemExit. Hence we make sure the # splash screen is shown only after # arguments have been parsed. try: namespace[0] = parseArgs(args) # But the wx.App.MainLoop eats SystemExit # exceptions for unknown reasons, and # and causes the application to exit # immediately. This makes testing FSLeyes # (e.g. code coverage) impossible. So I'm # catching SystemExit here, and then # telling the wx.App to exit gracefully. except SystemExit as e: app.ExitMainLoop() exitCode[0] = e.code return # See FSLeyesSplash.Show # for horribleness. splash.Show() # Configure logging (this has to be done # after cli arguments have been parsed, # but before initialise is called). fsleyes.configLogging(namespace[0]) # Initialise sub-modules/packages. The # buildGui function is passed through # as a callback, which gets called when # initialisation is complete. initialise(splash, namespace[0], buildGui) def buildGui(): # Now the main stuff - create the overlay # list and the master display context, # and then create the FSLeyesFrame. overlayList, displayCtx = makeDisplayContext(namespace[0], splash) app.SetOverlayListAndDisplayContext(overlayList, displayCtx) frame = makeFrame(namespace[0], displayCtx, overlayList, splash) app.SetTopWindow(frame) frame.Show() # Check that $FSLDIR is set, complain # to the user if it isn't if not namespace[0].skipfslcheck: wx.CallAfter(fslDirWarning, frame) # Check for updates. Ignore point # releases, otherwise users might # get swamped with update notifications. if namespace[0].updatecheck: import fsleyes.actions.updatecheck as updatecheck wx.CallAfter(updatecheck.UpdateCheckAction(), showUpToDateMessage=False, showErrorMessage=False, ignorePoint=False) # Note: If no wx.Frame is created, the # wx.MainLoop call will exit immediately, # even if we have scheduled something via # wx.CallAfter. In this case, we have # already created the splash screen, so # all is well. wx.CallAfter(init, splash) app.MainLoop() shutdown() return exitCode[0]