diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2019-05-02 19:54:26 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2019-05-02 19:59:49 +0200 |
commit | 6fcef36d90a66afd7c974748af7de2017f4f5792 (patch) | |
tree | 8859f434423fc7355f7c8c1e5b246ee2a6a516b6 | |
parent | b35ade41339ea95ec3c59eb45b813273304682e7 (diff) |
Input intensity
-rw-r--r-- | src/file.py | 6 | ||||
-rw-r--r-- | src/phys.py | 7 | ||||
-rw-r--r-- | src/ui.py | 28 | ||||
-rw-r--r-- | src/ui_widgets.py | 2 |
4 files changed, 35 insertions, 8 deletions
diff --git a/src/file.py b/src/file.py index 417c77b..3c69063 100644 --- a/src/file.py +++ b/src/file.py @@ -1,13 +1,13 @@ import re, sys, traceback, json import phys -file_format_version = 4 +file_format_version = 5 def save_system(path, system): ser = dict() + ser["input_intensity"] = system.input_intensity ser["version"] = file_format_version - ser["ignore"] = system.ignore ser["elements"] = [] for pol in system.elements: el = { @@ -36,7 +36,7 @@ def open_system(path): raise ValueError("Bad file version: expected %d, found %d" \ % (file_format_version, ser["version"])) - system.ignore = ser["ignore"] + system.input_intensity = float(ser["input_intensity"]) for el in ser["elements"]: pol = phys.Polarizer(str(el["type"])) diff --git a/src/phys.py b/src/phys.py index cf30667..4e78fe2 100644 --- a/src/phys.py +++ b/src/phys.py @@ -94,6 +94,7 @@ class Polarizer: class System: def __init__(self): self.elements = list() + self.input_intensity = 1 def recalculate(system): system.states = [None] * len(system.elements) @@ -102,6 +103,10 @@ class System: state = None for i, pol in enumerate(system.elements): if pol.enable: - state = pol.mul(state) + new_state = pol.mul(state) + if state is None and new_state is not None: + state = new_state * np.sqrt(system.input_intensity) + else: + state = new_state system.states[i] = state system.ellipses.append(Ellipse(state)) @@ -236,6 +236,8 @@ class TableRow: def populate_table(): + GUI.input_intensity.setText("%g" % system.input_intensity) + GUI.table = QGridLayout() GUI.table.setColumnStretch(1, 1) GUI.table.setColumnStretch(2, 2) @@ -444,17 +446,37 @@ def optimize(which): GUI.table_rows[op_idx].optbox.angle.edit.setText("%g" % round(opt.x * 180 / np.pi, 3)) + +def change_input_intensity(): + try: + system.input_intensity = float(GUI.input_intensity.text()) + update() + except ValueError: + pass + def setup(win, system_): global system system = system_ # Needless to say, I'm getting real tired of this whole Layout/Widget # clusterfuck in Qt - root = QHBoxLayout() + root = QVBoxLayout() root_fucking_random_container = QWidget() root_fucking_random_container.setLayout(root) win.setCentralWidget(root_fucking_random_container) + # Top bar (input intensity) + box = QHBoxLayout() + root.addLayout(box) + + box.addWidget(QLabel("Input intensity")) + GUI.input_intensity = QLineEdit("1") + GUI.input_intensity.textChanged.connect(change_input_intensity) + box.addWidget(GUI.input_intensity) + + hbox = QHBoxLayout() + root.addLayout(hbox) + rhs = QVBoxLayout() Widocques.image = QImage("jones.jpg") @@ -479,8 +501,8 @@ def setup(win, system_): GUI.table_frame.setLayout(GUI.table) GUI.scroll.setWidget(GUI.table_frame) - root.addWidget(GUI.scroll) - root.addLayout(rhs) + hbox.addWidget(GUI.scroll) + hbox.addLayout(rhs) setup_menubar(win) diff --git a/src/ui_widgets.py b/src/ui_widgets.py index 36ff333..9eabd2e 100644 --- a/src/ui_widgets.py +++ b/src/ui_widgets.py @@ -33,7 +33,7 @@ class EllipseWidget(QWidget): QSizePolicy.MinimumExpanding)) def minimumSizeHint(self): - return QSize(100, 100) + return QSize(170, 170) def paintEvent(self, event): P = QPainter(self) |