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: UI Footer #23

Merged
merged 9 commits into from
Aug 26, 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
56 changes: 52 additions & 4 deletions archive_viewer/archive_viewer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from functools import partial
import os
from logging import (Handler, LogRecord)
from subprocess import run
from qtpy.QtCore import Slot
from qtpy.QtWidgets import (QAbstractButton, QApplication)
from qtpy.QtWidgets import (QAbstractButton, QApplication, QLabel)
from pydm import Display
from config import logger
from config import (logger, datetime_pv)
from mixins import (TracesTableMixin, AxisTableMixin, FileIOMixin)
from styles import CenterCheckStyle

Expand All @@ -11,6 +13,10 @@ class ArchiveViewer(Display, TracesTableMixin, AxisTableMixin, FileIOMixin):
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)
self.set_footer()

app = QApplication.instance()
app.setStyle(CenterCheckStyle())

self.ui.main_spltr.setCollapsible(0, False)
self.ui.main_spltr.setStretchFactor(0, 1)
Expand All @@ -28,7 +34,7 @@ def __init__(self, parent=None, args=None, macros=None, ui_filename=__file__.rep
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))
self.ui.timespan_btns.buttonClicked.connect(self.set_plot_timerange)

plot_viewbox = self.ui.archiver_plot.plotItem.vb
plot_viewbox.sigRangeChangedManually.connect(self.ui.cursor_scale_btn.click)
Expand All @@ -41,6 +47,21 @@ def file_menu_items(self) -> dict:
return {"save": (self.export_save_file, "Ctrl+S"),
"load": (self.import_save_file, "Ctrl+L")}

def set_footer(self):
"""Set footer information for application. Includes logging, nodename,
username, PID, git version, Archiver URL, and current datetime
"""
self.logging_handler = LoggingHandler(self.ui.ftr_logging_lbl)
logger.addHandler(self.logging_handler)
logger.setLevel("NOTSET")

self.ui.ftr_node_lbl.setText(os.uname().nodename)
self.ui.ftr_user_lbl.setText(os.getlogin())
self.ui.ftr_pid_lbl.setText(str(os.getpid()))
self.ui.ftr_ver_lbl.setText(self.git_version())
self.ui.ftr_url_lbl.setText(os.getenv('PYDM_ARCHIVER_URL'))
self.ui.ftr_time_lbl.channel = "ca://" + datetime_pv

@Slot(QAbstractButton)
def set_plot_timerange(self, button: QAbstractButton) -> None:
"""Slot to be called when a timespan setting button is pressed.
Expand All @@ -54,11 +75,38 @@ def set_plot_timerange(self, button: QAbstractButton) -> None:
The timespan setting button pressed. Determines which timespan
to set.
"""
logger.debug(f"Setting plot timerange")
if button not in self.button_spans:
logger.error(f"{button} is not a valid timespan button")
return

enable_scroll = (button != self.ui.cursor_scale_btn)
timespan = self.button_spans[button]
if enable_scroll:
logger.debug(f"Enabling plot autoscroll for {timespan}s")
else:
logger.debug("Disabling plot autoscroll, using mouse controls")

self.ui.archiver_plot.setAutoScroll(enable_scroll, timespan)

@staticmethod
def git_version():
"""Get the current git tag for the project"""
project_directory = __file__.rsplit('/', 1)[0]
git_cmd = run(f"cd {project_directory} && git describe --tags",
text=True,
shell=True,
capture_output=True)
return git_cmd.stdout.strip()


class LoggingHandler(Handler):
def __init__(self, logging_lbl: QLabel, level: int=0) -> None:
super().__init__(level)
self.logging_lbl = logging_lbl

def emit(self, record: LogRecord):
log = record.msg
if record.levelno > 20:
log = f"[{record.levelname}] - {log}"
self.logging_lbl.setText(log)
Loading
Loading