summaryrefslogtreecommitdiff
path: root/src/ui.py
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2019-05-02 19:20:02 +0200
committerPaweł Redman <pawel.redman@gmail.com>2019-05-02 19:20:02 +0200
commitb35d3e4e76ce4fad133316861f1962efd9b9184f (patch)
tree8990b30d768daf1bdea44137ea0858b0880fe02f /src/ui.py
parent6db078cf4696289bb40169398ebe5f3b1f5e87bb (diff)
Element edition window
Diffstat (limited to 'src/ui.py')
-rw-r--r--src/ui.py190
1 files changed, 114 insertions, 76 deletions
diff --git a/src/ui.py b/src/ui.py
index 6fced54..84322b6 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -39,71 +39,133 @@ class Pens:
from ui_widgets import *
-class OptBox(QVBoxLayout):
- def __init__(self, row, pol, rownum):
- super().__init__()
- self.rownum = rownum
- # Name
- self.name = MeinGroßLabel("Element %d" % rownum)
- self.name.setContextMenuPolicy(Qt.CustomContextMenu)
- self.name.customContextMenuRequested.connect(lambda pos: OptBox.open_menu(self, pos))
- self.addWidget(self.name)
- # Type / Enable box
+class ElementEditorWindow(QMainWindow):
+ windows = list()
+
+ @staticmethod
+ def open(pol):
+ win = ElementEditorWindow(pol)
+ win.show()
+ ElementEditorWindow.windows.append(win)
+
+ def __init__(self, pol):
+ super().__init__(flags=Qt.Dialog)
+ self.pol = pol
+
+ self.setWindowTitle("Element editor")
+ root = QVBoxLayout()
+ root_fucking_random_container = QWidget()
+ root_fucking_random_container.setLayout(root)
+ self.setCentralWidget(root_fucking_random_container)
+
+ # Name
box = QHBoxLayout()
- self.addLayout(box)
+ root.addLayout(box)
+ box.addWidget(QLabel("Name"))
+ self.name = QLineEdit(self.pol.name)
+ self.name.textChanged.connect(self.change_name)
+ box.addWidget(self.name)
+
+ # OPTICS
+ root.addWidget(MeinGroßLabel("Optics"))
# Type combo
self.type = QComboBox()
self.type.addItem("Linear", "linear",)
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))
- box.addWidget(self.type)
+ self.type.currentIndexChanged.connect(self.change_type)
+ root.addWidget(self.type)
- # Enable checkbox
- self.enable = QCheckBox("Enable")
- self.enable.setChecked(True)
- self.enable.stateChanged.connect(update)
- box.addWidget(self.enable)
+ # TRANSMITTANCE
+ root.addWidget(MeinGroßLabel("Transmittance"))
- # Delta / Reference layout
box = QHBoxLayout()
- self.addLayout(box)
+ root.addLayout(box)
+
+ box.addWidget(QLabel("T"))
+ self.t1 = QLineEdit("1")
+ self.t1.textChanged.connect(self.change_t)
+ box.addWidget(self.t1)
+ self.t2 = QLineEdit("0")
+ self.t2.textChanged.connect(self.change_t)
+ box.addWidget(self.t2)
+
+ # ARRANGEMENT
+ root.addWidget(MeinGroßLabel("Arrangement"))
# Angle reference
self.ref = QComboBox()
+ self.populate_ref()
+ self.ref.currentIndexChanged.connect(update)
+ root.addWidget(self.ref)
+
+ # Delta angle
+ self.delta = AngleSlider("Delta")
+ self.delta.on_change = self.change_delta
+ root.addLayout(self.delta)
+
+ root.addItem(ExpandingSpacer())
+
+ # Done
+ self.done = QPushButton("Done")
+ self.done.pressed.connect(self.close)
+ root.addWidget(self.done)
+
+ def change_name(self):
+ self.pol.name = self.name.text()
+ self.pol.row.optbox.name.setText(self.pol.name)
+
+ def change_type(self):
+ self.pol.set_type(self.type.currentData())
+ update()
+
+ def change_delta(self):
+ try:
+ self.pol.delta = self.delta.angle / 180 * np.pi
+ update()
+ except ValueError:
+ pass
+
+ def change_t(self):
+ try:
+ self.pol.t1 = float(self.t1.text())
+ self.pol.t2 = float(self.t2.text())
+ update()
+ except ValueError:
+ pass
+
+ def populate_ref(self):
self.ref.addItem("Absolute", False)
for i, _ in enumerate(system.elements):
- if i >= rownum - 1:
+ if i >= self.pol.rownum - 1:
continue
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)
+ if self.pol.ref is not False and i == self.pol.ref:
+ self.ref.setCurrentIndex(self.pol.ref + 1)
- self.ref.currentIndexChanged.connect(update)
- 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("°"))
- # Transmittance layout
- box = QHBoxLayout()
- self.addLayout(box)
+class OptBox(QVBoxLayout):
+ def __init__(self, row, pol, rownum):
+ super().__init__()
+ self.row = row
+ self.rownum = rownum
- box.addWidget(QLabel("T"))
- self.t1 = QLineEdit("1")
- self.t1.textChanged.connect(lambda: TableRow.t_change(row))
- box.addWidget(self.t1)
- self.t2 = QLineEdit("0")
- self.t2.textChanged.connect(lambda: TableRow.t_change(row))
- box.addWidget(self.t2)
+ # Name
+ self.name = MeinGroßLabel(pol.name)
+ self.name.setContextMenuPolicy(Qt.CustomContextMenu)
+ self.name.customContextMenuRequested.connect(lambda pos: OptBox.open_menu(self, pos))
+ self.addWidget(self.name)
+
+ # Enable checkbox
+ self.enable = QCheckBox("Enable")
+ self.enable.setChecked(True)
+ self.enable.stateChanged.connect(update)
+ self.addWidget(self.enable)
# Angle
self.angle = AngleSlider("Angle")
@@ -114,6 +176,7 @@ class OptBox(QVBoxLayout):
def open_menu(self, pos):
menu = QMenu()
+ menu.addAction("Edit", lambda: ElementEditorWindow.open(self.row.pol))
menu.addAction("Insert before", lambda: half_assed_element_creation(self.rownum - 1))
menu.addAction("Insert after", lambda: half_assed_element_creation(self.rownum))
menu.addAction("Delete", lambda: half_assed_element_deletion(self.rownum - 1))
@@ -123,6 +186,8 @@ class OptBox(QVBoxLayout):
class TableRow:
def __init__(self, pol, grid, rownum):
self.pol = pol
+ pol.row = self
+ pol.rownum = rownum
self.grid = grid
self.rownum = rownum
self.angle = pol.angle
@@ -150,15 +215,7 @@ class TableRow:
@staticmethod
def angle_change(row):
row.angle = row.optbox.angle.angle / 180 * np.pi
- try:
- row.delta = float(row.optbox.delta.text()) / 180 * np.pi
- except ValueError:
- pass
- update()
-
- @staticmethod
- def type_change(row):
- row.pol.set_type(row.optbox.type.currentData())
+ row.pol.angle = row.angle
update()
@staticmethod
@@ -190,9 +247,6 @@ def update():
for i, pol in enumerate(system.elements):
row = GUI.table_rows[i]
- pol.angle = row.angle
- pol.delta = row.delta
- pol.ref = row.optbox.ref.currentData()
if pol.ref is not False:
pol.angle += system.elements[pol.ref].angle
@@ -245,34 +299,18 @@ def update():
# optimize()
-#TODO later
-#class AddElementWindow(QMainWindow):
-# dialog = None
-#
-# def __init__(self):
-# super().__init__()
-#
-# chuj = QLabel("adolf")
-# self.setCentralWidget(chuj)
-# self.show()
-#
-#
-# def __del__(self):
-# AddElementWindow.dialog = None
-#
-# def open():
-# if not AddElementWindow.dialog:
-# AddElementWindow.dialog = AddElementWindow()
def half_assed_element_creation(index=None):
+ pol = phys.Polarizer("linear")
if index is None:
- system.elements.append(phys.Polarizer("linear"))
+ system.elements.append(pol)
else:
- system.elements.insert(index, phys.Polarizer("linear"))
+ system.elements.insert(index, pol)
populate_table()
GUI.table_frame = QFrame()
GUI.table_frame.setLayout(GUI.table)
GUI.scroll.setWidget(GUI.table_frame)
+ ElementEditorWindow.open(pol)
update()
def half_assed_clear():
@@ -335,13 +373,13 @@ def setup_menubar(win):
menu = win.menuBar()
# File
- open = QAction("&Open a system", win)
+ open = QAction("&Open system", win)
open.setShortcut("Ctrl+O")
open.triggered.connect(lambda: do_open(win))
- save = QAction("&Save a system", win)
+ save = QAction("&Save system", win)
save.setShortcut("Ctrl+S")
save.triggered.connect(lambda: do_save(win, True))
- save_as = QAction("&Save a system as...", win)
+ save_as = QAction("&Save system as...", win)
save_as.triggered.connect(lambda: do_save(win, False))
close = QAction("Exit", win)
close.setShortcut("Ctrl+Q")