|
| 1 | +MessageBox |
| 2 | +========== |
| 3 | + |
| 4 | +Convenience wrapper to display message boxes and a simple |
| 5 | +text input dialog from Python scripts using the ``moldflow`` package. |
| 6 | + |
| 7 | +Usage |
| 8 | +----- |
| 9 | + |
| 10 | +.. code-block:: python |
| 11 | +
|
| 12 | + from moldflow import ( |
| 13 | + MessageBox, |
| 14 | + MessageBoxType, |
| 15 | + MessageBoxResult, |
| 16 | + MessageBoxOptions, |
| 17 | + MessageBoxIcon, |
| 18 | + MessageBoxDefaultButton, |
| 19 | + MessageBoxModality, |
| 20 | + ) |
| 21 | +
|
| 22 | + # Informational message |
| 23 | + MessageBox("Operation completed.", MessageBoxType.INFO).show() |
| 24 | +
|
| 25 | + # Confirmation |
| 26 | + result = MessageBox("Proceed with analysis?", MessageBoxType.YES_NO).show() |
| 27 | + if result == MessageBoxResult.YES: |
| 28 | + pass |
| 29 | +
|
| 30 | + # Text input |
| 31 | + material_id = MessageBox("Enter your material ID:", MessageBoxType.INPUT).show() |
| 32 | + if material_id: |
| 33 | + pass |
| 34 | +
|
| 35 | + # Advanced options |
| 36 | + opts = MessageBoxOptions( |
| 37 | + icon=MessageBoxIcon.WARNING, |
| 38 | + default_button=MessageBoxDefaultButton.BUTTON2, |
| 39 | + modality=MessageBoxModality.TASK, |
| 40 | + topmost=True, |
| 41 | + right_align=False, |
| 42 | + rtl_reading=False, |
| 43 | + help_button=False, |
| 44 | + set_foreground=True, |
| 45 | + owner_hwnd=None, |
| 46 | + ) |
| 47 | + result = MessageBox( |
| 48 | + "Retry failed operation?", |
| 49 | + MessageBoxType.RETRY_CANCEL, |
| 50 | + title="Moldflow", |
| 51 | + options=opts, |
| 52 | + ).show() |
| 53 | +
|
| 54 | +Convenience methods |
| 55 | +------------------- |
| 56 | + |
| 57 | +.. code-block:: python |
| 58 | +
|
| 59 | + MessageBox.info("Saved") |
| 60 | + MessageBox.warning("Low disk space") |
| 61 | + MessageBox.error("Failed to save") |
| 62 | + if MessageBox.confirm_yes_no("Proceed?") == MessageBoxResult.YES: |
| 63 | + pass |
| 64 | +
|
| 65 | + # Prompt text with validation |
| 66 | + def is_nonempty(s: str) -> bool: |
| 67 | + return bool(s.strip()) |
| 68 | +
|
| 69 | + value = MessageBox.prompt_text( |
| 70 | + "Enter ID:", |
| 71 | + default_text="", |
| 72 | + placeholder="e.g. MAT-123", |
| 73 | + validator=is_nonempty, |
| 74 | + ) |
| 75 | + if value is not None: |
| 76 | + pass |
| 77 | +
|
| 78 | +Options |
| 79 | +------- |
| 80 | + |
| 81 | +.. list-table:: MessageBoxOptions |
| 82 | + :header-rows: 1 |
| 83 | + |
| 84 | + * - Parameter |
| 85 | + - Type |
| 86 | + - Description |
| 87 | + * - icon |
| 88 | + - MessageBoxIcon | None |
| 89 | + - Override default icon |
| 90 | + * - default_button |
| 91 | + - MessageBoxDefaultButton | None |
| 92 | + - Set default button (2/3/4). Validated vs type |
| 93 | + * - modality |
| 94 | + - MessageBoxModality | None |
| 95 | + - Application (default), Task-modal, System-modal |
| 96 | + * - topmost |
| 97 | + - bool |
| 98 | + - Keep message box on top (standard MessageBox only) |
| 99 | + * - set_foreground |
| 100 | + - bool |
| 101 | + - Force foreground (standard MessageBox only) |
| 102 | + * - right_align / rtl_reading |
| 103 | + - bool |
| 104 | + - Layout flags for right-to-left locales (standard MessageBox only) |
| 105 | + * - help_button |
| 106 | + - bool |
| 107 | + - Show Help button |
| 108 | + * - owner_hwnd |
| 109 | + - int | None |
| 110 | + - Owner window handle (standard MessageBox only, improves modality/Z-order) |
| 111 | + * - default_text / placeholder |
| 112 | + - str | None |
| 113 | + - Prefill text and cue banner for input dialog |
| 114 | + * - is_password |
| 115 | + - bool |
| 116 | + - Mask input characters |
| 117 | + * - char_limit |
| 118 | + - int | None |
| 119 | + - Maximum characters accepted (client-side) |
| 120 | + * - width_dlu / height_dlu |
| 121 | + - int | None |
| 122 | + - Size the input dialog (pixels; DLUs in legacy template path) |
| 123 | + * - validator |
| 124 | + - Callable[[str], bool] | None |
| 125 | + - Enable OK only when input satisfies predicate |
| 126 | + * - font_face / font_size_pt |
| 127 | + - str / int |
| 128 | + - Font for legacy template; CreateWindowEx path uses system dialog font |
| 129 | + |
| 130 | +API |
| 131 | +--- |
| 132 | + |
| 133 | +.. automodule:: moldflow.message_box |
| 134 | + |
| 135 | +Notes |
| 136 | +----- |
| 137 | + |
| 138 | +- Localization: action button captions (e.g., "OK", "Cancel", "Submit") are localized via the package i18n system. Title and prompt are not localized automatically. |
| 139 | +- Return type: ``MessageBox.show()`` returns ``MessageBoxReturn`` (``MessageBoxResult | str | None``). |
0 commit comments