Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Plot Config Import/Export #32

Merged
merged 7 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion archive_viewer/archive_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion archive_viewer/av_file_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions archive_viewer/mixins/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 24 additions & 9 deletions archive_viewer/mixins/plot_config.py
Original file line number Diff line number Diff line change
@@ -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):
aksharsarvesh marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -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
Expand Down
Loading