Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
[0.1.5] 首页可以查看当期UP角色
Browse files Browse the repository at this point in the history
提高了线程安全(理论上,实际依旧很不安全)
  • Loading branch information
AuroraZiling committed May 18, 2023
1 parent 0f274bd commit cb0e13b
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/assets/configs/application.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"application_version": "0.1.4",
"application_version": "0.1.5",
"ui_version": "0.8.7"
}
17 changes: 13 additions & 4 deletions src/asta.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from qframelesswindow import FramelessWindow

from modules.Scripts.Utils.file_verification import assetsCheck

from modules.Views import home_frame, gacha_report_frame, link_frame, \
settings_frame, about_frame, metadata_frame, glyphs_frame
from modules.Scripts.UI import custom_icon
from modules.Scripts.UI.title_bar import CustomTitleBar
from modules.Scripts.UI.style_sheet import StyleSheet
from modules.Scripts.Utils import file_verification, metadata_utils, config_utils, downloader, log_recorder as log
from modules.Metadata import character_list, weapon_list
from modules.Scripts.Utils import file_verification, metadata_utils, config_utils, log_recorder as log
from modules.Metadata import character_list
from src.modules.Views import announcement_frame

utils = config_utils.ConfigUtils()

Expand Down Expand Up @@ -57,7 +57,7 @@ def __init__(self, logFile):
def __BuildLogger(self):
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.FileHandler(self.__logFile))
logger.addHandler(logging.FileHandler(self.__logFile, encoding="utf-8"))
return logger

def __HandleException(self, excType, excValue, tb):
Expand Down Expand Up @@ -96,6 +96,7 @@ def __init__(self):
self.mainHomeInterface = home_frame.HomeWidget(self)
self.mainGachaReportInterface = gacha_report_frame.GachaReportWidget(self)
self.mainLinkInterface = link_frame.LinkWidget(self)
self.mainAnnouncementInterface = announcement_frame.AnnouncementWidget(self)
self.mainGlyphsInterface = glyphs_frame.GlyphsWidget(self)
self.mainMetaDataInterface = metadata_frame.MetaDataWidget(self)
self.mainSettingInterface = settings_frame.SettingWidget(self)
Expand All @@ -104,6 +105,7 @@ def __init__(self):
self.mainStackWidget.addWidget(self.mainHomeInterface)
self.mainStackWidget.addWidget(self.mainGachaReportInterface)
self.mainStackWidget.addWidget(self.mainLinkInterface)
self.mainStackWidget.addWidget(self.mainAnnouncementInterface)
self.mainStackWidget.addWidget(self.mainGlyphsInterface)
self.mainStackWidget.addWidget(self.mainMetaDataInterface)
self.mainStackWidget.addWidget(self.mainSettingInterface)
Expand Down Expand Up @@ -150,6 +152,13 @@ def initNavigation(self):
onClick=lambda: self.switchTo(self.mainLinkInterface)
)

self.mainNavigationInterface.addItem(
routeKey=self.mainAnnouncementInterface.objectName(),
icon=custom_icon.MyFluentIcon.ANNOUNCEMENT,
text="公告",
onClick=lambda: self.switchTo(self.mainAnnouncementInterface)
)

self.mainNavigationInterface.addSeparator()

self.mainNavigationInterface.addItem(
Expand Down
Empty file.
15 changes: 0 additions & 15 deletions src/modules/Scripts/Updater/check_update.py

This file was deleted.

3 changes: 2 additions & 1 deletion src/modules/Scripts/Utils/log_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ def errorWrite(content):
format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
filename=utils.logDir + "/" + logFileName,
filemode='w'
filemode='w',
encoding="utf-8"
)
43 changes: 42 additions & 1 deletion src/modules/Views/ViewFunctions/homeFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,53 @@

from PySide6.QtCore import QThread, Signal

from ...Scripts.Utils import downloader
from ...Scripts.Utils.config_utils import ConfigUtils
from ...constant import SOFTWARE_ANNOUNCEMENT_URL
from ...constant import SOFTWARE_ANNOUNCEMENT_URL, ANNOUNCE_REQUEST_URL, ANNOUNCE_ICON_REQUEST_URL, \
ANNOUNCE_CURRENT_UP_URL

utils = ConfigUtils()


class HomeCurrentUPThread(QThread):
trigger = Signal(int, int, str, str, str)

def __init__(self, parent=None):
super(HomeCurrentUPThread, self).__init__(parent)

def run(self):
character1ImagePath = f"{utils.workingDir}/assets/unknownAvatar.png"
character1Pool = "信息获取失败"
self.trigger.emit(0, 0, "正在获取信息...", "未知", character1ImagePath)
self.trigger.emit(1, 0, "正在获取信息...", "未知", character1ImagePath)
upWeaponList = []
if not os.path.exists(f"{utils.workingDir}/cache/announce.json"):
downloader.downloadFromJson(ANNOUNCE_REQUEST_URL, utils.workingDir + "/cache/", "announce.json")
downloader.downloadFromJson(ANNOUNCE_ICON_REQUEST_URL, utils.workingDir + "/cache/",
"announce_icons.json")
downloader.downloadFromJson(ANNOUNCE_CURRENT_UP_URL, utils.workingDir + "/cache/", "current_up.json")
if os.path.exists(f"{utils.workingDir}/cache/current_up.json") and os.path.exists(f"{utils.workingDir}/cache/announce.json"):
originalCurrentUPInfo = json.loads(open(f"{utils.workingDir}/cache/current_up.json", 'r', encoding="utf-8").read())["data"]["list"]
character1Time = f"{originalCurrentUPInfo[0]['start_time']} - {originalCurrentUPInfo[0]['end_time']}"
downloader.downloadFromImage(originalCurrentUPInfo[0]['pool'][0]['icon'], utils.workingDir + "/cache/", "current_up_character_1.png")

originalInfo = json.loads(open(f"{utils.workingDir}/cache/announce.json", encoding="utf-8").read())["data"]["list"]
for announce in originalInfo:
if "活动期间,限定5星角色「" in announce["content"]:
character1Pool = f"「{originalCurrentUPInfo[0]['title']}」跃迁 | {announce['content'].split('活动期间,限定5星角色')[1].split('跃迁成功概率限时提升')[0]}"
if "活动期间,限定5星光锥「" in announce["content"]:
upWeaponList.append(announce["content"].split("活动期间,限定5星光锥「")[1].split("」")[0])
else:
self.trigger.emit(0, 0, "信息获取失败", "未知", character1ImagePath)
self.trigger.emit(1, 0, "信息获取失败", "未知", character1ImagePath)
return
upWeaponList = ' '.join(upWeaponList)
if os.path.exists(f"{utils.workingDir}/cache/current_up_character_1.png"):
character1ImagePath = f"{utils.workingDir}/cache/current_up_character_1.png"
self.trigger.emit(0, 0, character1Pool, character1Time, character1ImagePath)
self.trigger.emit(1, 0, "武器: " + ' '.join(upWeaponList), "未知", character1ImagePath)


class HomeSoftwareAnnouncementThread(QThread):
trigger = Signal(str)

Expand Down
155 changes: 155 additions & 0 deletions src/modules/Views/announcement_frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import webbrowser

from PySide6 import QtGui
from PySide6.QtCore import Qt, QSize
from PySide6.QtWidgets import QFrame, QLabel, QHBoxLayout, QVBoxLayout, QSizePolicy

from qfluentwidgets import PrimaryPushButton, FluentIcon, InfoBar, PushButton, InfoBarPosition, isDarkTheme, ListWidget

from ..Scripts.UI.style_sheet import StyleSheet
from ..Scripts.Utils import downloader, log_recorder as log
from ..Scripts.Utils.config_utils import ConfigUtils
from .ViewFunctions import announcementFunctions
from ..constant import ANNOUNCE_REQUEST_URL, ANNOUNCE_ICON_REQUEST_URL

utils = ConfigUtils()


class AnnouncementWidget(QFrame):

def __init__(self, parent=None):
super().__init__(parent=parent)
if not (utils.jsonValidator(f"{utils.workingDir}/cache/announce.json") or utils.jsonValidator(f"{utils.workingDir}/cache/announce_icons.json")):
log.infoWrite("[Announcement] Get announce.json")
downloader.downloadFromJson(ANNOUNCE_REQUEST_URL, utils.workingDir + "/cache/", "announce.json")
log.infoWrite("[Announcement] Get announce_icon.json")
downloader.downloadFromJson(ANNOUNCE_ICON_REQUEST_URL, utils.workingDir + "/cache/",
"announce_icons.json")

self.baseVBox = QVBoxLayout(self)

self.announceData = utils.getAnnounceData()
self.announceIconData = utils.getAnnounceIconData()
self.currentAnnounceHTMLPath = ""

self.headerHBox = QHBoxLayout(self)

self.headerLeftVBox = QVBoxLayout(self)
self.headerLeftAnnounceTitleLabel = QLabel(self)
self.headerLeftContentTitleLabel = QLabel(self)
self.headerLeftVBox.addWidget(self.headerLeftAnnounceTitleLabel)
self.headerLeftVBox.addWidget(self.headerLeftContentTitleLabel)

self.headerHBox.addLayout(self.headerLeftVBox)
self.headerHBox.addStretch(1)

self.headerRightVBox = QVBoxLayout(self)
self.headerRightRefreshBtn = PrimaryPushButton("刷新", self, FluentIcon.SYNC)
self.headerRightAnnounceDateLabel = QLabel(self)
self.headerRightVBox.addSpacing(3)
self.headerRightVBox.addWidget(self.headerRightRefreshBtn, 0, Qt.AlignmentFlag.AlignRight)
self.headerRightVBox.addWidget(self.headerRightAnnounceDateLabel, 0, Qt.AlignmentFlag.AlignRight)

self.headerHBox.addLayout(self.headerRightVBox)
self.headerHBox.addSpacing(5)
self.baseVBox.addLayout(self.headerHBox)

self.announceHBox = QHBoxLayout(self)

self.announceListBox = ListWidget(self)
self.announceHBox.addWidget(self.announceListBox)

self.contentVBox = QVBoxLayout(self)
self.contentBanner = QLabel(self)
self.contentNoBanner = QLabel("此公告没有封面", self)
self.contentHTMLBtn = PushButton(self)
self.contentVBox.addWidget(self.contentBanner)
self.contentVBox.addStretch(1)
self.contentVBox.addWidget(self.contentNoBanner)
self.contentVBox.addStretch(1)
self.contentVBox.addWidget(self.contentHTMLBtn)
self.announceHBox.addLayout(self.contentVBox)

self.baseVBox.addLayout(self.announceHBox)

log.infoWrite(f"[Announcement] UI Initialized")

self.announceFunc = announcementFunctions.AnnouncementFunctions(self.announceData, self.announceIconData)
self.initAnnounce()

self.setObjectName("AnnouncementFrame")
StyleSheet.ANNOUNCEMENT_FRAME.apply(self)

self.initFrame()

def initFrame(self):
# Top - Left
self.headerLeftAnnounceTitleLabel.setText("公告")
self.headerLeftAnnounceTitleLabel.setFont(utils.getFont(18))
self.headerLeftContentTitleLabel.setText("尚未选择公告")
self.headerLeftContentTitleLabel.setFont(utils.getFont(10))
# Top - Right
self.headerRightRefreshBtn.setFixedWidth(100)
self.headerRightAnnounceDateLabel.setText("于" + utils.getFileDate(f"{utils.workingDir}/cache/announce.json") + "更新")
self.headerRightAnnounceDateLabel.setFont(utils.getFont(10))
# List
self.announceListBox.resize(200, 200)
self.announceListBox.setFrameShape(QFrame.Shape.NoFrame)
self.announceListBox.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
self.announceListBox.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
self.announceListBox.currentItemChanged.connect(self.__announceListBoxItemChanged)
self.announceListBox.setCurrentRow(0)
# Content
self.contentBanner.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.contentBanner.setMaximumWidth(750)
self.contentBanner.setScaledContents(True)
self.contentNoBanner.setFont(utils.getFont(24))
self.contentNoBanner.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
self.contentNoBanner.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.contentHTMLBtn.setText("详情")
self.contentHTMLBtn.setFixedSize(750, 30)
self.contentHTMLBtn.clicked.connect(self.openAnnounce)
# Refresh
self.headerRightRefreshBtn.clicked.connect(self.refreshAnnounce)

def showEvent(self, a0: QtGui.QShowEvent) -> None:
if isDarkTheme():
self.announceListBox.setStyleSheet("background-color: rgb(39, 39, 39); color: white;")

def __announceListBoxItemChanged(self):
currentAnnounceData = self.announceFunc.getCurrentAnnounce(self.announceListBox.currentIndex().row())
log.infoWrite(f"[Announcement] Announcement changed: {currentAnnounceData['bigTitle']}")
self.headerLeftContentTitleLabel.setText(currentAnnounceData["bigTitle"])
self.contentBanner.hide()
if currentAnnounceData["banner"]:
self.contentBanner.show()
self.contentNoBanner.hide()
self.contentBanner.setPixmap(currentAnnounceData["banner"])
self.contentBanner.setFixedHeight(currentAnnounceData["bannerHeight"])
else:
self.contentNoBanner.show()
self.currentAnnounceHTMLPath = currentAnnounceData["contentHtml"]

def initAnnounce(self):
self.announceFunc.getIcons()
self.headerRightAnnounceDateLabel.setText("于" + utils.getFileDate(f"{utils.workingDir}/cache/announce.json") + "更新")
for index, item in enumerate(self.announceFunc.getItems()):
self.announceListBox.addItem(item)
self.announceListBox.item(index).setSizeHint(QSize(300, 30))
log.infoWrite(f"[Announcement] Announcement initialized")
self.__announceListBoxItemChanged()

def refreshAnnounce(self):
self.announceListBox.clear()
downloader.downloadFromJson(ANNOUNCE_REQUEST_URL, utils.workingDir + "/cache/", "announce.json")
downloader.downloadFromJson(ANNOUNCE_ICON_REQUEST_URL, utils.workingDir + "/cache/",
"announce_icons.json")
self.announceData = utils.getAnnounceData()
self.announceIconData = utils.getAnnounceIconData()
self.initAnnounce()
log.infoWrite("[Announcement] Announcement updated")
InfoBar.success("成功", "公告已更新", position=InfoBarPosition.TOP, parent=self)

def openAnnounce(self):
webbrowser.open(f"{utils.workingDir}/cache/{self.announceListBox.currentRow()}.html")
log.infoWrite(f"[Announcement] Announcement opened at row:{self.announceListBox.currentRow()}")
8 changes: 6 additions & 2 deletions src/modules/Views/gacha_report_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
QTableWidgetItem, QStyleOptionViewItem

from qfluentwidgets import FluentIcon, RoundMenu, TableWidget, TextEdit, MessageBox, InfoBarPosition, ComboBox, \
Action, InfoBar, StateToolTip, TableItemDelegate, InfoBarIcon, isDarkTheme
Action, InfoBar, StateToolTip, TableItemDelegate, isDarkTheme
from qfluentwidgets import DropDownPushButton

from .ViewConfigs.config import cfg
from ..Scripts.Utils import config_utils, log_recorder as log
from ..Core.GachaReport.gacha_report_thread import GachaReportThread
from ..Scripts.UI.style_sheet import StyleSheet
from ..Scripts.UI.custom_dialog import URLDialog
from ..Core.GachaReport.gacha_report_utils import getDefaultGameDataPath, convertAPI
from ..Core.GachaReport.gacha_report_utils import convertAPI
from ..Core.GachaReport import gacha_report_read
from ..Core.GachaReport.Analysis import table_completion, analysis
from ..Core.GachaReport.MihoyoAPI import by_web_cache
Expand Down Expand Up @@ -111,6 +111,10 @@ def __init__(self, parent=None):

self.initData()

def closeEvent(self, event):
self.gachaReportThread.exit()
event.accept()

def __gachaReportThreadStateTooltipClosed(self):
self.gachaReportThread.exit(0)
self.gachaReportStatusChanged((1, "Operation cancelled", "Operation cancelled"))
Expand Down
Loading

0 comments on commit cb0e13b

Please sign in to comment.