From d39c23895857ef9ae8080ddd125e845eaa1c8aa3 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Wed, 1 May 2019 12:17:01 +0200 Subject: Optbox improvements --- src/ui.py | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'src/ui.py') diff --git a/src/ui.py b/src/ui.py index d58ab3a..4f6b189 100644 --- a/src/ui.py +++ b/src/ui.py @@ -50,8 +50,8 @@ class OptBox(QVBoxLayout): self.addWidget(self.name) # Type / Enable box - self.hbox = QHBoxLayout() - self.addLayout(self.hbox) + box = QHBoxLayout() + self.addLayout(box) # Type combo self.type = QComboBox() @@ -59,19 +59,17 @@ class OptBox(QVBoxLayout): self.type.addItem("Quarterwave plate", "quarterwave") self.type.setCurrentIndex(0 if pol.type == "linear" else 1) self.type.currentIndexChanged.connect(lambda : TableRow.type_change(row)) - self.hbox.addWidget(self.type) + box.addWidget(self.type) # Enable checkbox self.enable = QCheckBox("Enable") self.enable.setChecked(True) self.enable.stateChanged.connect(update) - self.hbox.addWidget(self.enable) + box.addWidget(self.enable) - # Delta angle - self.delta = AngleSlider("Delta") - self.delta.setValue(pol.delta * 180 / np.pi) - self.delta.on_change = lambda: TableRow.angle_change(row) - self.addLayout(self.delta) + # Delta / Reference layout + box = QHBoxLayout() + self.addLayout(box) # Angle reference self.ref = QComboBox() @@ -79,13 +77,20 @@ class OptBox(QVBoxLayout): for i, _ in enumerate(system.elements): if i >= rownum - 1: continue - self.ref.addItem("Relative to element #%d" % (i + 1), i) + self.ref.addItem("Relative to #%d" % (i + 1), i) if row.ref is not False and i == row.ref: self.ref.setCurrentIndex(row.ref + 1) self.ref.currentIndexChanged.connect(update) - self.addWidget(self.ref) + box.addWidget(self.ref) + + # Delta angle + box.addWidget(QLabel("Delta")) + self.delta = QLineEdit("0") + self.delta.textChanged.connect(lambda: TableRow.angle_change(row)) + box.addWidget(self.delta) + box.addWidget(QLabel("°")) # Angle self.angle = AngleSlider("Angle") @@ -102,11 +107,11 @@ class OptBox(QVBoxLayout): self.delete = QPushButton("Delete") self.delete.clicked.connect(lambda: half_assed_element_deletion(rownum - 1)) - self.buttons = QHBoxLayout() - self.buttons.addWidget(self.add_above) - self.buttons.addWidget(self.add_below) - self.buttons.addWidget(self.delete) - self.addLayout(self.buttons) + box = QHBoxLayout() + box.addWidget(self.add_above) + box.addWidget(self.add_below) + box.addWidget(self.delete) + self.addLayout(box) @@ -140,7 +145,10 @@ class TableRow: @staticmethod def angle_change(row): row.angle = row.optbox.angle.angle / 180 * np.pi - row.delta = row.optbox.delta.angle / 180 * np.pi + try: + row.delta = float(row.optbox.delta.text()) / 180 * np.pi + except ValueError: + pass update() @staticmethod -- cgit