fsleyes_widgets.utils.progress

This module provides some classes and functions which use the wx.ProgressDialog to display the progress of some task.

fsleyes_widgets.utils.progress.bounce(*args, **kwargs)[source]

Context manager which creates, starts and yields a Bounce dialog, and destroys it on exit.

fsleyes_widgets.utils.progress.runWithBounce(task, *args, **kwargs)[source]

Runs the given task in a separate thread, and creates a Bounce dialog which is displayed while the task is running.

Parameters:
  • callback – Must be passed as a keyword argument. A function to call when the task has finished. Must accept one boolean parameter which is True if the task ended, or False if the progress dialog was cancelled.

  • dlg – Must be passed as a keyword argument. A Bounce dialog to use. If not provided, one is created. If provided, the caller is responsible for destroying it.

  • polltime – Must be passed as a keyword argument. Amount of time in seconds to wait while periodically checking the task state. Defaults to 0.1 seconds.

All other arguments are passed through to Bounce.__init__(), unless a dlg is provided.

Note

This function is non-blocking - it returns immediately. Use the callback function to be notified when the task has completed.

class fsleyes_widgets.utils.progress.Bounce(title=None, message=None, *args, **kwargs)[source]

Bases: ProgressDialog

Display a ‘bouncing’ progress bar.

The Bounce class is a wx.ProgressDialog for use with tasks with an unknown duration. The progress bar ‘bounces’ back and forth until the dialog is destroyed or cancelled.

A Bounce dialog can either be controlled manually via the DoBounce() method, , or allowed to run automatically via the StartBounce(). Automatic bouncing can be stopped via StopBounce().

Create a Bounce dialog.

Parameters:
  • title – Dialog title.

  • message – Dialog message.

  • delay – Must be passed as a keyword argument. Delay in milliseconds between progress bar updates. Defaults to 200 milliseconds.

  • values – Must be passed as a keyword argument. A sequence of values from 1 to 99 specifying the locations of the progress bar on each update. Deafults to [1, 25, 50, 75, 99].

All other arguments are passed through to wx.ProgressDialog.

classmethod runWithBounce(task, *args, **kwargs)[source]

Deprecated - use the standalone runWithBounce() function instead.

Close()[source]

Close the Bounce dialog.

EndModal(code=5100)[source]

Close the Bounce dialog.

Destroy()[source]

Destroy the Bounce dialog.

StartBounce()[source]

Start automatic bouncing.

StopBounce()[source]

Stop automatic bouncing.

Update(value, message=None)[source]

Overrides wx.ProgressDialog.Update.

The Update method in wxPython 3.0.2.0 will raise an error if a message of None gets passed in. This implementation accepts a message of None.

UpdateMessage(message)[source]

Updates the message displayed on the dialog.

DoBounce(message=None)[source]

Perform a single bounce update to the progress bar.

Parameters:

message – New message to show.

Returns:

False if the dialog gets cancelled, True otherwise.