diff --git a/archive_viewer/archive_viewer.py b/archive_viewer/archive_viewer.py index 22d60cd..3fd07ff 100644 --- a/archive_viewer/archive_viewer.py +++ b/archive_viewer/archive_viewer.py @@ -27,7 +27,8 @@ def __init__(self, parent=None, args=None, macros=None, ui_filename=__file__.rep self.curve_delegates_init() self.axis_delegates_init() - self.timespan = -1 self.axis_table_model.reset_everything.connect(self.resetPlot) + self.timespan = -1 + self.axis_table_model.reset_everything.connect(self.resetPlot) # Create reference dict for timespan_btns button group self.button_spans = { self.ui.half_min_scale_btn: 30, diff --git a/archive_viewer/av_file_convert.py b/archive_viewer/av_file_convert.py index 0c3ca2c..b686718 100755 --- a/archive_viewer/av_file_convert.py +++ b/archive_viewer/av_file_convert.py @@ -278,7 +278,7 @@ def get_plot_data(plot: PyDMTimePlot) -> dict: [start_ts, end_ts] = plot.getXAxis().range start_dt = datetime.fromtimestamp(start_ts) end_dt = datetime.fromtimestamp(end_ts) - + output_dict['plot'] = plot.to_dict() output_dict['time_axis'] = {'name': "Main Time Axis", 'start': start_dt.isoformat(sep=' ', timespec='seconds'), 'end': end_dt.isoformat(sep=' ', timespec='seconds'), diff --git a/archive_viewer/mixins/file_io.py b/archive_viewer/mixins/file_io.py index b182a98..3e33f29 100644 --- a/archive_viewer/mixins/file_io.py +++ b/archive_viewer/mixins/file_io.py @@ -95,6 +95,7 @@ def import_save_file(self, file_name: str | Path = None) -> None: # Set the models to use the file data self.axis_table_model.set_model_axes(file_data['y-axes']) self.curves_model.set_model_curves(file_data['curves']) + self.plot_setup(file_data['plot']) # Enable auto scroll if the end time is "now" self.ui.cursor_scale_btn.click() diff --git a/archive_viewer/mixins/plot_config.py b/archive_viewer/mixins/plot_config.py index 54a6280..f7b70b1 100644 --- a/archive_viewer/mixins/plot_config.py +++ b/archive_viewer/mixins/plot_config.py @@ -1,6 +1,7 @@ -from widgets import ColorButton +from typing import Dict +from qtpy.QtGui import QColor from pyqtgraph import ViewBox - +from widgets import ColorButton class PlotConfigMixin: def plot_config_init(self): @@ -12,25 +13,39 @@ def plot_config_init(self): self.plot = self.ui.archiver_plot self.ui.plot_title_edit.textChanged.connect(self.plot.setPlotTitle) - self.ui.x_grid_chckbx.clicked.connect(self.show_x_grid) + self.ui.x_grid_chckbx.stateChanged.connect(self.show_x_grid) - self.ui.y_grid_chckbx.clicked.connect(self.show_y_grid) + self.ui.y_grid_chckbx.stateChanged.connect(self.show_y_grid) self.ui.opacity_sldr.valueChanged.connect(self.change_opacity) - background_color_button = ColorButton(color="white") - self.ui.background_color_lyt.insertWidget(1, background_color_button) - background_color_button.color_changed.connect(self.plot.setBackgroundColor) + self.background_color_button = ColorButton(color="white") + self.ui.background_color_lyt.insertWidget(1, self.background_color_button) + self.background_color_button.color_changed.connect(self.plot.setBackgroundColor) self.ui.refresh_interval_spnbx.setValue(5) self.ui.refresh_interval_spnbx.valueChanged.connect(lambda interval: self.autoScroll(enable=True)) - self.ui.legend_chckbx.clicked.connect(self.plot.setShowLegend) + self.ui.legend_chckbx.stateChanged.connect(self.plot.setShowLegend) - self.ui.crosshair_chckbx.clicked.connect(lambda show: self.plot.enableCrosshair(show, 100, 100)) + self.ui.crosshair_chckbx.stateChanged.connect(lambda show: self.plot.enableCrosshair(show, 100, 100)) self.ui.mouse_mode_cmbbx.currentIndexChanged.connect(self.changeMouseMode) + def plot_setup(self, config: Dict): + """Read in the full config dictionary, making sure not to fail if a user manually typed + the import file out. For each config preset, set the widgets to match the value, which will + send signals out that will actually cause the plot to change""" + if 'title' in config: self.ui.plot_title_edit.setText(config['title']) + if 'xGrid' in config: self.ui.x_grid_chckbx.setChecked(config['xGrid']) + if 'yGrid' in config: self.ui.y_grid_chckbx.setChecked(config['yGrid']) + if 'opacity' in config: self.ui.opacity_sldr.setValue(config['opacity']) + if 'backgroundColor' in config: self.background_color_button.color = QColor(config['backgroundColor']) + if 'legend' in config: self.ui.legend_chckbx.setChecked(config['legend']) + if 'mouseMode' in config: self.ui.mouse_mode_cmbbx.setCurrentIndex(int(config['mouseMode']/3)) + if 'crosshair' in config: self.ui.crosshair_chckbx.setChecked(config['crosshair']) + if 'refreshInterval' in config: self.ui.refresh_interval_spnbx.setValue(config['refreshInterval']) + def changeMouseMode(self, mode:int): """If the user wants to have their mouse in PAN or RECT mode""" mouse_mode = ViewBox.RectMode