Skip to content

Commit

Permalink
Worked at a few changes for precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
aksharsarvesh committed Jul 15, 2024
1 parent 175c117 commit 85287b7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
21 changes: 11 additions & 10 deletions archive_viewer/archive_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from qtpy.QtWidgets import QAbstractButton, QApplication
from pydm import Display
from config import logger
from mixins import (TracesTableMixin, AxisTableMixin)
from mixins import TracesTableMixin, AxisTableMixin
from styles import CenterCheckStyle


class ArchiveViewer(Display, TracesTableMixin, AxisTableMixin):
def __init__(self, parent=None, args=None, macros=None, ui_filename=__file__.replace(".py", ".ui")) -> None:
super(ArchiveViewer, self).__init__(parent=parent, args=args,
macros=macros, ui_filename=ui_filename)
super(ArchiveViewer, self).__init__(parent=parent, args=args, macros=macros, ui_filename=ui_filename)

self.ui.main_spltr.setCollapsible(0, False)
self.ui.main_spltr.setStretchFactor(0, 1)
Expand All @@ -21,12 +20,14 @@ def __init__(self, parent=None, args=None, macros=None, ui_filename=__file__.rep
self.curve_delegates_init()
self.axis_delegates_init()

self.button_spans = {self.ui.half_min_scale_btn: 30,
self.ui.min_scale_btn: 60,
self.ui.hour_scale_btn: 3600,
self.ui.week_scale_btn: 604800,
self.ui.month_scale_btn: 2628300,
self.ui.cursor_scale_btn: -1}
self.button_spans = {
self.ui.half_min_scale_btn: 30,
self.ui.min_scale_btn: 60,
self.ui.hour_scale_btn: 3600,
self.ui.week_scale_btn: 604800,
self.ui.month_scale_btn: 2628300,
self.ui.cursor_scale_btn: -1
}
self.ui.timespan_btns.buttonClicked.connect(partial(self.set_plot_timerange))

plot_viewbox = self.ui.archiver_plot.plotItem.vb
Expand All @@ -52,7 +53,7 @@ def set_plot_timerange(self, button: QAbstractButton) -> None:
logger.error(f"{button} is not a valid timespan button")
return

enable_scroll = (button != self.ui.cursor_scale_btn)
enable_scroll = button != self.ui.cursor_scale_btn
timespan = self.button_spans[button]

self.ui.archiver_plot.setAutoScroll(enable_scroll, timespan)
4 changes: 2 additions & 2 deletions archive_viewer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
with open("config.json") as f:
loaded_json = load(f)

archiver_urls = loaded_json['archivers']
archiver_urls = loaded_json["archivers"]
if not archiver_urls:
archiver_urls = [os.getenv("PYDM_ARCHIVER_URL")]

color_palette = [QColor(hex_code) for hex_code in loaded_json['colors']]
color_palette = [QColor(hex_code) for hex_code in loaded_json["colors"]]
42 changes: 25 additions & 17 deletions archive_viewer/mixins/traces_table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import (Dict, Any)
from typing import Dict, Any
from PySide2.QtGui import QKeyEvent
from qtpy.QtCore import (Slot, QPoint, QModelIndex, QObject, Qt)
from qtpy.QtWidgets import (QHeaderView, QMenu, QAction, QTableView, QDialog,
Expand All @@ -7,8 +7,14 @@
from pydm.widgets.baseplot_curve_editor import PlotStyleColumnDelegate
from config import logger
from pydm.widgets.archiver_time_plot import FormulaCurveItem
from widgets import (ArchiveSearchWidget, ColorButtonDelegate, ComboBoxDelegate,
DeleteRowDelegate, FloatDelegate, InsertPVDelegate)
from widgets import (
ArchiveSearchWidget,
ColorButtonDelegate,
ComboBoxDelegate,
DeleteRowDelegate,
FloatDelegate,
InsertPVDelegate
)
from table_models import ArchiverCurveModel
import numpy as np

Expand All @@ -23,8 +29,7 @@ def traces_table_init(self) -> None:
self.ui.traces_tbl.setModel(self.curves_model)

self.menu = PVContextMenu(self)
self.ui.traces_tbl.customContextMenuRequested.connect(
self.custom_context_menu)
self.ui.traces_tbl.customContextMenuRequested.connect(self.custom_context_menu)

hdr = self.ui.traces_tbl.horizontalHeader()
hdr.setSectionResizeMode(QHeaderView.Stretch)
Expand Down Expand Up @@ -206,10 +211,11 @@ def __init__(self, parent: QObject) -> None:
self.pv_list.setItemDelegateForColumn(self.curveModel.columnCount() - 1, insertButton)
layout.addWidget(self.pv_list)
layout.addWidget(self.field)

self.index = self.parent().selected_index

# Define the list of calculator buttons. It's a bunch of preset buttons, but users can type other functions under math.

# Define the list of calculator buttons.
# It's a bunch of preset buttons, but users can type other functions under math.
buttons = ["7", "8", "9", "+", "(", ")",
"4", "5", "6", "-", "^2", "sqrt()",
"1", "2", "3", "*", "^-1", "ln()",
Expand All @@ -225,9 +231,10 @@ def __init__(self, parent: QObject) -> None:
col = i % 6
grid_layout.addWidget(button, row, col)
# Connect the button clicked signal to the appropriate action
#PV currently does nothing, this is a remnant from when we would have the pv_list open in a new window
# PV currently does nothing, this is a remnant
# From when we would have the pv_list open in a new window
if button_text == "PV":
#TODO: Either give a function for this button or replace it
# TODO: Either give a function for this button or replace it
pass
elif button_text == "Clear":
button.clicked.connect(lambda _: self.field.clear())
Expand All @@ -240,28 +247,29 @@ def __init__(self, parent: QObject) -> None:
ok_button.clicked.connect(self.accept_formula)
layout.addWidget(ok_button)
def keyPressEvent(self, e: QKeyEvent) -> None:
#Special key press tracker, just so that if enter or return is pressed the formula dialog attempts to submit the formula
# Special key press tracker, just so that if enter or return is pressed the formula dialog attempts to submit the formula
if e.key() == Qt.Key_Return or e.key() == Qt.Key_Enter:
self.accept_formula()
return super().keyPressEvent(e)
def exec_(self):
#When the formula dialog is opened (every time) we need to update it with the latest information on the curve model and
#also populate the text box with the pre-existing formula (if it already was there)
# When the formula dialog is opened (every time) we need to
# update it with the latest information on the curve model and
# also populate the text box with the pre-existing formula (if it already was there)
self.index = self.parent().selected_index
self.pv_list.setRowHidden(len(self.curveModel._row_names) - 1, True)
for i in range(self.curveModel.rowCount() - 1):
self.pv_list.setRowHidden(i, False)
if self.index:
if self.index:
index = self.curveModel.index(self.index.row(), 0)
curve = self.curveModel._plot._curves[self.index.row()]
if index.data() and isinstance(curve, FormulaCurveItem):
self.field.setText(str(index.data()).strip("f://"))
else:
self.field.setText("")
self.field.setText("")
super().exec_()

def evaluate_formula(self, **kwargs: Dict[str, Any]) -> None:
#This function isn't used. Used to be there when an '=' existed in the calculator.
# This function isn't used. Used to be there when an '=' existed in the calculator.
# Evaluate the formula expression and update the formula input field
# TODO: Check if PVs used are in Table Model
# if yes, replace with row header; if no, add to TableModel and replace with row header
Expand Down

0 comments on commit 85287b7

Please sign in to comment.