-
Notifications
You must be signed in to change notification settings - Fork 0
/
HistogramWindow.py
94 lines (76 loc) · 3.31 KB
/
HistogramWindow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from PyQt5.QtWidgets import QDialog, QSlider, QLabel, QWidget, QMainWindow
from PyQt5 import QtCore, QtWidgets
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
from ResultWindow import HistogramResultWindow
class HistogramWindow(QDialog):
def __init__(self, parent):
super(HistogramWindow, self).__init__()
self.parent = parent
self._setup()
self._createActions()
self._connectActions()
self.installEventFilter(self)
self.n_bins = 40
def _setup(self):
self.setObjectName("Histogram Window")
self.setFixedSize(750, 440)
self.setWindowTitle("Histogram")
self.plotting_area = QtWidgets.QWidget(self)
self.plotting_area.setGeometry(QtCore.QRect(20, 20, 700, 300))
self.plotting_area_layout = QtWidgets.QVBoxLayout(self.plotting_area)
self.canvas = FigureCanvas(self, 5, 3, 100)
self.plotting_area_layout.addWidget(self.canvas)
self.update_plot()
def update_plot(self):
self.canvas.axes.cla()
if self.parent.active_result_window is not None:
active_window = self.parent.results_windows[self.parent.active_result_window]
hist, bins = active_window.data.histogram(self.n_bins)
self.canvas.axes.stairs(hist, bins, fill=True)
self.canvas.draw()
def clear_plot(self):
self.canvas.axes.cla()
self.canvas.draw()
def _createActions(self):
self.spin_box = QtWidgets.QSpinBox(self)
self.spin_box.setGeometry(QtCore.QRect(20, 350, 150, 20))
self.spin_box.setRange(1, 1024)
self.spin_box.setValue(40)
self.spin_box.setSingleStep(1)
# Create apply button
self.applyButton = QtWidgets.QPushButton("Apply", self)
self.applyButton.setGeometry(QtCore.QRect(520, 350, 70, 30))
self.applyButton.setObjectName("applyButton")
# Create cancel button
self.cancelButton = QtWidgets.QPushButton("Cancel", self)
self.cancelButton.setGeometry(QtCore.QRect(630, 350, 70, 30))
self.cancelButton.setObjectName("cancelButton")
def _connectActions(self):
self.applyButton.clicked.connect(self.apply)
self.cancelButton.clicked.connect(self.cancel)
self.spin_box.valueChanged.connect(self._update_n_bins)
def _update_n_bins(self, value):
self.n_bins = value
self.update_plot()
def disable(self):
self.applyButton.setDisabled(True)
def enable(self):
self.applyButton.setDisabled(False)
def apply(self):
active_window = self.parent.results_windows[self.parent.active_result_window]
hist, bins = active_window.data.histogram(self.n_bins)
HistogramResultWindow(bins=bins, histogram=hist, parent=self.parent)
def cancel(self):
self.hide()
# Event handling
def eventFilter(self, source, event):
# Calling parent closing function on close
if event.type() == QtCore.QEvent.Hide:
self.parent.hist_win_active = False
return False
class FigureCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
super(FigureCanvas, self).__init__(fig)