msl.qt.prompt module¶
Convenience functions to prompt the user.
The following functions create a dialog window to either notify the user of an event that happened or to request information from the user.
- msl.qt.prompt.critical(message, *, title=None, font=None)[source]¶
Display a critical message in a dialog window.
- Parameters:
message (
strorException) – The message to display. The message can use HTML/CSS markup, for example,'<html>A <p style="color:red;font-size:18px"><i>critical</i></p> error occurred!</html>'title (
str, optional) – The text to display in the title bar of the dialog window. IfNonethen uses the text in the title bar of the active window.font (
int,str,tupleorQtGui.QFont, optional) – The font to use. If anintthen the point size, if astrthen the family name, if atuplethen the (family name, point size).
- msl.qt.prompt.double(message, *, title=None, font=None, value=0, minimum=-2147483647, maximum=2147483647, step=1, decimals=2)[source]¶
Request a double-precision value (a Python
floatdata type).- Parameters:
message (
str) – The message that is shown to the user to describe what the value represents. The message can use HTML/CSS markup, for example,'<html>Enter a mass, in μg</html>'title (
str, optional) – The text to display in the title bar of the dialog window. IfNonethen uses the text in the title bar of the active window.font (
int,str,tupleorQtGui.QFont, optional) – The font to use. If anintthen the point size, if astrthen the family name, if atuplethen the (family name, point size).value (
float, optional) – The initial value.minimum (
float, optional) – The minimum value that the user can enter.maximum (
float, optional) – The maximum value that the user can enter.step (
float, optional) – The step size by which the value is increased and decreased.decimals (
int, optional) – The number of digits that are displayed after the decimal point.
- Returns:
floatorNone– The value orNoneif the user cancelled the request.
- msl.qt.prompt.filename(*, title='Select File', directory=None, filters=None, multiple=False)[source]¶
Request to select the file(s) to open.
- Parameters:
title (
str, optional) – The text to display in the title bar of the dialog window.directory (
str, optional) – The initial directory to start in.filters (
str,listofstrordict, optional) –Only filenames that match the specified filters are shown.
Examples:
'Images (*.png *.xpm *.jpg)' 'Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)' ['Images (*.png *.xpm *.jpg)', 'Text files (*.txt)', 'XML files (*.xml)'] {'Images': ('*.png', '*.xpm', '*.jpg'), 'Text files': '*.txt'}
multiple (
bool, optional) – Whether multiple files can be selected.
- Returns:
str,listofstrorNone– The name(s) of the file(s) to open orNoneif the user cancelled the request.
- msl.qt.prompt.folder(*, title='Select Folder', directory=None)[source]¶
Request to select an existing folder or to create a new folder.
- msl.qt.prompt.information(message, *, title=None, font=None)[source]¶
Display an information message in a dialog window.
- Parameters:
message (
strorException) – The message to display. The message can use HTML/CSS markup, for example,'<html>The temperature is 21.3 °C</html>'title (
str, optional) – The text to display in the title bar of the dialog window. IfNonethen uses the text in the title bar of the active window.font (
int,str,tupleorQtGui.QFont, optional) – The font to use. If anintthen the point size, if astrthen the family name, if atuplethen the (family name, point size).
- msl.qt.prompt.integer(message, *, title=None, font=None, value=0, minimum=-2147483647, maximum=2147483647, step=1)[source]¶
Request an integer value.
- Parameters:
message (
str) – The message that is shown to the user to describe what the value represents. The message can use HTML/CSS markup, for example,'<html>Enter a mass, in μg</html>'title (
str, optional) – The text to display in the title bar of the dialog window. IfNonethen uses the text in the title bar of the active window.font (
int,str,tupleorQtGui.QFont, optional) – The font to use. If anintthen the point size, if astrthen the family name, if atuplethen the (family name, point size).value (
int, optional) – The initial value.minimum (
int, optional) – The minimum value that the user can enter.maximum (
int, optional) – The maximum value that the user can enter.step (
int, optional) – The step size by which the value is increased and decreased.
- Returns:
intorNone– The value orNoneif the user cancelled the request.
- msl.qt.prompt.item(message, items, *, title=None, font=None, index=0)[source]¶
Request an item from a list of items.
- Parameters:
message (
str) – The message that is shown to the user to describe what the list of items represent. The message can use HTML/CSS markup.items (
listortuple) – The list of items to choose from. The items can be of any data type.title (
str, optional) – The text to display in the title bar of the dialog window. IfNonethen uses the text in the title bar of the active window.font (
int,str,tupleorQtGui.QFont, optional) – The font to use. If anintthen the point size, if astrthen the family name, if atuplethen the (family name, point size).index (
int, optional) – The index of the initial item that is selected.
- Returns:
The selected item or
Noneif the user cancelled the request.
Notes
The data type of the selected item is preserved. For example, if items =
[1, 2.0, 2+3j, 'hello', b'world', True, QtWidgets.QPushButton]and the user selects the2+3jitem then acomplexdata type is returned.
- msl.qt.prompt.comments(*, path=None, title=None, even_row_color='#FFFFFF', odd_row_color='#EAF2F8')[source]¶
Ask the user to enter comments.
Opens a
QtWidgets.QDialogto allow for a user to enter comments about a task that they are performing. The dialog provides a table of all the previous comments that have been used. Comments that are in the table can be deleted by selecting the desired row(s) and pressing theDeletekey or the comment in a row can be selected by double-clicking on a row.This function is useful when acquiring data, and you want to include comments about how the data was acquired. Using a prompt to enter comments forces you to enter a new comment (or use a previous comment) every time you acquire data rather than having the comments in a for example,
QtWidgets.QPlainTextEdit, which you might forget to update before acquiring the next data set.- Parameters:
path (
str, optional) – The path to a JSON file that contains the history of the comments that have been used. IfNonethen the default file is used. The file will automatically be created if it does not exist.title (
str, optional) – The text to display in the title bar of the dialog window.even_row_color – The background color of the even-numbered rows in the history table. See
to_qcolor()for details about the different data types that are supported.odd_row_color – The background color of the odd-numbered rows in the history table. See
to_qcolor()for details about the different data types that are supported.
- Returns:
str– The comment that was entered.
- msl.qt.prompt.save(*, title='Save As', directory=None, filters=None, options=None)[source]¶
Request to enter the name of a file to save.
- Parameters:
title (
str, optional) – The text to display in the title bar of the dialog window.directory (
str, optional) – The initial directory to start in.filters (
str,listofstrordict, optional) –Only filenames that match the specified filters are shown.
Examples:
'Images (*.png *.xpm *.jpg)' 'Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)' ['Images (*.png *.xpm *.jpg)', 'Text files (*.txt)', 'XML files (*.xml)'] {'Images': ('*.png', '*.xpm', '*.jpg'), 'Text files': '*.txt'}
options (QtWidgets.QFileDialog.Option, optional) – Specify additional options on how to run the dialog.
- Returns:
strorNone– The name of the file to save orNoneif the user cancelled the request.
- msl.qt.prompt.text(message, *, title=None, font=None, value='', multi_line=False, echo=EchoMode.Normal)[source]¶
Request text.
- Parameters:
message (
str) – The message that is shown to the user to describe what the list of items represent. The message can use HTML/CSS markup.title (
str, optional) – The text to display in the title bar of the dialog window. IfNonethen uses the text in the title bar of the active window.font (
int,str,tupleorQtGui.QFont, optional) – The font to use. If anintthen the point size, if astrthen the family name, if atuplethen the (family name, point size).value (
str, optional) – The initial value.multi_line (
bool, optional) – Whether the entered text can span multiple lines.echo (
intor QLineEdit.EchoMode, optional) – The echo mode for the text value. Useful if requesting a password.
- Returns:
strorNone– The text that the user entered orNoneif the user cancelled the request.
- msl.qt.prompt.password(message, *, title=None, font=None)[source]¶
Request a password.
- Parameters:
message (
str) – The message that is shown to the user to describe what the list of items represent. The message can use HTML/CSS markup.title (
str, optional) – The text to display in the title bar of the dialog window. IfNonethen uses the text in the title bar of the active window.font (
int,str,tupleorQtGui.QFont, optional) – The font to use. If anintthen the point size, if astrthen the family name, if atuplethen the (family name, point size).
- Returns:
strorNone– The password orNoneif the user cancelled the request.
- msl.qt.prompt.warning(message, *, title=None, font=None)[source]¶
Display a warning message in a dialog window.
- Parameters:
message (
strorException) – The message to display. The message can use HTML/CSS markup, for example,'<html>A <p style="color:yellow">warning</p>...</html>'title (
str, optional) – The text to display in the title bar of the dialog window. IfNonethen uses the text in the title bar of the active window.font (
int,str,tupleorQtGui.QFont, optional) – The font to use. If anintthen the point size, if astrthen the family name, if atuplethen the (family name, point size).
- msl.qt.prompt.ok_cancel(message, *, title=None, font=None, default=True)[source]¶
Ask for a response to a message where the logical options are
OkorCancel.- Parameters:
message (
str) – The message to ask the user. The message can use HTML/CSS markup.title (
str, optional) – The text to display in the title bar of the dialog window. IfNonethen uses the text in the title bar of the active window.font (
int,str,tupleorQtGui.QFont, optional) – The font to use. If anintthen the point size, if astrthen the family name, if atuplethen the (family name, point size).default (
bool, optional) – The answer to be selected by default. IfTruethenOkis the default answer, otherwiseCancelis the default answer.
- Returns:
boolorNone–Trueif the user answeredOk,Noneif the user answeredCancel.
- msl.qt.prompt.yes_no(message, *, title=None, font=None, default=True)[source]¶
Ask for a response to a message where the logical options are
YesorNo.- Parameters:
message (
str) – The message to ask the user. The message can use HTML/CSS markup.title (
str, optional) – The text to display in the title bar of the dialog window. IfNonethen uses the text in the title bar of the active window.font (
int,str,tupleorQtGui.QFont, optional) – The font to use. If anintthen the point size, if astrthen the family name, if atuplethen the (family name, point size).default (
bool, optional) – The answer to be selected by default. IfTruethenYesis the default answer, otherwiseNois the default answer.
- Returns:
bool–Trueif the user answeredYes,Falseif the user answeredNo.
- msl.qt.prompt.yes_no_cancel(message, *, title=None, font=None, default=True)[source]¶
Ask for a response to a message where the logical options are
Yes,NoorCancel.- Parameters:
message (
str) – The message to ask the user. The message can use HTML/CSS markup.title (
str, optional) – The text to display in the title bar of the dialog window. IfNonethen uses the text in the title bar of the active window.font (
int,str,tupleorQtGui.QFont, optional) – The font to use. If anintthen the point size, if astrthen the family name, if atuplethen the (family name, point size).default (
bool, optional) – The answer to be selected by default. IfTruethenYesis the default answer, ifFalsethenNois the default answer, else ifNonethenCancelis the default answer.
- Returns:
boolorNone–Trueif the user answeredYes,Falseif the user answeredNo, orNoneif the user answeredCancel.