Skip to content

Commit

Permalink
feat: 添加了彩蛋
Browse files Browse the repository at this point in the history
fix: 修复了打开评教页面后程序窗口被覆盖的问题
  • Loading branch information
Yang-ZhiHang committed Dec 16, 2024
1 parent 68b3de3 commit fa2d883
Show file tree
Hide file tree
Showing 10 changed files with 611 additions and 29 deletions.
6 changes: 6 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ src/
└── updater.spec # 更新模块打包配置
```

## 编译资源模块

```bash
pyrcc5 resources.qrc -o resources_rc.py
```

## 打包

```bash
Expand Down
10 changes: 8 additions & 2 deletions src/core/configs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os


class Settings:

# 应用相关
Expand All @@ -19,18 +20,23 @@ class Settings:

# 更新相关
# GITHUB_API = "https://github.com/Yang-ZhiHang/XDU-WallNut"
GITHUB_APP_PAGE_URL = "https://github.com/Yang-ZhiHang/XDU-WallNut"
GITHUB_API = "https://api.github.com/repos/Yang-ZhiHang/XDU-WallNut/releases/latest"
GITHUB_EXE_URL = "https://github.com/Yang-ZhiHang/XDU-WallNut/releases/latest/download/XDU_WallNut.exe"

BASE_DIR = ""

@staticmethod
def get_base_dir():
"""获取程序运行目录"""
import sys
if getattr(sys, 'frozen', False):

if getattr(sys, "frozen", False):
# 如果是打包后的可执行文件
BASE_DIR = os.path.dirname(sys.executable)
else:
# 如果是源码运行
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
BASE_DIR = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)
return BASE_DIR
1 change: 1 addition & 0 deletions src/core/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ class Icon:
info_ico_path = ":/icons/info.png"
warning_ico_path = ":/icons/warning.png"
error_ico_path = ":/icons/error.png"
github_ico_path = ":/icons/github.png"
3 changes: 0 additions & 3 deletions src/core/loaders/web_loader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""
该模块用于浏览器相关操作
"""
"""
该模块用于浏览器相关操作
"""

import os
import webbrowser
Expand Down
10 changes: 3 additions & 7 deletions src/data/version.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"latest_version": "1.2.3",
"download_url": "https://github.com/Yang-ZhiHang/XDU-WallNut/releases/download/v1.2.3/XDU_WallNut_setup.exe",
"release_notes": "## 🚀更新概况🚀\r\n\r\n- 修复了字体在不同电脑缩放比情况下的自适应问题\r\n- 绿色软件 -> setup 安装程序\r\n\r\n## 资源\r\n\r\n- XDU_WallNut.exe 用于应用获取更新(不用下载)\r\n- XDU_WallNut_setup.exe 供下载学习交流使用\r\n\r\n欢迎提出问题,一起完善 😋",
"download_url": "https://github.com/Yang-ZhiHang/XDU-WallNut/releases/download/v1.3.1/XDU_WallNut_setup.exe",
"release_date": null,
"release_url": "https://github.com/Yang-ZhiHang/XDU-WallNut/releases/tag/v1.2.3",
"release_url": "https://github.com/Yang-ZhiHang/XDU-WallNut/releases/tag/v1.3.1",
"author": "Yang-ZhiHang",
"name": "v1.2.3",
"published_at": "2024-11-18T08:36:35Z",
"version": "1.2.3"
"version": "1.3.1"
}
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
def main():
app = QApplication(sys.argv)
window = MainWindow()
window.check_update()
window.web_loader.open_website("https://ehall.xidian.edu.cn/jwapp/sys/wspjyyapp/*default/index.do", window.console_output)
window.check_update()
sys.exit(app.exec_())


Expand Down
Binary file added src/resources/icons/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
559 changes: 557 additions & 2 deletions src/resources/resources_rc.py

Large diffs are not rendered by default.

39 changes: 32 additions & 7 deletions src/ui/widgets/title_bar_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,42 @@
from utils.logger import Logger
from core.configs.settings import Settings
from core.icons import Icon
from core.loaders import web_loader
except ImportError as e:
Logger.error(
"title_bar_widget.py", "title_bar_widget", "ImportError: " + str(e), color="red"
)


class TitleBarWidget(QWidget):
def __init__(self):
def __init__(self, web_loader=None, console_output=None):
super().__init__()

self.default_icon = QIcon(Icon.logo_ico_path)
self.hover_icon = QIcon(Icon.github_ico_path)
self.github_url = Settings.GITHUB_APP_PAGE_URL
self.web_loader = web_loader
self.console_output = console_output
self._init_component()

self._set_component_style()

self._apply_component()

def _init_component(self):

self.title_bar = QHBoxLayout()

self.icon_label = QLabel()
icon_size = (30, 30)
self.icon_label.setFixedSize(*icon_size)
icon_pixmap = QIcon(Icon.logo_ico_path).pixmap(*icon_size)
self.icon_size = (30, 30)
self.icon_label.setFixedSize(*self.icon_size)
icon_pixmap = self.default_icon.pixmap(*self.icon_size)
self.icon_label.setPixmap(icon_pixmap)

# 设置鼠标悬停时为手型
self.icon_label.setCursor(Qt.PointingHandCursor)

# QLabel 接收鼠标点击事件
self.icon_label.setMouseTracking(True)
self.icon_label.mousePressEvent = self.icon_clicked

self.title_label = QLabel(Settings.WINDOW_TITLE)
self.min_button = QPushButton("-")
self.close_button = QPushButton("×")
Expand Down Expand Up @@ -131,3 +141,18 @@ def mouseMoveEvent(self, event):
self.window().move(self.window_position + delta)

# ------------------------------- 窗口拖动 end

# 添加鼠标进入事件处理
def enterEvent(self, event):
hover_pixmap = self.hover_icon.pixmap(*self.icon_size)
self.icon_label.setPixmap(hover_pixmap)

# 添加鼠标离开事件处理
def leaveEvent(self, event):
default_pixmap = self.default_icon.pixmap(*self.icon_size)
self.icon_label.setPixmap(default_pixmap)

def icon_clicked(self, event):
Logger.info("title_bar_widget.py", "icon_clicked", "icon clicked")
if event.button() == Qt.LeftButton and self.web_loader:
self.web_loader.open_website(self.github_url, self.console_output)
10 changes: 3 additions & 7 deletions src/ui/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
QTabWidget,
QScrollArea,
QLabel,
QTextBrowser,
)
from PyQt5.QtCore import Qt, QTimer
import markdown

from ui.windows.progress_window import ProgressWindow


try:
Expand Down Expand Up @@ -150,14 +146,14 @@ def _load_component(self):
# ------------------------------- 设置 end

self.setWindowFlags(Qt.FramelessWindowHint)
self.title_bar = TitleBarWidget()
self.web_loader = WebLoader()
self.console_output = ConsoleOutput()
self.title_bar = TitleBarWidget(web_loader=self.web_loader, console_output=self.console_output)

self._app_icon = QIcon(Icon.logo_ico_path)
self.start_button = StartButton()
self.console_output = ConsoleOutput()

self.style_loader = StyleLoader("base.qss")
self.web_loader = WebLoader()
self.update_checker = UpdateChecker()

def _apply_component(self):
Expand Down

0 comments on commit fa2d883

Please sign in to comment.