hamyar_paygah.utils.qt_utils¶
Utility functions related to Qt UI.
Attributes¶
Text to show when an information is not yet registered by EMS |
|
Functions¶
|
Set a checkbox state and enabled status. |
|
Set a text field with a value or disable it if empty/zero. |
|
Set a QLineEdit with the Persian label of a domain enum. |
|
Typed wrapper around qasync.asyncSlot. |
|
Display an error dialog with a critical icon. |
Module Contents¶
- hamyar_paygah.utils.qt_utils.NOT_REGISTERED_PERSIAN_TEXT: str = 'ثبت نشده'¶
Text to show when an information is not yet registered by EMS
- hamyar_paygah.utils.qt_utils.set_checkbox(checkbox, *, value)¶
Set a checkbox state and enabled status.
The checkbox is checked and enabled if
valueisTrue. IfvalueisFalse, the checkbox is unchecked and disabled.- Parameters:
checkbox (PySide6.QtWidgets.QCheckBox) – The QCheckBox instance to modify.
value (bool) – Determines both the checked state and whether the checkbox is enabled.
- Return type:
None
- hamyar_paygah.utils.qt_utils.set_textfield(textfield, value)¶
Set a text field with a value or disable it if empty/zero.
This function updates the text of a QLineEdit or QPlainTextEdit widget. - If value is None or zero (for integers), the field is disabled and filled with a placeholder text (NOT_REGISTERED_PERSIAN_TEXT). - Otherwise, the field is updated with str(value) and will be enabled.
- Parameters:
textfield (PySide6.QtWidgets.QLineEdit | PySide6.QtWidgets.QPlainTextEdit) – A QLineEdit or QPlainTextEdit widget to update.
value (int | str | datetime.timedelta | datetime.time | jdatetime.date | None) – The value to set. Can be int, str, timedelta, time, jdatetime.date, or None. Integers equal to zero are treated as empty.
- Returns:
None
- Return type:
None
Notes
This function is designed to handle various types safely.
NOT_REGISTERED_PERSIAN_TEXT is used as a placeholder for missing values.
- hamyar_paygah.utils.qt_utils.set_enum_textfield(textfield, enum_value)¶
Set a QLineEdit with the Persian label of a domain enum.
If enum_value is None, the text field is populated with NOT_REGISTERED_PERSIAN_TEXT and disabled.
If a valid enum value is provided, its persian_label attribute is displayed and the field is enabled.
- Parameters:
textfield (PySide6.QtWidgets.QLineEdit) – The QLineEdit widget to update.
enum_value (hamyar_paygah.models.mission_details_submodels.mission_result_model.MissionOutcome | hamyar_paygah.models.mission_details_submodels.location_and_emergency_model.LocationType | hamyar_paygah.models.mission_details_submodels.location_and_emergency_model.AccidentType | hamyar_paygah.models.mission_details_submodels.location_and_emergency_model.IllnessType | hamyar_paygah.models.mission_details_submodels.location_and_emergency_model.InjuryRole | hamyar_paygah.models.mission_details_submodels.location_and_emergency_model.VehicleType | hamyar_paygah.models.mission_details_submodels.pupils_lungs_heart_model.PupilStatus | hamyar_paygah.models.mission_details_submodels.pupils_lungs_heart_model.LungSound | hamyar_paygah.models.mission_details_submodels.pupils_lungs_heart_model.BreathingRhythm | hamyar_paygah.models.mission_details_submodels.pupils_lungs_heart_model.HeartSound | hamyar_paygah.models.mission_details_submodels.pupils_lungs_heart_model.HeartRhythm | hamyar_paygah.models.mission_details_submodels.trauma_types_model.PatientExtrication | hamyar_paygah.models.mission_details_submodels.trauma_types_model.FractureType | hamyar_paygah.models.mission_details_submodels.trauma_types_model.DistalPulseStatus | None) – A supported domain enum instance or None.
- Returns:
None
- Return type:
None
- hamyar_paygah.utils.qt_utils.F¶
- hamyar_paygah.utils.qt_utils.typed_async_slot(*args, **kwargs)¶
Typed wrapper around qasync.asyncSlot.
Provides proper type hints for the untyped
asyncSlotdecorator from theqasyncmodule. This allows static type checkers such as mypy or Pyright to correctly infer the signature of decorated async functions.- Parameters:
*args (Any) – Positional arguments forwarded to
asyncSlot.**kwargs (Any) – Keyword arguments forwarded to
asyncSlot.
- Returns:
A decorator that preserves the type signature of the async function it decorates.
- Return type:
- hamyar_paygah.utils.qt_utils.show_error_dialog(parent, title, message)¶
Display an error dialog with a critical icon.
This function creates a modal error dialog attached to the given parent widget. The dialog displays a title and a message to inform the user of an error. Execution is blocked until the user closes the dialog.
- Parameters:
parent (PySide6.QtWidgets.QWidget) – The parent widget for the dialog. The dialog will be centered on this widget.
title (str) – The title displayed in the window’s title bar.
message (str) – The error message to display in the dialog body.
- Returns:
None
- Return type:
None
Notes
This function uses a modal dialog; it will block interaction with other windows until closed.
For non-blocking dialogs, consider using dialog.show() instead of dialog.exec().