Line data Source code
1 : # SPDX-FileCopyrightText: 2025 PairInteraction Developers
2 : # SPDX-License-Identifier: LGPL-3.0-or-later
3 1 : from __future__ import annotations
4 :
5 1 : from functools import partial
6 1 : from typing import TYPE_CHECKING
7 :
8 1 : from PySide6.QtCore import QTimer
9 1 : from PySide6.QtGui import QStatusTipEvent
10 1 : from PySide6.QtWidgets import QApplication
11 :
12 : if TYPE_CHECKING:
13 : import logging
14 :
15 : from PySide6.QtCore import QObject
16 :
17 :
18 1 : def show_status_tip(parent: QObject, message: str, timeout: int = 0, logger: logging.Logger | None = None) -> None:
19 : """Show a status tip message using QStatusTipEvent."""
20 1 : QApplication.sendEvent(parent, QStatusTipEvent(message))
21 1 : if logger:
22 1 : logger.info(message)
23 1 : if timeout > 0:
24 1 : QTimer.singleShot(timeout, partial(reset_status_tip, parent))
25 :
26 :
27 1 : def reset_status_tip(parent: QObject) -> None:
28 : """Hide the status tip by sending an empty message."""
29 1 : QApplication.sendEvent(parent, QStatusTipEvent("Ready"))
|