dylab/HelperClasses/Plotting/MainPlotPanel.py

113 lines
3.8 KiB
Python
Raw Normal View History

2022-07-30 21:50:53 +02:00
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
from pyqtgraph.dockarea import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import lyse
2022-08-09 15:37:34 +02:00
from .WidgetDataSelector import WidgetDataSelector
from .WidgetAnalysePanel import WidgetAnalysePanel
2022-07-30 21:50:53 +02:00
class MainPlotPanel(QtGui.QMainWindow):
def __init__(self, h5_paths, n_rows=3, **kwargs):
self.h5_paths = h5_paths
super().__init__(**kwargs)
pg.mkQApp()
self.n_rows = n_rows
self.setWindowFlag(QtCore.Qt.WindowCloseButtonHint, False)
self.area = DockArea()
self.setCentralWidget(self.area)
2022-08-09 15:37:34 +02:00
self.resize(900, 500)
2022-07-30 21:50:53 +02:00
self.dshotselector = Dock("Shot selector")
2022-08-09 15:37:34 +02:00
self.shotselector = WidgetDataSelector()
self.dshotselector.setFixedSize(400, 150)
2022-07-30 21:50:53 +02:00
self.dshotselector.addWidget(self.shotselector)
2022-08-09 15:37:34 +02:00
self.area.addDock(self.dshotselector, 'left')
2022-07-30 21:50:53 +02:00
# self.qpg_dock = Dock("Quick Plot Generator")
# self.qpg_dock.addWidget(QuickPlotGenerator(self))
# self.qpg_dock.setMinimumSize(self.qpg_dock.minimumSizeHint())
# self.area.addDock(self.qpg_dock)
2022-08-09 15:37:34 +02:00
self.danalyse_panel = Dock("Analyse and Fitting")
self.analyse_panel = WidgetAnalysePanel()
self.danalyse_panel.addWidget(self.analyse_panel)
self.area.addDock(self.danalyse_panel, 'bottom')
2022-07-30 21:50:53 +02:00
self.show()
self.plots = {}
self.shotselector.valueChanged.connect(self.refresh)
self.shotselector.selectionChanged.connect(self.refresh)
self.df = lyse.data()
2022-08-09 15:37:34 +02:00
def add_plot_dock(self, plot_name, plot_widget, overlap=True, **kwargs):
2022-07-30 21:50:53 +02:00
if plot_name not in self.plots:
plot_widget.plot_name = plot_name
dock = Dock(plot_name, **kwargs)
dock.sigClosed.connect(self.remove_plot)
dock.addWidget(plot_widget)
2022-08-09 15:37:34 +02:00
if overlap and len(self.plots):
self.area.addDock(dock, 'above', relativeTo=self.area.docks[list(self.plots.keys())[-1]])
elif len(self.plots):
2022-07-30 21:50:53 +02:00
if len(self.plots) % self.n_rows == 2:
position = 'right'
self.area.addDock(dock, position)
if len(self.plots) % (self.n_rows * 2) in [0, 1]:
position = 'bottom'
self.area.addDock(dock, position, relativeTo=self.area.docks[list(self.plots.keys())[-1]])
if len(self.plots) % (self.n_rows * 2) in [3, 4]:
position = 'top'
self.area.addDock(dock, position, relativeTo=self.area.docks[list(self.plots.keys())[-1]])
print(len(self.plots) % (self.n_rows * 2), len(self.plots) % self.n_rows)
else:
self.area.addDock(dock, 'right')
self.plots[plot_name] = plot_widget
else:
print(f'Plot {plot_name} already exists. Please choose different name.')
def remove_plot(self, dock):
del self.plots[dock.title()]
def update_h5_paths(self, h5_paths):
self.h5_paths = h5_paths
self.shotselector.update_nshots(len(h5_paths))
for plot_name in self.plots:
self.plots[plot_name].data_extractor_manager.clean_memory(h5_paths)
def refresh(self, h5_path=None):
if len(self.h5_paths):
self.h5_paths_selected = self.h5_paths.iloc[self.shotselector.get_selected_indices()]
if h5_path == None:
i = self.shotselector.get_current_index()
h5_path = self.h5_paths.iloc[i]
for plot_name in self.plots:
self.plots[plot_name].data_extractor_manager.update_local_data(h5_path)
# self.data_extractor_manager.update_local_data(h5_path)
for plot_name, plot in self.plots.items():
plot.update_from_h5(h5_path)
else:
pass