Skip to content

Commit

Permalink
✨ Add real time plot render
Browse files Browse the repository at this point in the history
  • Loading branch information
NoaSecond committed May 31, 2024
1 parent 3d43e63 commit 09b0f49
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 7 deletions.
35 changes: 32 additions & 3 deletions GUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTabWidget" name="tabWidget">
<property name="enabled">
Expand All @@ -22,15 +25,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>1920</width>
<height>1080</height>
<width>1891</width>
<height>821</height>
</rect>
</property>
<property name="tabShape">
<enum>QTabWidget::TabShape::Rounded</enum>
</property>
<property name="currentIndex">
<number>6</number>
<number>4</number>
</property>
<property name="tabsClosable">
<bool>false</bool>
Expand Down Expand Up @@ -200,6 +203,19 @@
</property>
</widget>
</widget>
<widget class="QListWidget" name="listWidget_magnet">
<property name="geometry">
<rect>
<x>20</x>
<y>180</y>
<width>1221</width>
<height>521</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Shape::Box</enum>
</property>
</widget>
</widget>
<widget class="QWidget" name="RF">
<attribute name="title">
Expand Down Expand Up @@ -981,6 +997,19 @@
</property>
</widget>
</widget>
<widget class="QListWidget" name="listWidget_vacuum">
<property name="geometry">
<rect>
<x>20</x>
<y>250</y>
<width>1221</width>
<height>521</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Shape::Box</enum>
</property>
</widget>
</widget>
<widget class="QWidget" name="Eau">
<attribute name="title">
Expand Down
13 changes: 11 additions & 2 deletions GUI_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(1920, 1080)
MainWindow.setAutoFillBackground(False)
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.tabWidget = QTabWidget(self.centralwidget)
self.tabWidget.setObjectName(u"tabWidget")
self.tabWidget.setEnabled(True)
self.tabWidget.setGeometry(QRect(0, 0, 1920, 1080))
self.tabWidget.setGeometry(QRect(0, 0, 1891, 821))
self.tabWidget.setTabShape(QTabWidget.TabShape.Rounded)
self.tabWidget.setTabsClosable(False)
self.tabWidget.setTabBarAutoHide(False)
Expand Down Expand Up @@ -82,6 +83,10 @@ def setupUi(self, MainWindow):
self.label_3 = QLabel(self.Container_2)
self.label_3.setObjectName(u"label_3")
self.label_3.setGeometry(QRect(0, 0, 161, 16))
self.listWidget_magnet = QListWidget(self.Aimant)
self.listWidget_magnet.setObjectName(u"listWidget_magnet")
self.listWidget_magnet.setGeometry(QRect(20, 180, 1221, 521))
self.listWidget_magnet.setFrameShape(QFrame.Shape.Box)
self.tabWidget.addTab(self.Aimant, "")
self.RF = QWidget()
self.RF.setObjectName(u"RF")
Expand Down Expand Up @@ -299,6 +304,10 @@ def setupUi(self, MainWindow):
self.label_54 = QLabel(self.Container_9)
self.label_54.setObjectName(u"label_54")
self.label_54.setGeometry(QRect(0, 0, 161, 16))
self.listWidget_vacuum = QListWidget(self.Vide)
self.listWidget_vacuum.setObjectName(u"listWidget_vacuum")
self.listWidget_vacuum.setGeometry(QRect(20, 250, 1221, 521))
self.listWidget_vacuum.setFrameShape(QFrame.Shape.Box)
self.tabWidget.addTab(self.Vide, "")
self.Eau = QWidget()
self.Eau.setObjectName(u"Eau")
Expand Down Expand Up @@ -397,7 +406,7 @@ def setupUi(self, MainWindow):

self.retranslateUi(MainWindow)

self.tabWidget.setCurrentIndex(6)
self.tabWidget.setCurrentIndex(4)


QMetaObject.connectSlotsByName(MainWindow)
Expand Down
26 changes: 24 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from scripts.settings import Settings
from scripts.logger import log_values, log_action
from scripts.devicesLink import list_all_devices
import scripts.realTimePlot as realTimePlot


def loadUiWidget(uifilename, parent=None):
Expand Down Expand Up @@ -151,7 +152,8 @@ def refresh_ports():
# Resize tabWidget to screen size in width and 95% of screen size in height
tabWidget = MainWindow.findChild(QtWidgets.QTabWidget, "tabWidget")
tabWidget.resize(QtWidgets.QApplication.primaryScreen().availableSize())
tabWidget.resize(MainWindow.width(), int(QtWidgets.QApplication.primaryScreen().availableSize().height() * 0.95))
tabWidget.resize(MainWindow.width(), int(
QtWidgets.QApplication.primaryScreen().availableSize().height() * 0.95))

# Settings
settings = Settings()
Expand All @@ -164,10 +166,10 @@ def refresh_ports():
QtWidgets.QSpinBox, "spinBox_logFrequency")
logFrequencyInMB = spinBox_logFrequency.value() * 1000
timer.setInterval(logFrequencyInMB)
values_to_log = [1, 2, 3]
spinBox_fileSizeLimit = MainWindow.findChild(
QtWidgets.QSpinBox, "spinBox_fileSizeLimit")
fileSizeLimit = spinBox_fileSizeLimit.value()
values_to_log = [1, 2, 3]
timer.timeout.connect(log_values(values_to_log, fileSizeLimit))
timer.start()

Expand All @@ -177,5 +179,25 @@ def refresh_ports():
QtWidgets.QPushButton, "pushButton_Refresh")
pushButton_Refresh.clicked.connect(refresh_ports)

# realTimePlot
# Vacuum pump
plot1 = realTimePlot.RealTimePlot()
plot1.start_animation()
figure = plot1.figure
listWidget_vacuum = MainWindow.findChild(QtWidgets.QListWidget, "listWidget_vacuum")
item = QtWidgets.QListWidgetItem()
item.setSizeHint(QtCore.QSize(0, 500))
listWidget_vacuum.addItem(item)
listWidget_vacuum.setItemWidget(item, figure.canvas)
# Magnet
plot2 = realTimePlot.RealTimePlot()
plot2.start_animation()
figure = plot2.figure
listWidget_magnet = MainWindow.findChild(QtWidgets.QListWidget, "listWidget_magnet")
item = QtWidgets.QListWidgetItem()
item.setSizeHint(QtCore.QSize(0, 500))
listWidget_magnet.addItem(item)
listWidget_magnet.setItemWidget(item, figure.canvas)

sys.exit(app.exec())
# Développé avec ❤️ par : www.noasecond.com.
33 changes: 33 additions & 0 deletions scripts/realTimePlot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from datetime import datetime
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
from random import randrange
from PyQt5 import QtWidgets

class RealTimePlot:
def __init__(self):
self.x_data, self.y_data = [], []
self.figure, self.ax = plt.subplots()
self.line, = self.ax.plot_date(self.x_data, self.y_data, '-')
self.animation = None # Keep a reference to the animation object

def update(self, frame):
if not self.x_data:
self.x_data.append(0)
else:
self.x_data.append(self.x_data[-1] + 1)
self.y_data.append(randrange(0, 10))
self.line.set_data(self.x_data, self.y_data)
self.ax.relim()
self.ax.autoscale_view()
return self.line,

def start_animation(self, interval=200):
self.animation = FuncAnimation(self.figure, self.update, interval=interval, cache_frame_data=False)
# plt.show() # Ensure the plot window is shown

def add_plot(self, MainWindow, widget_name):
widget = MainWindow.findChild(QtWidgets.QWidget, widget_name)
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.figure.canvas)
widget.setLayout(layout)

0 comments on commit 09b0f49

Please sign in to comment.