-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScaleAdjustments.py
96 lines (74 loc) · 3.52 KB
/
ScaleAdjustments.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
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
class ScaleAdjustmentsView(QMainWindow):
""" Это окно для смены масштаба рассматриваемого графика.
"""
def __init__(self, parent, axes):
super().__init__(parent)
self.axes = axes
self.centralWidget = QWidget()
self.setCentralWidget(self.centralWidget)
self.centralLayout = QVBoxLayout(self.centralWidget)
self.xgroup = QGroupBox("Ось X")
self.xgroupLayout = QGridLayout(self.xgroup)
self.xstartlabel = QLabel("Начало оси:")
self.xendlabel = QLabel("Конец оси:")
self.xstartfield = QLineEdit(str(self.axes.get_xlim()[0]))
self.xendfield = QLineEdit(str(self.axes.get_xlim()[1]))
self.xgroupLayout.addWidget(self.xstartlabel, 1, 1)
self.xgroupLayout.addWidget(self.xendlabel, 2, 1)
self.xgroupLayout.addWidget(self.xstartfield, 1, 2)
self.xgroupLayout.addWidget(self.xendfield, 2, 2)
self.centralLayout.addWidget(self.xgroup)
self.ygroup = QGroupBox("Ось Y")
self.ygroupLayout = QGridLayout(self.ygroup)
self.ystartlabel = QLabel("Начало оси:")
self.yendlabel = QLabel("Конец оси:")
self.ystartfield = QLineEdit(str(self.axes.get_ylim()[0]))
self.yendfield = QLineEdit(str(self.axes.get_ylim()[1]))
self.ygroupLayout.addWidget(self.ystartlabel, 1, 1)
self.ygroupLayout.addWidget(self.yendlabel, 2, 1)
self.ygroupLayout.addWidget(self.ystartfield, 1, 2)
self.ygroupLayout.addWidget(self.yendfield, 2, 2)
self.centralLayout.addWidget(self.ygroup)
self.buttongroup = QWidget()
self.buttonlayout = QHBoxLayout(self.buttongroup)
self.okbutton = QPushButton("Готово")
self.okbutton.clicked.connect(self.okbuttonclicked)
self.cancelbutton = QPushButton("Отмена")
self.cancelbutton.clicked.connect(self.cancelbuttonclicked)
self.buttonlayout.addWidget(self.okbutton)
self.buttonlayout.addWidget(self.cancelbutton)
self.centralLayout.addWidget(self.buttongroup)
self.resetbutton = QPushButton("Установить масштаб по умолчанию")
self.resetbutton.clicked.connect(self.resetscaling)
self.centralLayout.addWidget(self.resetbutton)
self.setWindowTitle("Масштабирование")
self.show()
def cancelbuttonclicked(self):
self.close()
def okbuttonclicked(self):
try:
xstart = float(self.xstartfield.text())
xend = float(self.xendfield.text())
ystart = float(self.ystartfield.text())
yend = float(self.yendfield.text())
self.axes.set_xlim([xstart, xend])
self.axes.set_ylim([ystart, yend])
self.parent().graphWidget.draw()
self.close()
except ValueError:
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("Ошибка")
msg.setInformativeText("Допускаются только числовые значения")
msg.setWindowTitle("Внимание")
msg.exec_()
def resetscaling(self):
self.axes.relim()
self.axes.autoscale()
self.parent().graphWidget.draw()
self.close()