-
Notifications
You must be signed in to change notification settings - Fork 11
/
sigvisualizer.py
82 lines (65 loc) · 2.94 KB
/
sigvisualizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import sys
from PyQt5.QtCore import QSize, Qt, pyqtSignal
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (QApplication, QMainWindow, QStatusBar,
QTreeWidgetItem)
from ui_sigvisualizer import Ui_MainWindow
class SigVisualizer(QMainWindow):
stream_expanded = pyqtSignal(str)
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.setWindowTitle('Real Time Signal Visualizer')
self.ui.treeWidget.setHeaderLabel('Streams')
self.setWindowIcon(QIcon('sigvisualizer.ico'))
self.statusBar = QStatusBar()
self.setStatusBar(self.statusBar)
self.ui.toggleButton.setIcon(QIcon("icons/chevron_left.svg"))
self.ui.toggleButton.setIconSize(QSize(30, 30))
self.ui.toggleButton.clicked.connect(self.toggle_panel)
self.ui.updateButton.clicked.connect(
self.ui.widget.dataTr.update_streams)
self.ui.widget.dataTr.updateStreamNames.connect(
self.update_metadata_widget)
self.panelHidden = False
self.ui.treeWidget.itemExpanded.connect(self.tree_item_expanded)
self.stream_expanded.connect(self.ui.widget.dataTr.handle_stream_expanded)
def tree_item_expanded(self, widget_item):
name = widget_item.text(0)
for it_ix in range(self.ui.treeWidget.topLevelItemCount()):
item = self.ui.treeWidget.topLevelItem(it_ix)
if item.text(0) != name:
item.setExpanded(False)
self.stream_expanded.emit(name)
def update_metadata_widget(self, metadata, default_idx):
for s_ix, s_meta in enumerate(metadata):
item = QTreeWidgetItem(self.ui.treeWidget)
item.setText(0, s_meta["name"])
for m in range(s_meta["ch_count"]):
channel_item = QTreeWidgetItem(item)
channel_item.setText(0, 'Channel {}'.format(m+1))
channel_item.setCheckState(0, Qt.Checked)
item.setExpanded(True if s_ix == default_idx else False)
self.ui.treeWidget.addTopLevelItem(item)
self.ui.treeWidget.setAnimated(True)
self.statusBar.showMessage(
"Sampling rate: {}Hz".format(metadata[default_idx]["srate"]))
def toggle_panel(self):
if self.panelHidden:
self.panelHidden = False
self.ui.treeWidget.show()
self.ui.updateButton.show()
self.ui.toggleButton.setIcon(QIcon("icons/chevron_left.svg"))
self.ui.toggleButton.setIconSize(QSize(30, 30))
else:
self.panelHidden = True
self.ui.treeWidget.hide()
self.ui.updateButton.hide()
self.ui.toggleButton.setIcon(QIcon("icons/chevron_right.svg"))
self.ui.toggleButton.setIconSize(QSize(30, 30))
if __name__ == '__main__':
app = QApplication(sys.argv)
window = SigVisualizer()
window.show()
sys.exit(app.exec_())