modbus_test/gui/observable.py

22 lines
970 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from PyQt6.QtCore import pyqtSignal, QObject, QTimer
from logger import logger
class Observable(QObject):
value_changed = pyqtSignal(object) # Сигнал с переданным значением
def __init__(self, func, interval=1000):
super().__init__()
self.get_dynamic_value = func
self._value = None
# Таймер для периодической проверки значения
self.timer = QTimer(self)
self.timer.timeout.connect(self.check_function) # Вызываем some_function на каждом таймере
self.timer.start(interval) # Интервал в миллисекундах
def check_function(self):
# Пример функции, которая обновляет значение
new_value = self.get_dynamic_value()
if new_value != self._value:
self._value = new_value
self.value_changed.emit(new_value)