dylab/HelperClasses/Plotting/WidgetPlot.py

60 lines
1.8 KiB
Python
Raw Normal View History

2022-07-30 21:50:53 +02:00
import pyqtgraph as pg
from pyqtgraph import Qt
from pyqtgraph.Qt import QtCore, QtGui
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from .DataExtractorLyse import DataExtractorManager
2022-08-09 15:37:34 +02:00
class WidgetPlot(QSplitter):
2022-07-30 21:50:53 +02:00
def __init__(self, title, **kwargs):
super().__init__(**kwargs)
# Orientation of plot and title (and other information)
self.setOrientation(Qt.Vertical)
2022-08-09 15:37:34 +02:00
# Add title
self.title = QtGui.QLabel()
self.title.setAlignment(QtCore.Qt.AlignCenter)
self.title.setText('<h2>' + title + ' <\h2>')
self.addWidget(self.title)
2022-07-30 21:50:53 +02:00
# Claim bottom part (title)
self.bottom = QSplitter()
2022-08-09 15:37:34 +02:00
self.bottom.setOrientation(Qt.Vertical)
2022-07-30 21:50:53 +02:00
self.addWidget(self.bottom)
2022-08-09 15:37:34 +02:00
# Add plot
self.plots = pg.GraphicsLayoutWidget()
self.bottom.addWidget(self.plots)
2022-07-30 21:50:53 +02:00
# Add warning information
2022-08-09 15:37:34 +02:00
self.desciption = pg.LayoutWidget()
2022-07-30 21:50:53 +02:00
self.warning = QtGui.QLabel()
self.warning.setAlignment(QtCore.Qt.AlignCenter)
self.desciption.nextRow()
self.desciption.addWidget(self.warning)
2022-08-09 15:37:34 +02:00
# self.bottom.addWidget(self.desciption)
2022-07-30 21:50:53 +02:00
# Current hdf5 file path
self.h5_path_shown = None
# data extractor
self.data_extractor_manager = DataExtractorManager()
def update_from_h5(self, h5_path):
if self.h5_path_shown != h5_path or self.data_extractor_manager.local_data_changed:
self.h5_path_shown = h5_path
self.update(h5_path)
def update_warning(self, warning):
if warning == '':
self.warning.setStyleSheet("background-color: lightgreen")
warning = 'all good'
else:
self.warning.setStyleSheet("background-color: red")
self.warning.setText(warning)