diff options
Diffstat (limited to 'src/ui.py')
-rw-r--r-- | src/ui.py | 110 |
1 files changed, 37 insertions, 73 deletions
@@ -14,11 +14,11 @@ class GUI: monospace = QFont("monospace") bigfont = QFont("sans-serif", pointSize=10, weight=1000) - - from ui_widgets import * from ui_table import * + + def update(): for i, pol in enumerate(system.elements): row = GUI.table.rows[i] @@ -73,40 +73,6 @@ def update(): GUI.do_update = update - -def half_assed_element_creation(index=None): - pol = phys.Polarizer("linear") - if index is None: - system.elements.append(pol) - else: - 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(): - ElementEditorWindow.close_all() - system.elements = list() - populate_table() - GUI.table_frame = QFrame() - GUI.table_frame.setLayout(GUI.table) - GUI.scroll.setWidget(GUI.table_frame) - update() - -def half_assed_element_deletion(index): - ElementEditorWindow.close_all(pol=system.elements[pol]) - populate_table() - GUI.table_frame = QFrame() - GUI.table_frame.setLayout(GUI.table) - GUI.scroll.setWidget(GUI.table_frame) - update() - - # FIXME: refactor #def optimize(which): # if len(system.elements) == 0: @@ -144,12 +110,42 @@ class MainWindow(QMainWindow): def __init__(self, system_): super().__init__() self.last_save_path = None + global system + system = system_ - self.statusBar() self.setWindowTitle("Polarizzazione italiana") - global system - system = system_ + # Central widget + root = QVBoxLayout() + self.setCentralWidget(LayoutWrapper(root)) + + box = QHBoxLayout() + root.addLayout(box) + + # Top bar + box.addWidget(QLabel("Input intensity")) + GUI.input_intensity = QLineEdit("%g" % system.input_intensity) + GUI.input_intensity.textChanged.connect(self.change_input_intensity) + box.addWidget(GUI.input_intensity) + + # Splitter + split = QSplitter() + root.addWidget(split) + + # Table (LHS) + GUI.table = SystemTable() + split.addWidget(GUI.table) + + # Splitter RHS + rhs = QVBoxLayout() + split.addWidget(LayoutWrapper(rhs)) + + Widocques.image = QImage("jones.jpg") + GUI.widok = Widocques() + rhs.addWidget(GUI.widok) + + GUI.table.populate(system) + update() # Menu menu_bar = self.menuBar() @@ -182,45 +178,13 @@ class MainWindow(QMainWindow): act = QAction("&Add a new element", self) act.setShortcut("Ctrl+N") - act.triggered.connect(lambda: half_assed_element_creation()) + act.triggered.connect(lambda: GUI.table.insert_row(None, False)) menu.addAction(act) act = QAction("&Remove all elements", self) - act.triggered.connect(half_assed_clear) + act.triggered.connect(GUI.table.clear) menu.addAction(act) - # Central widget - root = QVBoxLayout() - self.setCentralWidget(LayoutWrapper(root)) - - box = QHBoxLayout() - root.addLayout(box) - - # Top bar - box.addWidget(QLabel("Input intensity")) - GUI.input_intensity = QLineEdit("%g" % system.input_intensity) - GUI.input_intensity.textChanged.connect(self.change_input_intensity) - box.addWidget(GUI.input_intensity) - - # Splitter - split = QSplitter() - root.addWidget(split) - - # Table (LHS) - GUI.table = SystemTable() - split.addWidget(GUI.table) - - # Splitter RHS - rhs = QVBoxLayout() - split.addWidget(LayoutWrapper(rhs)) - - Widocques.image = QImage("jones.jpg") - GUI.widok = Widocques() - rhs.addWidget(GUI.widok) - - GUI.table.populate(system) - update() - def change_input_intensity(self): try: system.input_intensity = float(GUI.input_intensity.text()) |