327 lines
8.0 KiB
Python
327 lines
8.0 KiB
Python
import sys
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QStackedWidget, QHBoxLayout, QWidget
|
|
from PyQt5.QtCore import Qt
|
|
from views.login import LoginPage
|
|
from views.nav import NavBar
|
|
from views.app_center import AppCenter
|
|
from views.word_to_pdf import WordToPDFPage
|
|
from views.history import HistoryPage
|
|
from PyQt5.QtGui import QPalette, QColor
|
|
|
|
# 优化的暗色主题样式表
|
|
STYLES_TXT = """
|
|
/* ===== 全局样式 ===== */
|
|
QWidget {
|
|
font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
|
|
font-size: 14px;
|
|
color: #e2e8f0;
|
|
border: none;
|
|
}
|
|
|
|
/* 输入框 */
|
|
QLineEdit {
|
|
background-color: #2d3748;
|
|
border: 1px solid #4a5568;
|
|
border-radius: 6px;
|
|
padding: 10px;
|
|
color: #e2e8f0;
|
|
min-height: 40px;
|
|
}
|
|
|
|
QLineEdit:focus {
|
|
border-color: #818cf8;
|
|
outline: none;
|
|
}
|
|
|
|
/* 按钮通用样式 */
|
|
QPushButton {
|
|
background-color: #4f46e5;
|
|
color: white;
|
|
border-radius: 6px;
|
|
padding: 8px 16px;
|
|
border: none;
|
|
min-height: 35px;
|
|
font-weight: 500;
|
|
transition: all 0.2s ease;
|
|
}
|
|
|
|
QPushButton:hover {
|
|
background-color: #4338ca;
|
|
transform: translateY(-1px);
|
|
}
|
|
|
|
QPushButton:disabled {
|
|
background-color: #4a5568;
|
|
color: #a0aec0;
|
|
}
|
|
|
|
/* 列表控件 */
|
|
QListWidget {
|
|
background-color: #2d3748;
|
|
border: 1px solid #4a5568;
|
|
border-radius: 8px;
|
|
padding: 4px;
|
|
color: #e2e8f0;
|
|
outline: none;
|
|
}
|
|
|
|
QListWidget::item {
|
|
padding: 8px 12px;
|
|
border-bottom: 1px solid #4a5568;
|
|
}
|
|
|
|
QListWidget::item:selected {
|
|
background-color: rgba(129, 140, 248, 0.15);
|
|
color: #e2e8f0;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
/* 滚动条 */
|
|
QScrollBar:vertical {
|
|
background: #2d3748;
|
|
width: 10px;
|
|
border: none;
|
|
}
|
|
|
|
QScrollBar::handle:vertical {
|
|
background: #4a5568;
|
|
min-height: 20px;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
QScrollBar::handle:vertical:hover {
|
|
background: #718096;
|
|
}
|
|
|
|
QScrollBar::add-line:vertical,
|
|
QScrollBar::sub-line:vertical {
|
|
height: 0;
|
|
}
|
|
|
|
QScrollBar::add-page:vertical,
|
|
QScrollBar::sub-page:vertical {
|
|
background: none;
|
|
}
|
|
|
|
/* 标签 */
|
|
QLabel {
|
|
color: #e2e8f0;
|
|
background-color: transparent;
|
|
}
|
|
|
|
/* 菜单栏 */
|
|
QMenuBar {
|
|
background-color: #1a202c;
|
|
color: #e2e8f0;
|
|
border-bottom: 1px solid #2d3748;
|
|
}
|
|
|
|
QMenuBar::item {
|
|
background-color: transparent;
|
|
padding: 4px 10px;
|
|
}
|
|
|
|
QMenuBar::item:selected {
|
|
background-color: #4f46e5;
|
|
color: white;
|
|
}
|
|
|
|
QMenu {
|
|
background-color: #2d3748;
|
|
border: 1px solid #4a5568;
|
|
color: #e2e8f0;
|
|
padding: 4px;
|
|
}
|
|
|
|
QMenu::item {
|
|
padding: 6px 30px 6px 20px;
|
|
}
|
|
|
|
QMenu::item:selected {
|
|
background-color: #4f46e5;
|
|
color: white;
|
|
}
|
|
|
|
QMenu::separator {
|
|
height: 1px;
|
|
background: #4a5568;
|
|
margin: 4px 8px;
|
|
}
|
|
|
|
/* 进度条 */
|
|
QProgressBar {
|
|
border-radius: 4px;
|
|
height: 8px;
|
|
background-color: #2d3748;
|
|
border: 1px solid #4a5568;
|
|
text-align: center;
|
|
}
|
|
|
|
QProgressBar::chunk {
|
|
background-color: #4f46e5;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
/* 复选框 */
|
|
QCheckBox {
|
|
color: #e2e8f0;
|
|
spacing: 8px;
|
|
}
|
|
|
|
QCheckBox::indicator {
|
|
width: 16px;
|
|
height: 16px;
|
|
border: 1px solid #4a5568;
|
|
border-radius: 3px;
|
|
background-color: #2d3748;
|
|
}
|
|
|
|
QCheckBox::indicator:checked {
|
|
background-color: #4f46e5;
|
|
border: 1px solid #4f46e5;
|
|
}
|
|
|
|
/* 分组框 */
|
|
QGroupBox {
|
|
font-weight: bold;
|
|
background-color: #2d3748;
|
|
border: 1px solid #4a5568;
|
|
border-radius: 8px;
|
|
margin-top: 1.5ex;
|
|
padding-top: 10px;
|
|
}
|
|
|
|
QGroupBox::title {
|
|
subcontrol-origin: margin;
|
|
subcontrol-position: top left;
|
|
background-color: transparent;
|
|
padding: 0 3px;
|
|
left: 9px;
|
|
}
|
|
"""
|
|
|
|
|
|
class MainWindow(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.username = None
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
self.setWindowTitle("文档处理工具")
|
|
self.setGeometry(100, 100, 1200, 800)
|
|
self.setStyleSheet(STYLES_TXT)
|
|
|
|
# 设置暗色主题调色板
|
|
palette = QPalette()
|
|
palette.setColor(QPalette.Window, QColor(26, 32, 44)) # #1a202c
|
|
palette.setColor(QPalette.WindowText, QColor(226, 232, 240)) # #e2e8f0
|
|
palette.setColor(QPalette.Base, QColor(45, 55, 72)) # #2d3748
|
|
palette.setColor(QPalette.AlternateBase, QColor(42, 50, 65)) # #2a3241
|
|
palette.setColor(QPalette.ToolTipBase, QColor(26, 32, 44)) # #1a202c
|
|
palette.setColor(QPalette.ToolTipText, QColor(226, 232, 240)) # #e2e8f0
|
|
palette.setColor(QPalette.Text, QColor(226, 232, 240)) # #e2e8f0
|
|
palette.setColor(QPalette.Button, QColor(79, 70, 229)) # #4f46e5
|
|
palette.setColor(QPalette.ButtonText, QColor(226, 232, 240)) # #e2e8f0
|
|
palette.setColor(QPalette.BrightText, Qt.white)
|
|
palette.setColor(QPalette.Link, QColor(129, 140, 248)) # #818cf8
|
|
palette.setColor(QPalette.Highlight, QColor(129, 140, 248)) # #818cf8
|
|
palette.setColor(QPalette.HighlightedText, Qt.white)
|
|
palette.setColor(QPalette.Disabled, QPalette.Text, QColor(160, 174, 192)) # #a0aec0
|
|
self.setPalette(palette)
|
|
|
|
# 主窗口部件
|
|
self.main_widget = QWidget()
|
|
self.main_layout = QHBoxLayout(self.main_widget)
|
|
self.main_layout.setContentsMargins(0, 0, 0, 0)
|
|
self.main_layout.setSpacing(0)
|
|
|
|
# 导航栏 (初始隐藏)
|
|
self.nav_bar = NavBar("")
|
|
self.nav_bar.setObjectName("navBar")
|
|
self.nav_bar.hide()
|
|
self.nav_bar.nav_item_clicked.connect(self.handle_nav_click)
|
|
self.nav_bar.logout_clicked.connect(self.handle_logout)
|
|
|
|
# 页面堆栈
|
|
self.stacked_pages = QStackedWidget()
|
|
self.stacked_pages.setObjectName("stackedPages")
|
|
|
|
# 登录页
|
|
self.login_page = LoginPage()
|
|
self.login_page.login_success.connect(self.handle_login_success)
|
|
|
|
# 应用中心页
|
|
self.app_center = AppCenter()
|
|
self.app_center.app_selected.connect(self.handle_app_selected)
|
|
|
|
# Word转PDF页
|
|
self.word_to_pdf = WordToPDFPage()
|
|
|
|
# 使用记录页
|
|
self.history_page = HistoryPage()
|
|
|
|
# 设置页(待实现)
|
|
self.settings_page = QWidget()
|
|
self.settings_page.setObjectName("settingsPage")
|
|
|
|
# 添加页面
|
|
self.stacked_pages.addWidget(self.login_page)
|
|
self.stacked_pages.addWidget(self.app_center)
|
|
self.stacked_pages.addWidget(self.word_to_pdf)
|
|
self.stacked_pages.addWidget(self.history_page)
|
|
self.stacked_pages.addWidget(self.settings_page)
|
|
|
|
# 主布局
|
|
self.main_layout.addWidget(self.nav_bar)
|
|
self.main_layout.addWidget(self.stacked_pages, 1) # 设置弹性因子为1
|
|
|
|
self.setCentralWidget(self.main_widget)
|
|
|
|
def handle_login_success(self, username):
|
|
self.username = username
|
|
# 更新导航栏用户信息
|
|
self.nav_bar.username = username
|
|
self.nav_bar.show()
|
|
# 设置默认激活页
|
|
self.nav_bar.set_active_nav("home")
|
|
self.stacked_pages.setCurrentWidget(self.app_center)
|
|
|
|
def handle_logout(self):
|
|
self.username = None
|
|
self.nav_bar.hide()
|
|
self.stacked_pages.setCurrentWidget(self.login_page)
|
|
|
|
def handle_nav_click(self, nav_id):
|
|
# 确保导航栏状态更新
|
|
self.nav_bar.set_active_nav(nav_id)
|
|
|
|
# 根据导航ID切换页面
|
|
if nav_id == "home":
|
|
self.stacked_pages.setCurrentWidget(self.app_center)
|
|
elif nav_id == "history":
|
|
self.stacked_pages.setCurrentWidget(self.history_page)
|
|
elif nav_id == "settings":
|
|
self.stacked_pages.setCurrentWidget(self.settings_page)
|
|
|
|
def handle_app_selected(self, app_id):
|
|
if app_id == "word_to_pdf":
|
|
self.stacked_pages.setCurrentWidget(self.word_to_pdf)
|
|
# 后续可添加其他应用
|
|
|
|
|
|
def main():
|
|
app = QApplication(sys.argv)
|
|
app.setStyle('Fusion')
|
|
|
|
# 设置高DPI支持
|
|
app.setAttribute(Qt.AA_EnableHighDpiScaling)
|
|
app.setAttribute(Qt.AA_UseHighDpiPixmaps)
|
|
|
|
window = MainWindow()
|
|
window.show()
|
|
sys.exit(app.exec_())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |