-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBandwidthDialog.py
More file actions
105 lines (86 loc) · 3.61 KB
/
BandwidthDialog.py
File metadata and controls
105 lines (86 loc) · 3.61 KB
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
95
96
97
98
99
100
101
102
103
104
105
from PyQt5.QtWidgets import QDoubleSpinBox, QHBoxLayout, QVBoxLayout, QLabel, QPushButton, QStatusBar, QSpacerItem, \
QSizePolicy
from ui.bandwidthDialog import Ui_bandwidthDialog
from pprint import pprint
class BandwidthDialog(Ui_bandwidthDialog):
def __init__(self):
super(BandwidthDialog, self).__init__()
self.__minBoxes = []
self.__maxBoxes = []
self.__minMaxValues = ((0.0, 0.0), (0.0, 0.0))
def setupUi(self, variables):
super().setupUi(self)
self.__setLayout(self, variables)
self.__connectSlots()
def __setLayout(self, bwDialog, variables):
# self.variables = variables
verticalLayout = QVBoxLayout()
for var in variables:
verticalLayout.addLayout(self.__addLineWithBandwidthParameters(var))
self.calculateButton = self.__makeCalculateButton()
self.statusBar = QStatusBar()
verticalLayout.addSpacerItem(QSpacerItem(20, 50, QSizePolicy.Expanding, QSizePolicy.Expanding))
verticalLayout.addWidget(self.calculateButton)
verticalLayout.addWidget(self.statusBar)
bwDialog.setLayout(verticalLayout)
def __makeCalculateButton(self):
calculateButton = QPushButton()
calculateButton.setText("Calculate")
calculateButton.setObjectName("calculateButton")
return calculateButton
def __addLineWithBandwidthParameters(self, var):
horizontalLayout = QHBoxLayout()
minText = QLabel(var + ' min:')
maxText = QLabel('max:')
minBox = QDoubleSpinBox()
minBox.setMinimum(-1e20)
self.__minBoxes.append(minBox)
maxBox = QDoubleSpinBox()
maxBox.setMinimum(-1e20)
self.__maxBoxes.append(maxBox)
horizontalLayout.addWidget(minText)
horizontalLayout.addWidget(minBox)
horizontalLayout.addWidget(maxText)
horizontalLayout.addWidget(maxBox)
return horizontalLayout
def __disableButtonAndShowMessage(self):
self.calculateButton.setDisabled(True)
self.statusBar.showMessage("The min must be greater than the max")
def __enableButtonAndClearMessage(self):
self.calculateButton.setEnabled(True)
self.statusBar.clearMessage()
def __calculateButtonClicked(self):
self.__readMinMaxValues()
if not self.__checkMinMaxIsCorrect():
self.__disableButtonAndShowMessage()
return
self.accept()
def __readMinMaxValues(self):
minValues = [minBox.value() for minBox in self.__minBoxes]
maxValues = [maxBox.value() for maxBox in self.__maxBoxes]
self.__minMaxValues = tuple(zip(minValues, maxValues))
def __checkMinMaxIsCorrect(self):
for min, max in self.__minMaxValues:
if min >= max:
return False
return True
def __minValueChanged(self):
self.__readMinMaxValues()
if not self.__checkMinMaxIsCorrect():
self.__disableButtonAndShowMessage()
else:
self.__enableButtonAndClearMessage()
def __maxValueChanged(self):
self.__readMinMaxValues()
if not self.__checkMinMaxIsCorrect():
self.__disableButtonAndShowMessage()
else:
self.__enableButtonAndClearMessage()
def __connectSlots(self):
for minBox in self.__minBoxes:
minBox.valueChanged.connect(self.__minValueChanged)
for maxBox in self.__maxBoxes:
maxBox.valueChanged.connect(self.__maxValueChanged)
self.calculateButton.clicked.connect(self.__calculateButtonClicked)
def getMinMaxValues(self):
return self.__minMaxValues