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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
import numpy as np
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from ui import GUI, Pens
from ui_widgets import *
class ElementEditorWindow(QMainWindow):
windows = list()
@staticmethod
def open(system, pol):
win = ElementEditorWindow(system, pol)
win.show()
ElementEditorWindow.windows.append(win)
@staticmethod
def close_all(pol=None):
for win in ElementEditorWindow.windows:
if pol is None or pol == win.pol:
win.close()
del(win)
def __init__(self, system, pol):
super().__init__(flags=Qt.Dialog)
self.system = system
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()
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(self.change_type)
root.addWidget(self.type)
# TRANSMITTANCE
root.addWidget(MeinGroßLabel("Transmittance"))
box = QHBoxLayout()
root.addLayout(box)
box.addWidget(QLabel("T"))
self.t1 = QLineEdit("%g" % self.pol.t1)
self.t1.textChanged.connect(self.change_t)
box.addWidget(self.t1)
self.t2 = QLineEdit("%g" % self.pol.t2)
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(GUI.do_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())
GUI.do_update()
def change_delta(self):
try:
self.pol.delta = self.delta.angle / 180 * np.pi
GUI.do_update()
except ValueError:
pass
def change_t(self):
try:
self.pol.t1 = float(self.t1.text())
self.pol.t2 = float(self.t2.text())
GUI.do_update()
except ValueError:
pass
def populate_ref(self):
self.ref.addItem("Absolute", False)
for i, pol in enumerate(self.system.elements):
self.ref.addItem("Relative to %s" % pol.name)
self.ref.setCurrentIndex(self.pol.ref)
class OptBox(QVBoxLayout):
def __init__(self, row, pol):
super().__init__()
self.row = row
# 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(self.change_enable)
self.addWidget(self.enable)
# Angle
self.angle = AngleSlider()
self.angle.setValue(pol.angle * 180 / np.pi)
self.angle.on_change = row.angle_change
self.addLayout(self.angle)
self.addItem(ExpandingSpacer())
def open_menu(self, pos):
menu = QMenu()
menu.addAction("Edit", lambda: ElementEditorWindow.open(self.row.parent.system, 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))
menu.exec_(self.name.mapToGlobal(pos))
def change_enable(self):
self.row.pol.enable = self.enable.isChecked()
update()
class SystemTableRow:
def __init__(self, parent, pol, row_number):
self.parent = parent
self.pol = pol
pol.row = self
self.angle = pol.angle
self.delta = pol.delta
self.ref = pol.ref
self.optbox = OptBox(self, pol)
parent.setCellWidget(row_number, 0, LayoutWrapper(self.optbox))
self.ellipse = EllipseWidget(pol)
parent.setCellWidget(row_number, 1, self.ellipse)
self.info = QVBoxLayout()
self.info_angle = MeinLabel()
self.info_angle.setAlignment(Qt.AlignLeft)
self.info.addWidget(self.info_angle)
self.info.addWidget(QLabel("Polarization state"))
self.info_jones = MeinLabel()
self.info_jones.setAlignment(Qt.AlignLeft)
self.info.addWidget(self.info_jones)
self.info.addItem(ExpandingSpacer())
parent.setCellWidget(row_number, 2, LayoutWrapper(self.info))
def angle_change(self):
self.angle = self.optbox.angle.angle / 180 * np.pi
self.pol.angle = self.angle
GUI.do_update()
class SystemTable(QTableWidget):
def __init__(self):
super().__init__()
self.rows = list()
self.setColumnCount(3) # this won't change
self.hh = self.horizontalHeader()
self.hh.setSectionResizeMode(0, QHeaderView.ResizeToContents)
self.hh.resizeSection(1, 170)
self.hh.setStretchLastSection(True)
self.setHorizontalHeaderLabels([
"Settings", "Ellipse", "State"
])
self.vh = self.verticalHeader()
self.vh.setSectionResizeMode(QHeaderView.ResizeToContents)
def populate(self, system):
self.system = system
self.rows = list()
self.clearContents()
self.setRowCount(len(system.elements))
for i, pol in enumerate(system.elements):
self.rows.append(SystemTableRow(self, pol, i))
|