修复问题

This commit is contained in:
2026-04-03 23:56:36 +08:00
parent 17655f2dba
commit 104dfe9693
6 changed files with 161 additions and 5 deletions
+102
View File
@@ -7,6 +7,7 @@ import struct
import time as _time
import datetime
import urllib.request
import webbrowser
import qtawesome as qta
from PyQt6.QtWidgets import (
QWidget,
@@ -647,6 +648,14 @@ class PanelWindow(QWidget):
bottom_layout.setContentsMargins(6, 0, 6, 0)
bottom_layout.setSpacing(4)
self.menu_btn = QPushButton()
self.menu_btn.setFixedSize(28, 28)
self.menu_btn.setToolTip("菜单")
self.menu_btn.setStyleSheet(
"border:none; background:transparent; border-radius:4px;"
)
self.menu_btn.clicked.connect(self._show_bottom_menu)
self.theme_btn = QPushButton()
self.theme_btn.setFixedSize(28, 28)
self.theme_btn.setToolTip("切换亮/暗主题")
@@ -671,6 +680,7 @@ class PanelWindow(QWidget):
)
self.quit_btn.clicked.connect(self._quit_application)
bottom_layout.addWidget(self.menu_btn)
bottom_layout.addStretch()
bottom_layout.addWidget(self.theme_btn)
bottom_layout.addWidget(self.settings_btn)
@@ -787,6 +797,8 @@ class PanelWindow(QWidget):
qta.icon("fa5s.sun" if is_dark else "fa5s.moon", color=ic)
)
self.theme_btn.setIconSize(QSize(14, 14))
self.menu_btn.setIcon(qta.icon("fa5s.bars", color=ic))
self.menu_btn.setIconSize(QSize(14, 14))
self.settings_btn.setIcon(qta.icon("fa5s.cog", color=ic))
self.settings_btn.setIconSize(QSize(14, 14))
self.quit_btn.setIcon(qta.icon("fa5s.sign-out-alt", color=ic))
@@ -827,6 +839,96 @@ class PanelWindow(QWidget):
self._settings_win = SettingsWindow(self)
self._settings_win.show()
def _show_bottom_menu(self):
menu = QMenu(self)
menu.setStyleSheet(self._bottom_menu_stylesheet())
menu.addAction(self._make_doubao_icon(), "豆包会话").triggered.connect(
self._open_doubao_session
)
menu.addAction(
self._make_round_menu_icon("D", "#4d6bfe"), "DeepSeek"
).triggered.connect(
lambda: self._open_url_in_browser(
"https://chat.deepseek.com/", "DeepSeek"
)
)
menu.addAction(
self._make_round_menu_icon("G", "#4285f4"), "Gemini"
).triggered.connect(
lambda: self._open_url_in_browser(
"https://gemini.google.com/", "Gemini"
)
)
# 菜单贴近按钮下方显示,避免漂移到不自然位置
pos = self.menu_btn.mapToGlobal(self.menu_btn.rect().bottomLeft())
menu.exec(pos)
def _bottom_menu_stylesheet(self) -> str:
t = theme.current()
return f"""
QMenu {{
background: {t['menu_bg']};
color: {t['menu_color']};
border: 1px solid {t['menu_border']};
border-radius: 8px;
padding: 4px;
}}
QMenu::item {{
padding: 6px 14px;
border-radius: 5px;
background: transparent;
}}
QMenu::item:selected {{
background: {t['menu_selected']};
}}
QMenu::separator {{
height: 1px;
background: {t['menu_border']};
margin: 4px 8px;
}}
"""
def _make_doubao_icon(self) -> QIcon:
return self._make_round_menu_icon("豆", "#3b82f6", font_pt=9)
def _make_round_menu_icon(
self, letter: str, bg_hex: str, *, font_pt: int = 9
) -> QIcon:
pm = QPixmap(18, 18)
pm.fill(Qt.GlobalColor.transparent)
p = QPainter(pm)
p.setRenderHint(QPainter.RenderHint.Antialiasing)
p.setBrush(QBrush(QColor(bg_hex)))
p.setPen(Qt.PenStyle.NoPen)
p.drawEllipse(1, 1, 16, 16)
p.setPen(QPen(QColor("white")))
f = p.font()
f.setPointSize(font_pt)
f.setBold(True)
p.setFont(f)
p.drawText(pm.rect(), int(Qt.AlignmentFlag.AlignCenter), letter)
p.end()
return QIcon(pm)
def _open_url_in_browser(self, url: str, title: str) -> None:
try:
ok = webbrowser.open(url)
except Exception as e:
dialog_style.warning(
self, "打开失败", f"无法在默认浏览器中打开{title}:{e}"
)
return
if not ok:
dialog_style.warning(
self,
"打开失败",
f"系统未注册可用的默认浏览器,请手动在浏览器中打开{title}:\n{url}",
)
def _open_doubao_session(self):
"""用系统默认浏览器打开豆包会话页。"""
self._open_url_in_browser("https://www.doubao.com/chat/", "豆包")
def refresh_groups(self):
# 记录当前折叠状态
collapsed_ids = set()