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:
Dialog
A simple, no-frills
wx.Dialog
for 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
SimpleMessageDialog
class supports the following styles:If set, the dialog will be re-centred on its parent whenever its message changes.
a
SimpleMessageDialog
looks something like this:Create a
SimpleMessageDialog
.- Parameters:
parent – The
wx
parent 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_CENTERED
style 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:
SimpleMessageDialog
A
SimpleMessageDialog
which 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
wx
parent 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:
SimpleMessageDialog
A
SimpleMessageDialog
which 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
ProcessingDialog
will 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
,messageFunc
anderrorFunc
parameters to__init__()
.A
ProcessingDialog
must be displayed via theRun()
method, not with thewx.Dialog.Show()
orwx.Dialog.ShowModal()
methods.Create a
ProcessingDialog
.- Parameters:
parent – The
wx
parent object.message – Initial message to display.
task – The function to run.
args – Positional arguments passed to the
task
function.kwargs – Keyword arguments passed to the
task
function.
Some special keyword arguments are also accepted:
Name
Description
passFuncs
If
True
, two extra keyword arguments are passed to thetask
function -messageFunc
anderrorFunc
.messageFunc
is a function which accepts a single string as its argument; when it is called, the dialog message is updated to display the string.errorFunc
is a function which accepts two arguemnts - a message string and anException
instance. 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.messageFunc
Overrides the default
messageFunc
described above.errorFunc
Overrides the default
errorFunc
described above.- Run(mainThread=False)[source]
Shows this
ProcessingDialog
, and runs thetask
function passed to__init__()
. When the task completes, this dialog is closed and destroyed.- Parameters:
mainThread – If
True
the 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
task
function.
Note
If
mainThread=True
, the task should callwx.Yield()
periodically - under GTK, there is a chance that thisProcessingDialog
will not get drawn before the task begins.
- class fsleyes_widgets.dialog.TextEditDialog(parent, title='', message='', text='', icon=None, style=None)[source]
Bases:
Dialog
A dialog which shows an editable/selectable text field.
TextEditDialog
supports 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_COPY
is also set, when the user chooses to copy the text to the system clipboard, a popup message is displayed.A
TextEditDialog
looks something like this:Create a
TextEditDialog
.- Parameters:
parent – The
wx
parent object.title – Dialog title.
message – Dialog message.
text – String to display in the text field.
icon – A
wx
icon identifier, such aswx.ICON_INFORMATION
orwx.ICON_WARNING
.style – A combination of
TED_READONLY
,TED_MULTILINE
,TED_OK
,TED_CANCEL
,TED_OK_CANCEL
,TED_COPY
andTED_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_COPY
is 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:
Dialog
A dialog which warns the user that the
$FSLDIR
environment 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
FSLDirDialog
looks something like this:Create a
FSLDirDialog
.- Parameters:
parent – The
wx
parent 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:
Dialog
A
wx.Dialog
which displays a message, one or morewx.CheckBox
widgets, with associated messages, an Ok button, and (optionally) a Cancel button.Create a
CheckBoxMessageDialog
.- Parameters:
parent – A
wx
parent 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
wx
icon identifier (e.g.wx.ICON_EXCLAMATION
).style – Passed through to the
wx.Dialog.__init__
method. Defaults towx.DEFAULT_DIALOG_STYLE
.