fsleyes_widgets.utils.status
This is a little module which provides an interface for displaying a
message, or status update, to the user. The status module provides the
following functions:
Set a target function to receive status updates.
Display a status update to the user.
Clear the status.
A couple of other functions are also provided, for reporting error messages to the user:
Reports an error to the user in a generic manner.
A context manager which calls
reportError()if the enclosed code raises anException.A decorator which wraps the decorated function with
reportIfError().
The update() function may be used to display a message. By default, the
message is simply logged (via the logging module). However, if a status
target has been set via the setTarget() function, the message is also
passed to this target.
Warning
If the status update target is a wx GUI object, you must
make sure that it is updated asynchronously (e.g. via
wx.CallAfter).
- fsleyes_widgets.utils.status.setTarget(target)[source]
Set a target function to receive status updates. The
targetmust be a function which accepts a string as its sole parameter.
- fsleyes_widgets.utils.status.update(message, timeout=1.0)[source]
Display a status update to the user. The message is logged and, if a status update target has been set, passed to the target.
- Parameters:
timeout – Timeout (in seconds) after which the status will be cleared (via the
ClearThread). Pass inNoneto disable this behaviour.
Note
The
timeoutmethod only makes sense to use if the status target is a GUI widget of some sort.
- fsleyes_widgets.utils.status.clearStatus()[source]
Clear the status. If a status update target has been set, it is passed the empty string.
- fsleyes_widgets.utils.status.reportError(title, msg, err)[source]
Reports an error to the user in a generic manner. If a GUI is available, a
wx.MessageBoxis shown. Otherwise a log message is generated.
- fsleyes_widgets.utils.status.reportIfError(title, msg, raiseError=True, report=True)[source]
A context manager which calls
reportError()if the enclosed code raises anException.- Parameters:
raiseError – If
True, theExceptionwhich was raised is propagated upwards.report – Defaults to
True. IfFalse, an error message is logged, butreportError()is not called.
- fsleyes_widgets.utils.status.reportErrorDecorator(*args, **kwargs)[source]
A decorator which wraps the decorated function with
reportIfError().
- class fsleyes_widgets.utils.status.ClearThread[source]
Bases:
ThreadThe
ClearThreadis a daemon thread used by theupdate()function. Only oneClearThreadis ever started - it is started on the first call toupdatewhen a timeout is specified.The
ClearThreadwaits until theclear()method is called. It then waits for the specified timeout and, unless another call toclear(), or a call toveto()has been made, clears the status via a call toclearStatus().Create a
ClearThread.- veto()[source]
If this
ClearThreadis waiting on a timeout to clear the status, a call tovetowill prevent it from doing so.
- die()[source]
This method may be used to force the
ClearThreadto exit immediately, rather than when the process exits.To cleanly kill the
ClearThread, follow this procedure:import fsleyes_widgets.utils.status as status status._clearThread.die() status._clearThread.clear(0.1) status._clearThread.join() status._clearThread = None
If the
update()function is used again, a newClearThreadwill automatically be started.
- run()[source]
The
ClearThreadfunction. Infinite loop which waits until theclear()method is called, and then clears the status (via a call toclearStatus()).