-
Notifications
You must be signed in to change notification settings - Fork 0
/
ticker_sandbox_qt.py
74 lines (61 loc) · 2.49 KB
/
ticker_sandbox_qt.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
from PySide6.QtCharts import QLineSeries, QChart, QChartView
from PySide6.QtCore import QPoint
from PySide6.QtGui import QPainter
from PySide6.QtWidgets import QDialog, QVBoxLayout, QLabel, QHBoxLayout, QComboBox, QPushButton
from storage_provider import StorageProvider
class Sandbox(QDialog):
def __init__(self, parent=None):
super(Sandbox, self).__init__(parent)
self.setWindowTitle("Sandbox")
self.symbol_label = QLabel("Symbols")
self.symbol_selector = QComboBox()
self.clear_button = QPushButton("Clear Display")
interactor_layout = self._init_interactors()
self.chart = QChart()
self.chart.createDefaultAxes()
self._line_series = []
self._chart_view = QChartView(self.chart)
main_layout = QVBoxLayout()
self.setLayout(main_layout)
main_layout.addLayout(interactor_layout)
main_layout.addLayout(self._init_data_display())
self.setBaseSize(800, 800)
def _init_interactors(self):
selector_layout = QHBoxLayout()
selector_layout.addWidget(self.symbol_label)
selector_layout.addWidget(self.symbol_selector)
selector_layout.addStretch()
clear_button_layout = QHBoxLayout()
clear_button_layout.addWidget(self.clear_button)
clear_button_layout.addStretch()
box_layout = QVBoxLayout()
box_layout.addLayout(selector_layout)
box_layout.addLayout(clear_button_layout)
db = StorageProvider()
symbols = db.get_all_symbols()
self.symbol_selector.addItems(symbols)
self.symbol_selector.currentIndexChanged.connect(self._load_history)
self.clear_button.clicked.connect(self._clear_display)
return box_layout
def _init_data_display(self):
data_layout = QHBoxLayout()
self._chart_view.setRenderHint(QPainter.Antialiasing)
data_layout.addWidget(self._chart_view)
return data_layout
def _load_history(self):
db = StorageProvider()
ticker = self.symbol_selector.currentText()
history = db.get_ticker_history(ticker)
line = QLineSeries()
line.setName(ticker)
i = 0
for date, price in history:
line.append(QPoint(i, price))
i += 1
self._line_series.append(line)
self.chart.addSeries(line)
self.chart.createDefaultAxes()
self.chart.axisX().hide()
def _clear_display(self):
self.chart.removeAllSeries()
self.chart.axisY().hide()