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:
Returns a wildcard string for use in a file dialog, to limit the the displayed file types to supported overlay file types. |
|
Loads all of the overlays specified in the sequence of files contained in |
|
Called by the |
|
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 theOverlayList
.-
__init__
(overlayList, displayCtx, frame)[source]¶ Create a
LoadOverlayAction
.- Parameters
overlayList – The
OverlayList
.displayCtx – The
DisplayContext
.frame – The
FSLeyesFrame
.
-
_LoadOverlayAction__loadOverlay
()¶ Calls
interactiveLoadOverlays()
.If overlays were added, updates the
DisplayContext.selectedOverlay
accordingly.If
DisplayContext.autoDisplay
isTrue
, uses theautodisplay
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 theonLoad
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 inNone
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 awx.MessageBox
with an error message. Pass inNone
to disable this default behaviour.saveDir – If
True
(the default), the directory of the last overlay in the list ofpaths
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
, allImage
overlays are force-loaded into memory. Otherwise, large compressed files may be kept on disk. Defaults toFalse
.blocking – Defaults to
False
. IfTrue
, overlays are loaded immediately (and theonLoad
function is called directly. Otherwise, overlays and theonLoad
are loaded and called on theidle.idle()
loop.
- Returns
If
blocking is False
(the default), returnsNone
. 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 anImage
instance, or a sub-class ofImage
. 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 oneImage
will be created and returned.- Parameters
dtype – Overlay type (
Image
, or a sub-class ofImage
).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 ofImage
.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 therecentPathManager
singleton instance.-
__module__
= 'fsleyes.actions.loadoverlay'¶
-
-
fsleyes.actions.loadoverlay.
recentPathManager
= <fsleyes.actions.loadoverlay.RecentPathManager object>¶ A
RecentPathManager
instance which gets updated by theloadOverlays()
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.