Commit 23eaacbb authored by Benjamin Mummery's avatar Benjamin Mummery 💻

added framework for charts tab with dummy data

parent 87070577
......@@ -14,10 +14,10 @@ repos:
hooks:
- id: black
language_version: python3.7
- repo: https://github.com/timothycrosley/isort
rev: 5.0.8
hooks:
- id: isort
# - repo: https://github.com/timothycrosley/isort
# rev: 5.0.8
# hooks:
# - id: isort
- repo: https://github.com/pycqa/pylint
rev: pylint-2.6.0
hooks:
......
......@@ -18,27 +18,23 @@ __email__ = "benjamin.mummery@stfc.ac.uk"
__status__ = "Prototype"
import argparse
import git
import json
import logging
import sys
import os
from PySide2 import QtCore
import re
import sys
from threading import Lock
import git
import numpy as np
from global_widgets.global_send_popup import confirmPopup
from hevclient import HEVClient
from ui_layout import Layout
from ui_widgets import Widgets
from threading import Lock
from PySide2 import QtCore
from PySide2.QtCore import Signal, Slot
from PySide2.QtGui import QColor, QFont, QPalette
from PySide2.QtWidgets import QApplication, QMainWindow, QWidget
from ui_layout import Layout
from ui_widgets import Widgets
logging.basicConfig(
level=logging.INFO,
......@@ -165,6 +161,12 @@ class NativeUI(HEVClient, QMainWindow):
for button in self.widgets.page_buttons.buttons:
button.PageButtonPressed.connect(self.change_page)
for button in self.widgets.chart_buttons_widget.buttons:
button.ToggleButtonPressed.connect(self.widgets.charts_widget.show_line)
button.ToggleButtonReleased.connect(self.widgets.charts_widget.hide_line)
button.on_press() # Ensure states of the plots match states of buttons.
button.toggle()
# Plot data should update on a timer
# TODO: make this actually grab the data and send it to the plots, rather than
# having the plots reach to NativeUI for the data.
......
......@@ -206,9 +206,17 @@ class Layout:
"""
Layout for the settings page.
"""
# Create the Charts tab
tab_charts = self.layout_tab_charts(
[self.widgets.charts_widget, self.widgets.chart_buttons_widget]
)
self.widgets.chart_buttons_widget.setFont(self.NativeUI.text_font)
self.widgets.chart_buttons_widget.set_size(self.left_bar_width, None)
# Create the stack
page_settings = SwitchableStackWidget(
self.NativeUI,
[self.widgets.settings_expert_tab, self.widgets.settings_chart_tab],
[self.widgets.settings_expert_tab, tab_charts],
["Expert", "Charts"],
)
page_settings.setFont(self.NativeUI.text_font)
......@@ -285,6 +293,14 @@ class Layout:
tab_main_detailed.setLayout(tab_main_detailed_layout)
return tab_main_detailed
def layout_tab_charts(self, widgets: list) -> QtWidgets.QWidget:
tab_charts = QtWidgets.QWidget()
tab_charts_layout = QtWidgets.QHBoxLayout(tab_charts)
for widget in widgets:
tab_charts_layout.addWidget(widget)
tab_charts.setLayout(tab_charts_layout)
return tab_charts
def __make_stack(self, widgets):
"""
Make a stack of widgets
......
......@@ -13,29 +13,34 @@ __maintainer__ = "Benjamin Mummery"
__email__ = "benjamin.mummery@stfc.ac.uk"
__status__ = "Prototype"
from PySide2.QtWidgets import QWidget
from alarm_widgets.tab_alarm_table import TabAlarmTable
from alarm_widgets.tab_alarms import TabAlarm
from alarm_widgets.tab_clinical import TabClinical
from global_widgets.tab_modeswitch_button import TabModeswitchButton
from mode_widgets.tab_modes import TabModes
from mode_widgets.tab_personal import TabPersonal
from PySide2.QtWidgets import QWidget
from widget_library.battery_display_widget import BatteryDisplayWidget
# from widget_library.tab_charts import TabChart
from widget_library.chart_buttons_widget import ChartButtonsWidget
from widget_library.history_buttons_widget import HistoryButtonsWidget
from widget_library.measurements_widget import (
NormalMeasurementsBlockWidget,
ExpertMeasurementsBloackWidget,
NormalMeasurementsBlockWidget,
)
from widget_library.plot_widget import TimePlotsWidget, CirclePlotsWidget
from widget_library.spin_buttons_widget import SpinButtonsWidget
from widget_library.page_buttons_widget import PageButtonsWidget
from widget_library.personal_display_widget import PersonalDisplayWidget
from widget_library.battery_display_widget import BatteryDisplayWidget
from widget_library.plot_widget import (
ChartsPlotWidget,
CirclePlotsWidget,
TimePlotsWidget,
)
from widget_library.spin_buttons_widget import SpinButtonsWidget
from widget_library.tab_expert import TabExpert
from widget_library.ventilator_start_stop_buttons_widget import (
VentilatorStartStopButtonsWidget,
)
from widget_library.tab_expert import TabExpert
from widget_library.tab_charts import TabChart
from mode_widgets.tab_modes import TabModes
from mode_widgets.tab_personal import TabPersonal
from alarm_widgets.tab_alarms import TabAlarm
from alarm_widgets.tab_alarm_table import TabAlarmTable
from alarm_widgets.tab_clinical import TabClinical
class Widgets:
......@@ -75,7 +80,9 @@ class Widgets:
# Settings Page Widgets
self.settings_expert_tab = TabExpert(NativeUI)
self.settings_chart_tab = TabChart(NativeUI)
self.charts_widget = ChartsPlotWidget(colors=NativeUI.colors)
self.chart_buttons_widget = ChartButtonsWidget(colors=NativeUI.colors)
# self.settings_chart_tab = TabChart(NativeUI)
# Modes Page Widgets
self.mode_settings_tab = TabModes(NativeUI)
......
#!/usr/bin/env python3
"""
chart_buttons_widget.py
"""
__author__ = ["Benjamin Mummery", "Tiago Sarmento"]
__credits__ = ["Benjamin Mummery", "Dónal Murray", "Tim Powell", "Tiago Sarmento"]
__license__ = "GPL"
__version__ = "0.0.1"
__maintainer__ = "Benjamin Mummery"
__email__ = "benjamin.mummery@stfc.ac.uk"
__status__ = "Development"
from PySide2 import QtGui, QtWidgets
from PySide2.QtCore import QSize, Signal, Slot
class ChartButtonsWidget(QtWidgets.QWidget):
def __init__(self, *args, colors: dict = {}, **kwargs):
super().__init__(*args, **kwargs)
self.buttons = [
ToggleButtonWidget("Pressure", signal_value="pressure"),
ToggleButtonWidget("Flow", signal_value="flow"),
]
stylesheet = (
"QPushButton{"
" background-color:" + colors["button_background_enabled"].name() + ";"
" color:" + colors["button_foreground_enabled"].name() + ";"
" border: none"
"}"
"QPushButton:checked{"
" background-color:" + colors["button_background_disabled"].name() + ";"
" color:" + colors["button_foreground_enabled"].name() + ";"
" border: none"
"}"
)
for button in self.buttons:
button.setStyleSheet(stylesheet)
# Layout buttons block
grid = QtWidgets.QGridLayout()
i_row = 0
i_col = 0
for widget in self.buttons:
grid.addWidget(widget, i_row, i_col)
i_row += 1
self.setLayout(grid)
def set_size(self, x: int, y: int, spacing: int = 10) -> int:
"""
Set the size of the widget and its subwidgets.
"""
pass
def setFont(self, font: QtGui.QFont) -> int:
"""
Overrides the existing setFont method in order to propogate the change to
subwidgets.
"""
for button in self.buttons:
button.setFont(font)
return 0
class ToggleButtonWidget(QtWidgets.QPushButton):
"""
Variant of the QPushButton that emits a signal containing a string (signal_value)
"""
ToggleButtonPressed = Signal(str)
ToggleButtonReleased = Signal(str)
def __init__(self, *args, signal_value: str = None, **kwargs):
super().__init__(*args, **kwargs)
self.__signal_value = signal_value
self.setCheckable(True)
self.pressed.connect(self.on_press)
def on_press(self) -> int:
"""
When the button is pressed, emit the either the ToggleButtonPressed or
ToggleButtonReleased signal depending on whether the button was in the checked
or unchacked state.
"""
if self.isChecked(): # active -> inactive
self.ToggleButtonReleased.emit(self.__signal_value)
else: # inactive -> active
self.ToggleButtonPressed.emit(self.__signal_value)
return 0
......@@ -144,7 +144,7 @@ class HistoryButton(QtWidgets.QPushButton):
HistoryButtonPressed = Signal(int)
def __init__(self, *args, signal_value=None, **kwargs):
def __init__(self, *args, signal_value: int = None, **kwargs):
super().__init__(*args, **kwargs)
self.__signal_value = signal_value
self.pressed.connect(self.on_press)
......
......@@ -19,7 +19,7 @@ import logging
import numpy as np
import pyqtgraph as pg
from pyqtgraph import mkColor
from PySide2 import QtCore, QtWidgets
from PySide2 import QtCore, QtGui, QtWidgets
class TimePlotsWidget(QtWidgets.QWidget):
......@@ -247,3 +247,84 @@ class CirclePlotsWidget(QtWidgets.QWidget):
plot.setXRange(self.time_range * (-1), 0, padding=0)
plot.enableAutoRange("y", True)
return 0
class ChartsPlotWidget(QtWidgets.QWidget):
def __init__(self, port=54322, *args, colors: dict = {}, **kwargs):
super().__init__(*args, **kwargs)
self.port = port
layout = QtWidgets.QHBoxLayout()
# Set up the graph widget
self.graph_widget = pg.GraphicsLayoutWidget()
layout.addWidget(self.graph_widget)
# Add the plot axes to the graph widget
self.display_plot = self.graph_widget.addPlot(
labels={"left": "????", "bottom": "????"}
)
self.graph_widget.nextRow()
# Store plots in a list in case we need to add additional axes in the future.
plots = [self.display_plot]
# Create lines
self.lines = {
"pressure": self.plot(
self.display_plot, [0, 10], [5, -5], "pressure", (0, 0, 0, 0)
),
"flow": self.plot(
self.display_plot,
[0, 2, 4, 6, 8, 10],
[3, 1, 4, 1, 5, 9],
"flow",
(0, 0, 0, 0),
),
}
# Store the colors of the lines
self.colors = {"pressure": colors["pressure_plot"], "flow": colors["flow_plot"]}
self.graph_widget.setContentsMargins(0.0, 0.0, 0.0, 0.0)
self.graph_widget.setBackground(colors["page_background"])
self.legends = []
for plot in plots:
plot.showGrid(x=True, y=True)
plot.hideButtons()
plot.setMouseEnabled(x=False, y=False)
self.legends.append(plot.addLegend(offset=(-1, 1)))
self.setLayout(layout)
self.hide_line("pressure")
self.show_line("pressure")
def setFont(self, font: QtGui.QFont) -> int:
for l in self.legends:
l.setFont(font)
return 0
def update_plot_data(self):
pass
def plot(self, canvas, x, y, plotname, color):
pen = pg.mkPen(color=color, width=3)
return canvas.plot(x, y, name=plotname, pen=pen)
@QtCore.Slot(str)
def show_line(self, key: str) -> int:
"""
Show the specified line
"""
self.lines[key].setPen(pg.mkPen(color=self.colors[key], width=3))
return 0
@QtCore.Slot(str)
def hide_line(self, key: str) -> int:
"""
Hide the specified line
"""
self.lines[key].setPen(pg.mkPen(color=(0, 0, 0, 0), width=0))
return 0
#!/usr/bin/env python3
"""
tab_charts.py
"""
__author__ = ["Benjamin Mummery", "Tiago Sarmento"]
__credits__ = ["Benjamin Mummery", "Dónal Murray", "Tim Powell", "Tiago Sarmento"]
__license__ = "GPL"
__version__ = "0.0.1"
__maintainer__ = "Tiago Sarmento"
__email__ = "tiago.sarmento@stfc.ac.uk"
__status__ = "Development"
from PySide2 import QtWidgets, QtGui, QtCore
import sys
class TabChart(
QtWidgets.QWidget
): # chose QWidget over QDialog family because easier to modify
def __init__(self, *args, **kwargs):
super(TabChart, self).__init__(*args, **kwargs)
label = QtWidgets.QLabel("charting")
vlayout = QtWidgets.QVBoxLayout()
vlayout.addWidget(label)
self.setLayout(vlayout)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment