diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2019-05-03 15:56:04 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2019-05-03 15:56:04 +0200 |
commit | ea83137c32be2f7c47e6c4e4bbfaafeb0591db21 (patch) | |
tree | acb0ee2dd3d29ee6d09dd29b234eb5a9b16eb469 /src | |
parent | 5a952899e095c82ff706449ee4d3f8c5eaac7911 (diff) |
Bring back basic functionality
Diffstat (limited to 'src')
-rw-r--r-- | src/ui.py | 9 | ||||
-rw-r--r-- | src/ui_table.py | 45 | ||||
-rw-r--r-- | src/ui_widgets.py | 19 |
3 files changed, 38 insertions, 35 deletions
@@ -41,7 +41,7 @@ from ui_table import * def update(): for i, pol in enumerate(system.elements): - row = GUI.table_rows[i] + row = GUI.table.rows[i] if pol.ref is not False: pol.angle += system.elements[pol.ref].angle @@ -50,7 +50,7 @@ def update(): I = 1 for i, pol in enumerate(system.elements): - row = GUI.table_rows[i] + row = GUI.table.rows[i] # update all the diagrams row.ellipse.state = system.states[i] @@ -91,6 +91,8 @@ def update(): #if GUI.auto_optimize.isChecked(): # optimize() +GUI.do_update = update + def half_assed_element_creation(index=None): pol = phys.Polarizer("linear") @@ -312,8 +314,7 @@ class MainWindow(QMainWindow): rhs.addWidget(GUI.widok) GUI.table.populate(system) - - #update() + update() def change_input_intensity(self): try: diff --git a/src/ui_table.py b/src/ui_table.py index 3d9a6fa..08b99f3 100644 --- a/src/ui_table.py +++ b/src/ui_table.py @@ -12,8 +12,8 @@ class ElementEditorWindow(QMainWindow): windows = list() @staticmethod - def open(pol): - win = ElementEditorWindow(pol) + def open(system, pol): + win = ElementEditorWindow(system, pol) win.show() ElementEditorWindow.windows.append(win) @@ -24,8 +24,9 @@ class ElementEditorWindow(QMainWindow): win.close() del(win) - def __init__(self, pol): + def __init__(self, system, pol): super().__init__(flags=Qt.Dialog) + self.system = system self.pol = pol self.setWindowTitle("Element editor") @@ -73,7 +74,7 @@ class ElementEditorWindow(QMainWindow): # Angle reference self.ref = QComboBox() self.populate_ref() - self.ref.currentIndexChanged.connect(update) + self.ref.currentIndexChanged.connect(GUI.do_update) root.addWidget(self.ref) # Delta angle @@ -94,12 +95,12 @@ class ElementEditorWindow(QMainWindow): def change_type(self): self.pol.set_type(self.type.currentData()) - update() + GUI.do_update() def change_delta(self): try: self.pol.delta = self.delta.angle / 180 * np.pi - update() + GUI.do_update() except ValueError: pass @@ -107,19 +108,16 @@ class ElementEditorWindow(QMainWindow): try: self.pol.t1 = float(self.t1.text()) self.pol.t2 = float(self.t2.text()) - update() + GUI.do_update() except ValueError: pass def populate_ref(self): self.ref.addItem("Absolute", False) - for i, _ in enumerate(system.elements): - if i >= self.pol.rownum - 1: - continue - self.ref.addItem("Relative to #%d" % (i + 1), i) + for i, pol in enumerate(self.system.elements): + self.ref.addItem("Relative to %s" % pol.name) - if self.pol.ref is not False and i == self.pol.ref: - self.ref.setCurrentIndex(self.pol.ref + 1) + self.ref.setCurrentIndex(self.pol.ref) @@ -143,13 +141,13 @@ class OptBox(QVBoxLayout): # Angle self.angle = AngleSlider() self.angle.setValue(pol.angle * 180 / np.pi) - self.angle.on_change = lambda: TableRow.angle_change(row) + 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.pol)) + 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)) @@ -188,11 +186,10 @@ class SystemTableRow: self.info.addItem(ExpandingSpacer()) parent.setCellWidget(row_number, 2, LayoutWrapper(self.info)) - @staticmethod - def angle_change(row): - row.angle = row.optbox.angle.angle / 180 * np.pi - row.pol.angle = row.angle - update() + def angle_change(self): + self.angle = self.optbox.angle.angle / 180 * np.pi + self.pol.angle = self.angle + GUI.do_update() @@ -204,8 +201,12 @@ class SystemTable(QTableWidget): self.setColumnCount(3) # this won't change self.hh = self.horizontalHeader() - self.hh.setSectionResizeMode(QHeaderView.ResizeToContents) - #self.hh.hide() + 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) diff --git a/src/ui_widgets.py b/src/ui_widgets.py index 3babfa6..384b948 100644 --- a/src/ui_widgets.py +++ b/src/ui_widgets.py @@ -10,6 +10,13 @@ class ExpandingSpacer(QSpacerItem): super().__init__(0, 0, QSizePolicy.Minimum, \ QSizePolicy.Expanding) +class LayoutWrapper(QWidget): + def __init__(self, layout): + super().__init__() + self.setLayout(layout) + + + class MeinLabel(QLabel): def __init__(self, *args): QLabel.__init__(self, *args) @@ -21,10 +28,7 @@ class MeinGroßLabel(QLabel): self.setFont(GUI.bigfont) self.setAlignment(Qt.AlignHCenter) -class LayoutWrapper(QWidget): - def __init__(self, layout): - super().__init__() - self.setLayout(layout) + class EllipseWidget(QWidget): def __init__(self, pol): @@ -34,11 +38,8 @@ class EllipseWidget(QWidget): self.ellipse = None self.is_used = True - self.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, \ - QSizePolicy.MinimumExpanding)) - - def minimumSizeHint(self): - return QSize(170, 170) + self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, \ + QSizePolicy.Expanding)) def paintEvent(self, event): P = QPainter(self) |