MessageBox#
Convenience wrapper to display message boxes and a simple
text input dialog from Python scripts using the moldflow package.
Usage#
from moldflow import (
MessageBox,
MessageBoxType,
MessageBoxResult,
MessageBoxOptions,
MessageBoxIcon,
MessageBoxDefaultButton,
MessageBoxModality,
)
# Informational message
MessageBox("Operation completed.", MessageBoxType.INFO).show()
# Confirmation
result = MessageBox("Proceed with analysis?", MessageBoxType.YES_NO).show()
if result == MessageBoxResult.YES:
pass
# Text input
material_id = MessageBox("Enter your material ID:", MessageBoxType.INPUT).show()
if material_id:
pass
# Advanced options
opts = MessageBoxOptions(
icon=MessageBoxIcon.WARNING,
default_button=MessageBoxDefaultButton.BUTTON2,
modality=MessageBoxModality.TASK,
topmost=True,
right_align=False,
rtl_reading=False,
help_button=False,
set_foreground=True,
owner_hwnd=None,
)
result = MessageBox(
"Retry failed operation?",
MessageBoxType.RETRY_CANCEL,
title="Moldflow",
options=opts,
).show()
Convenience methods#
MessageBox.info("Saved")
MessageBox.warning("Low disk space")
MessageBox.error("Failed to save")
if MessageBox.confirm_yes_no("Proceed?") == MessageBoxResult.YES:
pass
# Prompt text with validation
def is_nonempty(s: str) -> bool:
return bool(s.strip())
value = MessageBox.prompt_text(
"Enter ID:",
default_text="",
placeholder="e.g. MAT-123",
validator=is_nonempty,
)
if value is not None:
pass
Options#
Parameter |
Type |
Description |
|---|---|---|
icon |
MessageBoxIcon | None |
Override default icon |
default_button |
MessageBoxDefaultButton | None |
Set default button (2/3/4). Validated vs type |
modality |
MessageBoxModality | None |
Application (default), Task-modal, System-modal |
topmost |
bool |
Keep message box on top (standard MessageBox only) |
set_foreground |
bool |
Force foreground (standard MessageBox only) |
right_align / rtl_reading |
bool |
Layout flags for right-to-left locales (standard MessageBox only) |
help_button |
bool |
Show Help button |
owner_hwnd |
int | None |
Owner window handle (standard MessageBox only, improves modality/Z-order) |
default_text / placeholder |
str | None |
Prefill text and cue banner for input dialog |
is_password |
bool |
Mask input characters |
char_limit |
int | None |
Maximum characters accepted (client-side) |
width_dlu / height_dlu |
int | None |
Size the input dialog (pixels; DLUs in legacy template path) |
validator |
Callable[[str], bool] | None |
Enable OK only when input satisfies predicate |
font_face / font_size_pt |
str / int |
Font for legacy template; CreateWindowEx path uses system dialog font |
API#
MessageBox convenience wrapper for Moldflow scripts.
Provides simple info/warning/error dialogs, confirmation prompts, and a text input dialog. Uses Win32 MessageBox for standard dialogs and a lightweight custom Win32 dialog (ctypes) for text input.
- class MessageBox[source]#
Bases:
objectMessageBox convenience class.
Example
from moldflow import MessageBox, MessageBoxType # Information message MessageBox("Operation completed.", MessageBoxType.INFO).show() # Yes/No prompt result = MessageBox("Proceed with analysis?", MessageBoxType.YES_NO).show() if result == MessageBoxResult.YES: ... # Text input material_id = MessageBox("Enter your material ID:", MessageBoxType.INPUT).show() if material_id: ...
- classmethod confirm_yes_no(text, title=None, options=None)[source]#
Show a confirmation message box with Yes/No buttons.
- Return type:
- classmethod error(text, title=None, options=None)[source]#
Show an error message box with an OK button.
- Return type:
- classmethod info(text, title=None, options=None)[source]#
Show an informational message box with an OK button.
- Return type:
- classmethod prompt_text(prompt, title=None, default_text=None, placeholder=None, validator=None, options=None)[source]#
Show a text input dialog.
- Return type:
Optional[str]
- show()[source]#
Show the message box.
- Return type:
Union[MessageBoxResult,str,None]- Returns:
MessageBoxResult for INFO/WARNING/ERROR/YES_NO/OK_CANCEL
str | None for INPUT (user-entered text or None if cancelled)
- class MessageBoxDefaultButton[source]#
Bases:
EnumWhich button is the default (activated by Enter).
- BUTTON1 = 1#
- BUTTON2 = 2#
- BUTTON3 = 3#
- BUTTON4 = 4#
- class MessageBoxIcon[source]#
Bases:
EnumIcon to display on the message box. If not provided, a sensible default is chosen based on the MessageBoxType.
- ERROR = 4#
- INFORMATION = 2#
- NONE = 1#
- QUESTION = 5#
- WARNING = 3#
- class MessageBoxModality[source]#
Bases:
EnumModality for the message box window.
- APPLICATION = 1#
- SYSTEM = 2#
- TASK = 3#
- class MessageBoxOptions[source]#
Bases:
objectOptional advanced options for MessageBox.
icon: Overrides the default icon
default_button: Choose default button (2/3/4). BUTTON1 is implicit default
topmost: Keep message box on top of other windows
modality: Application (default), Task-modal, or System-modal
rtl_reading: Use right-to-left reading order
right_align: Right align the message text
help_button: Show a Help button
set_foreground: Force the message box to the foreground
-
char_limit:
Optional[int] = None#
-
default_button:
Optional[MessageBoxDefaultButton] = None#
-
default_text:
Optional[str] = None#
-
font_face:
str= 'Segoe UI'#
-
font_size_pt:
int= 9#
-
height_dlu:
Optional[int] = None#
-
help_button:
bool= False#
-
icon:
Optional[MessageBoxIcon] = None#
-
is_password:
bool= False#
-
modality:
Optional[MessageBoxModality] = None#
-
owner_hwnd:
Optional[int] = None#
-
placeholder:
Optional[str] = None#
-
right_align:
bool= False#
-
rtl_reading:
bool= False#
-
set_foreground:
bool= False#
-
topmost:
bool= False#
-
validator:
Optional[Callable[[str],bool]] = None#
-
width_dlu:
Optional[int] = None#
- class MessageBoxResult[source]#
Bases:
EnumResult of a message box interaction.
For INPUT type, the MessageBox.show() method returns a string rather than a MessageBoxResult. For other types, it returns one of these values.
- ABORT = 6#
- CANCEL = 2#
- CONTINUE = 9#
- IGNORE = 7#
- NO = 4#
- OK = 1#
- RETRY = 5#
- TRY_AGAIN = 8#
- YES = 3#
- class MessageBoxType[source]#
Bases:
EnumMessage box types supported by the convenience API.
INFO: Informational message with OK button
WARNING: Warning message with OK button
ERROR: Error message with OK button
YES_NO: Confirmation dialog with Yes/No buttons
YES_NO_CANCEL: Confirmation dialog with Yes/No/Cancel buttons
OK_CANCEL: Prompt with OK/Cancel buttons
RETRY_CANCEL: Prompt with Retry/Cancel buttons
ABORT_RETRY_IGNORE: Prompt with Abort/Retry/Ignore buttons
CANCEL_TRY_CONTINUE: Prompt with Cancel/Try Again/Continue buttons
INPUT: Text input dialog returning a string
- ABORT_RETRY_IGNORE = 8#
- CANCEL_TRY_CONTINUE = 9#
- ERROR = 3#
- INFO = 1#
- INPUT = 10#
- OK_CANCEL = 6#
- RETRY_CANCEL = 7#
- WARNING = 2#
- YES_NO = 4#
- YES_NO_CANCEL = 5#
Notes#
Localization: action button captions (e.g., “OK”, “Cancel”, “Submit”) are localized via the package i18n system. Title and prompt are not localized automatically.
Return type:
MessageBox.show()returnsMessageBoxReturn(MessageBoxResult | str | None).