feat: 添加上证所截图功能并优化股票数据获取
- 新增上证所网页元素截图功能,使用Playwright实现 - 优化股票数据获取方式,改用新浪财经JS接口 - 调整情感分析评分规则为7级分类 - 添加截图显示组件到主界面 - 更新依赖项,替换playwright为selenium
This commit is contained in:
@@ -4,9 +4,9 @@ PySide6 GUI界面模块
|
||||
from PySide6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QLabel,
|
||||
QPushButton, QSlider, QDialog, QFormLayout,
|
||||
QLineEdit, QSpinBox, QMessageBox, QSystemTrayIcon,
|
||||
QMenu, QTextEdit, QGroupBox, QDialogButtonBox, QCheckBox)
|
||||
QMenu, QTextEdit, QGroupBox, QDialogButtonBox, QCheckBox, QScrollArea)
|
||||
from PySide6.QtCore import Qt, QTimer, Signal, QPoint
|
||||
from PySide6.QtGui import QFont, QColor, QPainter, QBrush, QPen, QIcon, QAction
|
||||
from PySide6.QtGui import QFont, QColor, QPainter, QBrush, QPen, QIcon, QAction, QPixmap
|
||||
from typing import Callable, Optional
|
||||
from loguru import logger
|
||||
|
||||
@@ -95,16 +95,20 @@ class SentimentIndicator(QWidget):
|
||||
|
||||
def get_description(self, score: int) -> str:
|
||||
"""获取描述文本"""
|
||||
if score < 20:
|
||||
return "极度看跌"
|
||||
elif score < 40:
|
||||
if score < 30:
|
||||
return "极度悲观"
|
||||
elif score < 39:
|
||||
return "悲观"
|
||||
elif score < 45:
|
||||
return "偏悲观"
|
||||
elif score < 60:
|
||||
return "中性"
|
||||
elif score < 80:
|
||||
elif score < 55:
|
||||
return "中立"
|
||||
elif score < 65:
|
||||
return "偏乐观"
|
||||
elif score < 70:
|
||||
return "乐观"
|
||||
else:
|
||||
return "极度看涨"
|
||||
return "极度乐观"
|
||||
|
||||
|
||||
class ConfigDialog(QDialog):
|
||||
@@ -263,6 +267,22 @@ class MainWindow(QWidget):
|
||||
self.waveform_widget = WaveformWidget()
|
||||
self.waveform_widget.setMinimumHeight(200)
|
||||
|
||||
# 上证所截图显示
|
||||
screenshot_group = QGroupBox("上证所行情")
|
||||
screenshot_layout = QVBoxLayout(screenshot_group)
|
||||
|
||||
self.screenshot_label = QLabel("等待截图...")
|
||||
self.screenshot_label.setAlignment(Qt.AlignCenter)
|
||||
self.screenshot_label.setMinimumSize(400, 200)
|
||||
self.screenshot_label.setStyleSheet("border: 1px solid #ccc; background-color: #f0f0f0;")
|
||||
|
||||
screenshot_scroll = QScrollArea()
|
||||
screenshot_scroll.setWidget(self.screenshot_label)
|
||||
screenshot_scroll.setWidgetResizable(True)
|
||||
screenshot_scroll.setMinimumHeight(150)
|
||||
|
||||
screenshot_layout.addWidget(screenshot_scroll)
|
||||
|
||||
# 按钮
|
||||
btn_layout = QHBoxLayout()
|
||||
self.refresh_btn = QPushButton("刷新")
|
||||
@@ -279,6 +299,7 @@ class MainWindow(QWidget):
|
||||
layout.addWidget(self.score_label)
|
||||
layout.addWidget(self.status_label)
|
||||
layout.addWidget(self.waveform_widget)
|
||||
layout.addWidget(screenshot_group)
|
||||
layout.addLayout(btn_layout)
|
||||
|
||||
# 设置窗口标志(无边框、可拖拽)
|
||||
@@ -426,6 +447,22 @@ class MainWindow(QWidget):
|
||||
self.waveform_widget.add_data_point(time_str, value)
|
||||
logger.info(f"添加波形图数据点: 时间={time_str}, 值={value}")
|
||||
|
||||
def update_sse_screenshot(self, screenshot_path: str):
|
||||
"""更新上证所截图显示"""
|
||||
logger.info(f"更新截图显示: {screenshot_path}")
|
||||
pixmap = QPixmap(screenshot_path)
|
||||
if not pixmap.isNull():
|
||||
self.screenshot_label.setPixmap(pixmap.scaled(
|
||||
self.screenshot_label.size(),
|
||||
Qt.KeepAspectRatio,
|
||||
Qt.SmoothTransformation
|
||||
))
|
||||
self.screenshot_label.setText("")
|
||||
logger.info("截图显示更新成功")
|
||||
else:
|
||||
self.screenshot_label.setText("截图加载失败")
|
||||
logger.warning("截图加载失败")
|
||||
|
||||
|
||||
class QCheckBox(QPushButton):
|
||||
"""自定义复选框"""
|
||||
|
||||
Reference in New Issue
Block a user