Skip to content
Extraits de code Groupes Projets
module.py 2,29 ko
Newer Older
  • Learn to ignore specific revisions
  • Simon Collignon's avatar
    Simon Collignon a validé
    import numpy as np
    import pyqtgraph as pg
    
    from PySide6.QtWidgets import QWidget, QSizePolicy
    from PySide6.QtGui import QLinearGradient, QBrush, QColor
    
    from app.ui.dist.ui_module import Ui_module
    
    
    class Module(QWidget, Ui_module):
        """Handles all the post-processing settings of an `experiment` object."""
    
        def __init__(self):
            super().__init__()
            self.setupUi(self)
    
            self.graph = Graph()
            self.graph.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
            self.graph.setFixedSize(500, 200)
            view_box = self.graph.getViewBox()
            # Disable mouse interactivity (zoom, pan)
            view_box.setMouseEnabled(x=False, y=False)
            # view_box.setInteractive(False)
            
            data_count = 100
            self.x = np.arange(data_count) 
            self.y = np.zeros(data_count) 
            y2 = np.zeros(data_count) 
            self.curve = self.graph.plot(self.x, self.y, pen=pg.mkPen(QColor(237, 240, 96), width=2))
            curve2 = self.graph.plot(self.x, y2, pen=pg.mkPen(QColor(0, 0, 255, 0), width=0))
    
            # Create a gradient brush
            gradient = QLinearGradient(0, 0, 0, 1)
            gradient.setCoordinateMode(QLinearGradient.ObjectBoundingMode)
            gradient.setColorAt(0, QColor(237, 240, 96, 10))  # Blue at the bottom, semi-transparent
            gradient.setColorAt(1, QColor(237, 240, 96, 100))    # Transparent at the top
            brush = QBrush(gradient)
    
            # Fill the area under the curve with the gradient brush
            fill = pg.FillBetweenItem(self.curve, curve2, brush=brush)
            self.graph.addItem(fill)
            self.graph.showGrid(x=True, y=True, alpha=0.3)
            self.graph.getPlotItem().hideAxis('bottom')
            self.graph_layout.addWidget(self.graph)
    
    
        def update_plot_data(self, new_y):
            # Update y data with a new sine wave that changes over time
            self.y[:-1] = self.y[1:]
            self.y[-1] = new_y
            self.curve.setData(self.x, self.y)
    
    
    class Graph(pg.PlotWidget):
        """Handles all the post-processing settings of an `experiment` object."""
    
        def __init__(self, parent=None):
            super(Graph, self).__init__(parent)
            self.setBackground("#2c2e36")
            self.color_white = '#f2f2f2'
            self.pen = pg.mkPen(color="#EDF060", width=1)
            self.label_styles = {'color':'#a2a2a2', 'font-size':'14px'}