Skip to content

Commit 066754c

Browse files
committed
settings view
1 parent 6a663ba commit 066754c

File tree

9 files changed

+253
-122
lines changed

9 files changed

+253
-122
lines changed

omc3_gui/plotting/classes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
Containers for figures, plots, etc.
66
"""
7-
from dataclasses import dataclass
87
import pyqtgraph as pg
98
from accwidgets.graph import StaticPlotWidget
109
from accwidgets.graph.widgets.plotitem import ExViewBox

omc3_gui/plotting/tfs_plotter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def plot_dataframes(
5656
"""
5757
plot_item: pg.PlotItem = plot.plotItem
5858

59-
if legend:
60-
plot_item.addLegend(offset=(0, 0))
59+
plot_item.addLegend(offset=(0, 0))
6160

6261
for idx, (name, df) in enumerate(dataframes.items()):
6362
color = pg.Color(get_mpl_color(idx))
@@ -88,6 +87,8 @@ def plot_dataframes(
8887

8988
if ylabel is not None:
9089
plot_item.setLabel("left", ylabel)
90+
91+
plot_item.legend.setVisible(legend)
9192

9293
def plot_errorbar(
9394
plot: pg.PlotItem,

omc3_gui/segment_by_segment/main_controller.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from omc3_gui.segment_by_segment.defaults import DEFAULT_SEGMENTS
1919
from omc3_gui.segment_by_segment.plotting import plot_segment_data
20-
from omc3_gui.segment_by_segment.settings_model import PlotSettings, Settings
20+
from omc3_gui.segment_by_segment.settings import PlotSettings, Settings
2121
from omc3_gui.segment_by_segment.main_model import SegmentTableModel
2222
from omc3_gui.segment_by_segment.main_view import SbSWindow
2323
from omc3_gui.segment_by_segment.measurement_model import OpticsMeasurement
@@ -28,6 +28,7 @@
2828
compare_segments,
2929
)
3030
from omc3_gui.segment_by_segment.segment_view import SegmentDialog
31+
from omc3_gui.ui_components.dataclass_ui import SettingsDialog
3132
from omc3_gui.ui_components.file_dialogs import OpenAnySingleDialog, OpenDirectoriesDialog
3233
from omc3_gui.ui_components.message_boxes import show_confirmation_dialog
3334
from omc3_gui.ui_components.text_editor import TextEditorDialog
@@ -50,7 +51,7 @@ def __init__(self, settings: Settings | None = None):
5051
self.connect_signals()
5152
self.settings: Settings = settings or Settings()
5253

53-
self._last_selected_optics_path: Path = self.settings.cwd
54+
self._last_selected_optics_path: Path = self.settings.main.cwd
5455
self._running_tasks: list[BackgroundThread] = []
5556

5657
self.set_measurement_interaction_buttons_enabled(False)
@@ -328,7 +329,7 @@ def edit_corrections(self) -> None:
328329
# Only one or none correction file within the selection measurements from here ---
329330
if len(correction_files) == 0: # If there is none, ask user to provide one
330331
LOGGER.debug("No correction file selected. Asking.")
331-
directory = self.settings.cwd
332+
directory = self.settings.main.cwd
332333
if len(selected_measurements) == 1:
333334
directory = selected_measurements[0].measurement_dir
334335

@@ -650,7 +651,7 @@ def plot(self):
650651
""" Trigger a plot update with the currently selected segments. """
651652
view: SbSWindow = self._view
652653
settings: PlotSettings = self.settings.plotting
653-
654+
654655
segments = view.get_selected_segments()
655656
if len(segments) != 1:
656657
LOGGER.error("Please select exactly one segment to plot.")
@@ -660,6 +661,8 @@ def plot(self):
660661
LOGGER.error("Please enable at least one propagation method to show.")
661662
return
662663

664+
self.clear_plots()
665+
663666
segments_data: list[SegmentDataModel] = segments[0].segments
664667
definition, widget = view.get_current_tab()
665668
plot_segment_data(
@@ -679,3 +682,7 @@ def clear_plots(self):
679682
@Slot()
680683
def show_settings(self):
681684
LOGGER.debug("Showing settings.")
685+
settings_dialog = SettingsDialog(settings=self.settings)
686+
if settings_dialog.exec_():
687+
self.plot()
688+

omc3_gui/segment_by_segment/measurement_view.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ def __init__(self, parent=None, optics_measurement: OpticsMeasurement | None = N
2323
optics_measurement = OpticsMeasurement(measurement_dir=TO_BE_DEFINED, output_dir=TO_BE_DEFINED)
2424

2525
non_editable = ("measurement_dir", ) # set by program not by user
26-
dataclass_ui = DataClassUI.build_dataclass_ui(
26+
dataclass_ui = DataClassUI(
2727
field_definitions=[
2828
FieldUIDef(field.name, editable=field.name not in non_editable)
2929
for field in fields(OpticsMeasurement) if field.name[0] != "_"
3030
],
31-
dclass=OpticsMeasurement,
31+
dclass=optics_measurement,
3232
)
33-
dataclass_ui.model = optics_measurement
3433
super().__init__(dataclass_ui=dataclass_ui, parent=parent)
3534

3635
@property

omc3_gui/segment_by_segment/plotting.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from omc3.definitions.optics import ColumnsAndLabels, S_COLUMN
1111
from omc3_gui.plotting.classes import DualPlot
12-
from omc3_gui.segment_by_segment.settings_model import PlotSettings
12+
from omc3_gui.segment_by_segment.settings import PlotSettings
1313
from omc3_gui.plotting.latex_to_html import latex_to_html_converter
1414
from omc3_gui.plotting.tfs_plotter import plot_dataframes
1515
from omc3_gui.segment_by_segment.segment_model import SegmentDataModel
@@ -40,6 +40,9 @@ def plot_segment_data(widget: DualPlot, definition: ColumnsAndLabels, segments:
4040
column_def = PropagableColumns(plane_def.column, plane="") # `.column` already contains plane
4141

4242
for direction in ("forward", "backward"):
43+
if not getattr(settings, direction):
44+
continue
45+
4346
for expected in (None, settings.expected):
4447
# note: don't really like the way the following settings are handled,
4548
# but lack a better idea (jdilly, 2025)

omc3_gui/segment_by_segment/segment_view.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ def __init__(self, parent=None, segment: SegmentDataModel | None = None):
2121
if segment is None:
2222
segment = SegmentDataModel(name=TO_BE_DEFINED, measurement=None) # dummy
2323

24-
dataclass_ui = DataClassUI.build_dataclass_ui(
24+
dataclass_ui = DataClassUI(
2525
field_definitions=[
2626
FieldUIDef(name) for name in ("name", "start", "end")
2727
],
28-
dclass=SegmentDataModel,
28+
dclass=segment,
2929
)
30-
dataclass_ui.model = segment
3130
super().__init__(dataclass_ui=dataclass_ui, parent=parent)
3231

3332
@property

omc3_gui/segment_by_segment/settings_model.py renamed to omc3_gui/segment_by_segment/settings.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@
1111

1212
from omc3_gui.ui_components.dataclass_ui import metafield
1313

14+
@dataclass(slots=True)
15+
class MainSettings:
16+
cwd: Path = metafield("Working Directory", "Current working directory. Used for default path when opening file selection dialogs.", default=Path.cwd())
17+
# autoload_segments: bool = metafield("Autoload Segments", "Automatically try to load existing segments when loading a measurement.", default=True) # TODO
18+
1419

1520
@dataclass(slots=True)
1621
class PlotSettings:
17-
connect_x: bool = metafield("Connect X", "Connect X axes.", default=False)
18-
connect_y: bool = metafield("Connect Y", "Connect Y axes.", default=False)
22+
# connect_x: bool = metafield("Connect X", "Connect X axes.", default=False) # TODO
23+
# connect_y: bool = metafield("Connect Y", "Connect Y axes.", default=False) # TODO
1924
show_legend: bool = metafield("Show Legend", "Show legend.", default=True)
2025
forward: bool = metafield("Forward Propagation", "Show forward propagation.", default=True)
2126
backward: bool = metafield("Backward Propagation", "Show backward propagation.", default=True)
2227
expected: bool = metafield("Expectation", "Show expected value after correction instead of correction itself.", default=False)
2328

29+
2430
@dataclass(slots=True)
2531
class Settings:
26-
cwd: Path = metafield("CWD", "Current working directory.", default=Path.cwd())
27-
autoload_segments: bool = metafield("Autoload Segments", "Automatically try to load existing segments when loading a measurement.", default=True)
32+
main: MainSettings = field(default_factory=MainSettings)
2833
plotting: PlotSettings = field(default_factory=PlotSettings)

omc3_gui/segment_by_segment/settings_view.py

Whitespace-only changes.

0 commit comments

Comments
 (0)