fsleyes_widgets.dialog
This module contains a collection of basic dialog classes, available for
use throughout fslpy. The available dialogs are:
A simple, no-frills |
|
A |
|
A |
|
A dialog which shows an editable/selectable text field. |
|
A dialog which warns the user that the |
- class fsleyes_widgets.dialog.SimpleMessageDialog(parent=None, message='', style=None)[source]
Bases:
DialogA simple, no-frills
wx.Dialogfor displaying a message. The message can be updated via theSetMessage()method. As a simple usage example:import fsleyes_widgets.dialog as fsldlg dlg = fsldlg.SimpleMessageDialog(message='Loading data ...') dlg.Show() # load the data, like # you said you would # Data is loaded, so we # can kill the dialog dlg.Close() dlg.Destroy()
The
SimpleMessageDialogclass supports the following styles:If set, the dialog will be re-centred on its parent whenever its message changes.
a
SimpleMessageDialoglooks something like this:
Create a
SimpleMessageDialog.- Parameters:
parent – The
wxparent object.message – The initial message to show.
style – Only one style flag is supported,
SMD_KEEP_CENTERED. This flag is enabled by default.
- SetMessage(msg)[source]
Updates the message shown on this
SimpleMessageDialog.If the
SMD_KEEP_CENTEREDstyle is set, the dialog is re-centered on its parent, to account for changes in the message width.
- fsleyes_widgets.dialog.SMD_KEEP_CENTERED = 1
If set, the dialog will be re-centred on its parent whenever its message changes.
- class fsleyes_widgets.dialog.TimeoutDialog(parent, message, timeout=1000, **kwargs)[source]
Bases:
SimpleMessageDialogA
SimpleMessageDialogwhich automatically destroys itself after a specified timeout period.Note
The timeout functionality will not work if you show the dialog by any means other than the
wx.Dialog.Show()orwx.Dialog.ShowModal()methods … but is there any other way of showing awx.Dialog?Create a
TimeoutDialog.- Parameters:
parent – The
wxparent object.message – The initial message to display.
timeout – Timeout period in milliseconds.
kwargs – Passed through to
SimpleMessageDialog.__init__().
- class fsleyes_widgets.dialog.ProcessingDialog(parent, message, task, *args, **kwargs)[source]
Bases:
SimpleMessageDialogA
SimpleMessageDialogwhich displays a message and runs a task in the background. User interaction is blocked while the task runs, and the dialog closes and destroys itself automatically on task completion.The task is simply passed in as a function. If the task supports it, the
ProcessingDialogwill pass it two message-updating functions, which can be used by the task to update the message being displayed. This functionality is controlled by thepassFuncs,messageFuncanderrorFuncparameters to__init__().A
ProcessingDialogmust be displayed via theRun()method, not with thewx.Dialog.Show()orwx.Dialog.ShowModal()methods.Create a
ProcessingDialog.- Parameters:
parent – The
wxparent object.message – Initial message to display.
task – The function to run.
args – Positional arguments passed to the
taskfunction.kwargs – Keyword arguments passed to the
taskfunction.
Some special keyword arguments are also accepted:
Name
Description
passFuncsIf
True, two extra keyword arguments are passed to thetaskfunction -messageFuncanderrorFunc.messageFuncis a function which accepts a single string as its argument; when it is called, the dialog message is updated to display the string.errorFuncis a function which accepts two arguemnts - a message string and anExceptioninstance. If the task detects an error, it may call this function. A new dialog is shown, containing the details of the error, to inform the user.messageFuncOverrides the default
messageFuncdescribed above.errorFuncOverrides the default
errorFuncdescribed above.- Run(mainThread=False)[source]
Shows this
ProcessingDialog, and runs thetaskfunction passed to__init__(). When the task completes, this dialog is closed and destroyed.- Parameters:
mainThread – If
Truethe task is run in the current thread. Otherwise, the default behaviour is to run the task in a separate thread.- Returns:
the return value of the
taskfunction.
Note
If
mainThread=True, the task should callwx.Yield()periodically - under GTK, there is a chance that thisProcessingDialogwill not get drawn before the task begins.
- class fsleyes_widgets.dialog.TextEditDialog(parent, title='', message='', text='', icon=None, style=None)[source]
Bases:
DialogA dialog which shows an editable/selectable text field.
TextEditDialogsupports the following styles:If set, the user will not be able to change the text field contents.
If set, the text field will span multiple lines.
If set, an Ok button will be shown.
If set, a Cancel button will be shown.
If set, Ok and Cancel buttons will be shown.
If set, a Copy button will be shown, allowing the use to copy the text to the system clipboard.
If set, and if
TED_COPYis also set, when the user chooses to copy the text to the system clipboard, a popup message is displayed.A
TextEditDialoglooks something like this:
Create a
TextEditDialog.- Parameters:
parent – The
wxparent object.title – Dialog title.
message – Dialog message.
text – String to display in the text field.
icon – A
wxicon identifier, such aswx.ICON_INFORMATIONorwx.ICON_WARNING.style – A combination of
TED_READONLY,TED_MULTILINE,TED_OK,TED_CANCEL,TED_OK_CANCEL,TED_COPYandTED_COPY_MESSAGE. Defaults toTED_OK.
- fsleyes_widgets.dialog.TED_READONLY = 1
If set, the user will not be able to change the text field contents.
- fsleyes_widgets.dialog.TED_MULTILINE = 2
If set, the text field will span multiple lines.
- fsleyes_widgets.dialog.TED_OK = 4
If set, an Ok button will be shown.
- fsleyes_widgets.dialog.TED_CANCEL = 8
If set, a Cancel button will be shown.
- fsleyes_widgets.dialog.TED_OK_CANCEL = 12
If set, Ok and Cancel buttons will be shown. Equivalent to
TED_OK | TED_CANCEL.
- fsleyes_widgets.dialog.TED_COPY = 16
If set, a Copy button will be shown, allowing the use to copy the text to the system clipboard.
- fsleyes_widgets.dialog.TED_COPY_MESSAGE = 32
If set, and if
TED_COPYis also set, when the user chooses to copy the text to the system clipboard, a popup message is displayed.
- class fsleyes_widgets.dialog.FSLDirDialog(parent, toolName, osxHint, defaultPath=None)[source]
Bases:
DialogA dialog which warns the user that the
$FSLDIRenvironment variable is not set, and prompts them to identify the FSL installation directory.If the user selects a directory, the
getFSLDir()method can be called to retrieve their selection after the dialog has been closed.A
FSLDirDialoglooks something like this:
Create a
FSLDirDialog.- Parameters:
parent – The
wxparent object.toolName – The name of the tool which is running.
osxHint – If
True, an OSX-specific hint is added to the dialog.defaultPath – Directory to initialise the selection dialog when prompting the user to select
$FSLDIR. Defaults to$HOME.
- class fsleyes_widgets.dialog.CheckBoxMessageDialog(parent, title=None, message=None, cbMessages=None, cbStates=None, yesText=None, noText=None, cancelText=None, hintText=None, focus=None, icon=None, style=None)[source]
Bases:
DialogA
wx.Dialogwhich displays a message, one or morewx.CheckBoxwidgets, with associated messages, an Ok button, and (optionally) a Cancel button.Create a
CheckBoxMessageDialog.- Parameters:
parent – A
wxparent object.title – The dialog frame title.
message – Message to show on the dialog.
cbMessages – A list of labels, one for each
wx.CheckBox.cbStates – A list of initial states (boolean values) for each
wx.CheckBox.yesText – Text to show on the yes/confirm button. Defaults to OK.
noText – Text to show on the no button. If not provided, there will be no no button.
cancelText – Text to show on the cancel button. If not provided, there will be no cancel button.
hintText – If provided, shown as a “hint”, in a slightly faded font, between the checkboxes and the buttons.
focus – One of
'yes','no'`, or'cancel', specifying which button should be given initial focus.icon – A
wxicon identifier (e.g.wx.ICON_EXCLAMATION).style – Passed through to the
wx.Dialog.__init__method. Defaults towx.DEFAULT_DIALOG_STYLE.