fsleyes.actions.loadoverlay

This module provides the LoadOverlayAction, which allows the user to load overlay files into the OverlayList.

This module also provides a collection of standalone functions which can be called directly:

makeWildcard Returns a wildcard string for use in a file dialog, to limit the the displayed file types to supported overlay file types.
loadOverlays Loads all of the overlays specified in the sequence of files contained in paths.
loadImage Called by the loadOverlays() function.
interactiveLoadOverlays Convenience function for interactively loading one or more overlays.

Finally, this module provides a singleton RecentPathManager instance called recentPathManager, which can be registered with to be notified when new files have been loaded.

class fsleyes.actions.loadoverlay.LoadOverlayAction(overlayList, displayCtx, frame)[source]

Bases: fsleyes.actions.base.Action

The LoadOverlayAction allows the user to add files to the OverlayList.

__init__(overlayList, displayCtx, frame)[source]

Create a LoadOverlayAction.

Parameters:
_LoadOverlayAction__loadOverlay()

Calls interactiveLoadOverlays().

If overlays were added, updates the DisplayContext.selectedOverlay accordingly.

If DisplayContext.autoDisplay is True, uses the autodisplay module to configure the display properties of each new overlay.

__module__ = 'fsleyes.actions.loadoverlay'
fsleyes.actions.loadoverlay.makeWildcard(allowedExts=None, descs=None)[source]

Returns a wildcard string for use in a file dialog, to limit the the displayed file types to supported overlay file types.

fsleyes.actions.loadoverlay.loadOverlays(paths, loadFunc='default', errorFunc='default', saveDir=True, onLoad=None, inmem=False, blocking=False)[source]

Loads all of the overlays specified in the sequence of files contained in paths.

Note

The overlays are loaded asynchronously via idle.idle(). Use the onLoad argument if you wish to be notified when the overlays have been loaded.

Parameters:
  • loadFunc – A function which is called just before each overlay is loaded, and is passed the overlay path. The default load function uses the status module to display the name of the overlay currently being loaded. Pass in None to disable this default behaviour.
  • errorFunc – A function which is called if an error occurs while loading an overlay, being passed the name of the overlay, and either the Exception which occurred, or a string containing an error message. The default function pops up a wx.MessageBox with an error message. Pass in None to disable this default behaviour.
  • saveDir – If True (the default), the directory of the last overlay in the list of paths is saved, and used later on as the default load directory.
  • onLoad

    Optional function to call when all overlays have been loaded. Must accept two parameters:

    • a list of indices, one for each overlay, into the paths parameter, indicating, for each overlay, the path from which it was loaded.
    • a list of the overlays that were loaded
  • inmem – If True, all Image overlays are force-loaded into memory. Otherwise, large compressed files may be kept on disk. Defaults to False.
  • blocking – Defaults to False. If True, overlays are loaded immediately (and the onLoad function is called directly. Otherwise, overlays and the onLoad are loaded and called on the idle.idle() loop.
Returns:

If blocking is False (the default), returns None. Otherwise returns a list containing the loaded overlay objects.

fsleyes.actions.loadoverlay.loadImage(dtype, path, inmem=False)[source]

Called by the loadOverlays() function. Loads an overlay which is represented by an Image instance, or a sub-class of Image. Depending upon the image size, the data may be loaded into memory or kept on disk, and the initial image data range may be calculated from the whole image, or from a sample.

This function returns a sequence, most likely containing a single Image instance. But in some circumstances, more than one Image will be created and returned.

Parameters:
  • dtype – Overlay type (Image, or a sub-class of Image).
  • path – Path to the overlay file.
  • inmem – If True, Image overlays are loaded into memory.
Returns:

A sequence of Image instances that were loaded.

fsleyes.actions.loadoverlay._loadImage(dtype, path, nbytes, inmem)[source]

Loads an image with a non-complex data type.

Parameters:
  • dtype – Overlay type - Image, or a sub-class of Image.
  • path – Path to the image file
  • nbytes – Number of bytes that the image data takes up.
  • inmem – If True, the file is loaded into memory.
fsleyes.actions.loadoverlay.interactiveLoadOverlays(fromDir=None, dirdlg=False, **kwargs)[source]

Convenience function for interactively loading one or more overlays.

Pops up a file dialog prompting the user to select one or more overlays to load.

Parameters:
  • fromDir – Directory in which the file dialog should start. If None, the most recently visited directory (via this function) is used, or a directory from An already loaded overlay, or the current working directory.
  • dirdlg – Use a directory chooser instead of a file dialog.
  • kwargs – Passed through to the loadOverlays() function.
Raises:
  • ImportError – if wx is not present.
  • RuntimeError – if a wx.App has not been created.
class fsleyes.actions.loadoverlay.RecentPathManager(*args, **kwargs)[source]

Bases: __main__.MockClass

The RecentPathManager is a simple class which provides access to a list of recently loaded files, and can notify registered listeners when that list changes. See the recentPathManager singleton instance.

recordPath(path)[source]

Adds the given path to the recent files list.

listRecentPaths()[source]

Returns a list of recently loaded files.

__module__ = 'fsleyes.actions.loadoverlay'
fsleyes.actions.loadoverlay.recentPathManager = <fsleyes.actions.loadoverlay.RecentPathManager object>

A RecentPathManager instance which gets updated by the loadOverlays() function whenever a new path is loaded. Register as a listener on this instance if you want to be notified of changes to the recent paths list.