-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqtWindow.py
139 lines (102 loc) · 4.43 KB
/
qtWindow.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import sys
import os
import time
from PyQt5.QtWidgets import *
from PyQt5 import uic
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt, QRect, QEvent, QObject
from PyQt5.QtGui import QScreen, QGuiApplication
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from jdChart import JdChart
from jdGlobal import ui_folder
ui_path = os.path.join(ui_folder, 'qtWindow.ui')
form_class = uic.loadUiType(ui_path)[0]
class JdWindowClass(QMainWindow, form_class):
def __init__(self):
super().__init__()
self.setupUi(self)
self.chart : JdChart = None
screen = QGuiApplication.primaryScreen()
screen_size = screen.availableSize()
window_width = screen_size.width() * 0.9 # 전체 화면 폭의 80%
window_height = screen_size.height() * 0.9 # 전체 화면 높이의 80%
self.resize(window_width, window_height)
self.label : QLabel
self.setWindowTitle("Jidon stock helper")
self.lineEdit_search : QLineEdit
self.lineEdit_search.returnPressed.connect(self.on_lienEdit_search_returnPressed)
self.checkbox_ma10 : QCheckBox
self.checkbox_ma20 : QCheckBox
self.checkbox_ema10 : QCheckBox
self.checkbox_ema21 : QCheckBox
self.checkbox_ma10.stateChanged.connect(self.on_ma_checkbox_changed)
self.checkbox_ma20.stateChanged.connect(self.on_ma_checkbox_changed)
self.checkbox_ema10.stateChanged.connect(self.on_ma_checkbox_changed)
self.checkbox_ema21.stateChanged.connect(self.on_ma_checkbox_changed)
self.setFocusPolicy(Qt.StrongFocus)
def set_chart_class(self, inChartClass : JdChart):
self.chart = inChartClass
fig = self.chart.draw_stock_chart()
self.set_canvas(fig)
def refresh_canvas(self):
#self.canvas.updateGeometry()
self.canvas.draw()
def set_canvas(self, inFig : Figure):
# FigureCanvas 생성 및 설정
self.canvas = FigureCanvasQTAgg(inFig)
self.canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.canvas.setParent(self.label)
print('canvas size hint: ', self.canvas.sizeHint())
print('label size: ', self.label.size().width(), self.label.size().height())
self.canvas.setFixedSize(self.label.size())
self.refresh_canvas()
def on_lienEdit_search_returnPressed(self):
targetTicker = self.lineEdit_search.text()
print(targetTicker)
res = self.chart.move_to_ticker_stock(targetTicker)
if res:
self.chart.move_to_ticker_stock(targetTicker)
self.chart.draw_stock_chart()
self.refresh_canvas()
def on_ma_checkbox_changed(self):
bMa10Checked = self.checkbox_ma10.isChecked()
bMa20Checked = self.checkbox_ma20.isChecked()
beEma10Checked = self.checkbox_ema10.isChecked()
beEma21Checked = self.checkbox_ema21.isChecked()
self.chart.set_ma_visibility(bMa10Checked, bMa20Checked, beEma10Checked, beEma21Checked)
self.chart.draw_stock_chart()
self.refresh_canvas()
def keyPressEvent(self, event):
start_time = time.time()
key = event.key()
if event.key() == Qt.Key_Escape:
#print('Qt.Key_Escape')
self.chart.on_close(event)
self.close()
sys.exit(1)
elif event.key() == Qt.Key_Right:
#print('Qt.Key_Right')
self.chart.move_to_next_stock()
self.chart.draw_stock_chart()
self.refresh_canvas()
elif event.key() == Qt.Key_Left:
#print('Qt.Key_Left')
self.chart.move_to_prev_stock()
self.chart.draw_stock_chart()
self.refresh_canvas()
elif event.key() == Qt.Key_Return:
#print('Qt.Key_Return')
if not self.lineEdit_search.hasFocus():
self.chart.mark_ticker()
elapsedTime = time.time() - start_time
#print('keyPressEvent handling time : ', elapsedTime)
# if __name__ == "__main__" :
# #QApplication : 프로그램을 실행시켜주는 클래스
# app = QApplication(sys.argv)
# #WindowClass의 인스턴스 생성
# myWindow = JdWindowClass()
# #프로그램 화면을 보여주는 코드
# myWindow.show()
# #프로그램을 이벤트루프로 진입시키는(프로그램을 작동시키는) 코드
# app.exec_()