2023-09-19 19:17:22 +00:00
|
|
|
import random
|
2023-06-20 02:21:47 +00:00
|
|
|
import sys
|
2023-07-06 02:16:22 +00:00
|
|
|
import logging
|
2023-06-20 02:21:47 +00:00
|
|
|
|
|
|
|
import pyqtgraph.parametertree
|
|
|
|
from PySide6 import QtWidgets, QtCore
|
2023-09-19 19:17:22 +00:00
|
|
|
from PySide6.QtCore import QDir, Qt, QObject, Slot, Signal, QTimer
|
|
|
|
from PySide6.QtGui import QAction
|
2023-06-20 02:21:47 +00:00
|
|
|
from PySide6.QtWidgets import (
|
|
|
|
QApplication,
|
|
|
|
QWidget,
|
|
|
|
QMainWindow,
|
|
|
|
QTreeView,
|
2023-09-19 19:17:22 +00:00
|
|
|
QDockWidget, QToolBar, QPlainTextEdit,
|
2023-06-20 02:21:47 +00:00
|
|
|
)
|
2023-09-19 19:17:22 +00:00
|
|
|
from gui_log import QLogHandler
|
|
|
|
from pytelem.widgets.smart_display import SmartDisplay
|
2023-07-05 23:55:29 +00:00
|
|
|
from bms import BMSOverview
|
|
|
|
|
2023-07-06 02:16:22 +00:00
|
|
|
|
2023-09-19 19:17:22 +00:00
|
|
|
class DataStore(QObject):
|
2023-07-06 02:16:22 +00:00
|
|
|
"""Stores all packets and timestamps for display and logging.
|
|
|
|
Queries the upstreams for the packets as they come in as well as historical"""
|
2023-09-19 19:17:22 +00:00
|
|
|
|
2023-07-06 02:16:22 +00:00
|
|
|
def __init__(self, remote):
|
2023-09-19 19:17:22 +00:00
|
|
|
super().__init__()
|
|
|
|
|
2023-06-20 02:21:47 +00:00
|
|
|
|
|
|
|
class MainApp(QMainWindow):
|
2023-09-19 19:17:22 +00:00
|
|
|
new_data = Signal(float)
|
|
|
|
|
2023-06-20 02:21:47 +00:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2023-09-19 19:17:22 +00:00
|
|
|
self.setWindowTitle("pyview")
|
2023-07-05 23:55:29 +00:00
|
|
|
layout = QtWidgets.QVBoxLayout()
|
|
|
|
|
2023-09-19 19:17:22 +00:00
|
|
|
mb = self.menuBar()
|
|
|
|
self.WindowMenu = mb.addMenu("Windows")
|
|
|
|
|
2023-07-05 23:55:29 +00:00
|
|
|
bms = BMSOverview()
|
2023-09-19 19:17:22 +00:00
|
|
|
packet_tree = QDockWidget('Packet Tree', self)
|
|
|
|
self.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea, packet_tree)
|
|
|
|
packet_tree.setWidget(PacketTreeView())
|
|
|
|
packet_tree.hide()
|
|
|
|
self.ShowPacketTree = packet_tree.toggleViewAction()
|
|
|
|
self.WindowMenu.addAction(self.ShowPacketTree)
|
|
|
|
|
|
|
|
log_dock = QDockWidget('Application Log', self)
|
|
|
|
self.qlogger = QLogHandler()
|
|
|
|
self.log_box = QPlainTextEdit()
|
|
|
|
self.log_box.setReadOnly(True)
|
|
|
|
log_dock.setWidget(self.log_box)
|
|
|
|
self.qlogger.bridge.log.connect(self.log_box.appendPlainText)
|
|
|
|
self.addDockWidget(Qt.DockWidgetArea.BottomDockWidgetArea, log_dock)
|
|
|
|
|
|
|
|
self.logger = logging.Logger("Main")
|
|
|
|
self.logger.addHandler(self.qlogger)
|
|
|
|
self.logger.info("hi there!")
|
|
|
|
self.ShowLog = log_dock.toggleViewAction()
|
|
|
|
self.ShowLog.setShortcut("CTRL+L")
|
|
|
|
self.WindowMenu.addAction(self.ShowLog)
|
|
|
|
self.display = SmartDisplay(self, "test")
|
|
|
|
self.new_data.connect(self.display.update_value)
|
|
|
|
# start a qtimer to generate random data.
|
|
|
|
self.timer = QTimer(parent=self)
|
|
|
|
self.timer.timeout.connect(self.__random_data)
|
|
|
|
# self.__random_data.connect(self.timer.timeout)
|
|
|
|
self.timer.start(100)
|
2023-06-20 02:21:47 +00:00
|
|
|
|
2023-09-19 19:17:22 +00:00
|
|
|
self.setCentralWidget(self.display)
|
2023-06-20 02:21:47 +00:00
|
|
|
|
2023-09-19 19:17:22 +00:00
|
|
|
@Slot()
|
|
|
|
def __random_data(self):
|
|
|
|
# emit random data to the new_data
|
|
|
|
yay = random.normalvariate(10, 1)
|
|
|
|
self.logger.info(yay)
|
|
|
|
self.new_data.emit(yay)
|
2023-06-20 02:21:47 +00:00
|
|
|
|
2023-09-19 19:17:22 +00:00
|
|
|
|
|
|
|
class PacketTreeView(QWidget):
|
2023-06-20 02:21:47 +00:00
|
|
|
"""PacketView is a widget that shows a tree of packets as well as properties on them when selected."""
|
|
|
|
|
|
|
|
def __init__(self, parent: QtWidgets.QWidget | None = None):
|
|
|
|
super().__init__(parent)
|
|
|
|
self.setWindowTitle("Packet Overview")
|
|
|
|
splitter = QtWidgets.QSplitter(self)
|
|
|
|
layout = QtWidgets.QVBoxLayout()
|
|
|
|
|
2023-09-19 19:17:22 +00:00
|
|
|
# splitter.setOrientation(Qt.Vertical)
|
2023-06-20 02:21:47 +00:00
|
|
|
self.tree = QTreeView()
|
|
|
|
self.prop_table = pyqtgraph.parametertree.ParameterTree()
|
|
|
|
splitter.addWidget(self.tree)
|
|
|
|
splitter.addWidget(self.prop_table)
|
|
|
|
layout.addWidget(splitter)
|
|
|
|
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
|
2023-09-19 19:17:22 +00:00
|
|
|
class SolverView(QWidget):
|
|
|
|
"""Main Solver Widget/Window"""
|
|
|
|
|
|
|
|
|
2023-06-20 02:21:47 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
main_window = MainApp()
|
|
|
|
main_window.show()
|
|
|
|
app.exec()
|