Skip to content
Snippets Groups Projects
Commit c4162041 authored by esarrey's avatar esarrey
Browse files

Test asynch

parent 010e38f4
No related branches found
No related tags found
No related merge requests found
test.py 0 → 100644
import sys
import time
import random
from PyQt5.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
from PyQt5.QtCore import QThread, pyqtSignal
class SensorThread(QThread):
sensor_data_signal = pyqtSignal(float)
def __init__(self):
super().__init__()
def run(self):
while True:
time.sleep(0.1)
# Here, replace this with actual sensor data
sensor_data = random.uniform(0, 100) # Simulating sensor data with random values
self.sensor_data_signal.emit(sensor_data)
class SensorWidget(QWidget):
def __init__(self):
super().__init__()
self.sensor_value_label = QLabel('Waiting for sensor data...', self)
self.layout = QVBoxLayout(self)
self.layout.addWidget(self.sensor_value_label)
self.sensor_thread = SensorThread()
self.sensor_thread.sensor_data_signal.connect(self.update_sensor_value)
self.sensor_thread.start()
def update_sensor_value(self, sensor_value):
self.sensor_value_label.setText(f'Sensor value: {sensor_value:.2f}')
def main():
app = QApplication(sys.argv)
sensor_widget = SensorWidget()
sensor_widget.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment