-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
DoctorReid
committed
Jul 28, 2024
1 parent
4cf5fea
commit c0b7c27
Showing
10 changed files
with
251 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from PySide6.QtWidgets import QWidget, QVBoxLayout | ||
from qfluentwidgets import ProgressBar, IndeterminateProgressBar, SettingCardGroup, \ | ||
FluentIcon | ||
|
||
from one_dragon.gui.component.interface.vertical_scroll_interface import VerticalScrollInterface | ||
from one_dragon.gui.component.log_display_card import LogDisplayCard | ||
from one_dragon.utils.i18_utils import gt | ||
from zzz_od.context.zzz_context import ZContext | ||
from zzz_od.gui.view.installer.gamepad_install_card import GamepadInstallCard | ||
|
||
|
||
class ExtendInstallInterface(VerticalScrollInterface): | ||
|
||
def __init__(self, ctx: ZContext, parent=None): | ||
self.ctx: ZContext = ctx | ||
VerticalScrollInterface.__init__(self, ctx=ctx, object_name='extend_install_interface', | ||
parent=parent, content_widget=None, | ||
nav_text_cn='扩展安装', nav_icon=FluentIcon.DEVELOPER_TOOLS) | ||
|
||
def get_content_widget(self) -> QWidget: | ||
content_widget = QWidget() | ||
v_layout = QVBoxLayout(content_widget) | ||
|
||
self.progress_bar = ProgressBar() | ||
self.progress_bar.setRange(0, 1) | ||
self.progress_bar.setVisible(False) | ||
v_layout.addWidget(self.progress_bar) | ||
|
||
self.progress_bar_2 = IndeterminateProgressBar() | ||
self.progress_bar_2.setVisible(False) | ||
v_layout.addWidget(self.progress_bar_2) | ||
|
||
self.gamepad_opt = GamepadInstallCard(self.ctx) | ||
|
||
update_group = SettingCardGroup(gt('运行环境', 'ui')) | ||
update_group.addSettingCard(self.gamepad_opt) | ||
|
||
v_layout.addWidget(update_group) | ||
|
||
log_group = SettingCardGroup(gt('安装日志', 'ui')) | ||
self.log_card = LogDisplayCard() | ||
log_group.addSettingCard(self.log_card) | ||
v_layout.addWidget(log_group) | ||
|
||
return content_widget | ||
|
||
def on_interface_shown(self) -> None: | ||
""" | ||
页面加载完成后 检测各个组件状态并更新显示 | ||
:return: | ||
""" | ||
VerticalScrollInterface.on_interface_shown(self) | ||
self.gamepad_opt.check_and_update_display() | ||
self.log_card.update_on_log = True | ||
|
||
def on_interface_hidden(self) -> None: | ||
""" | ||
子界面隐藏时的回调 | ||
:return: | ||
""" | ||
VerticalScrollInterface.on_interface_hidden(self) | ||
self.log_card.update_on_log = False | ||
|
||
def update_progress(self, progress: float, message: str) -> None: | ||
""" | ||
进度回调更新 | ||
:param progress: 进度 0~1 | ||
:param message: 当前信息 | ||
:return: | ||
""" | ||
if progress == -1: | ||
self.progress_bar.setVisible(False) | ||
self.progress_bar_2.setVisible(True) | ||
self.progress_bar_2.start() | ||
else: | ||
self.progress_bar.setVisible(True) | ||
self.progress_bar.setVal(progress) | ||
self.progress_bar_2.setVisible(False) | ||
self.progress_bar_2.stop() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import os | ||
from PySide6.QtGui import QIcon | ||
from qfluentwidgets import FluentIcon, FluentThemeColor | ||
from typing import Tuple, Optional, Callable | ||
|
||
from one_dragon.gui.install_card.base_install_card import BaseInstallCard | ||
from one_dragon.utils import cmd_utils, os_utils | ||
from one_dragon.utils.i18_utils import gt | ||
from one_dragon.utils.log_utils import log | ||
from zzz_od.context.zzz_context import ZContext | ||
|
||
|
||
class GamepadInstallCard(BaseInstallCard): | ||
|
||
def __init__(self, ctx: ZContext, parent=None): | ||
self.ctx: ZContext = ctx | ||
BaseInstallCard.__init__( | ||
self, | ||
ctx=ctx, | ||
title_cn='虚拟手柄', | ||
install_method=self.install_requirements, | ||
parent=parent | ||
) | ||
|
||
def after_progress_done(self, success: bool, msg: str) -> None: | ||
""" | ||
安装结束的回调,由子类自行实现 | ||
:param success: 是否成功 | ||
:param msg: 提示信息 | ||
:return: | ||
""" | ||
if success: | ||
self.ctx.env_config.update('vgamepad_requirement', self.get_requirement_time()) | ||
self.check_and_update_display() | ||
else: | ||
self.update_display(FluentIcon.INFO.icon(color=FluentThemeColor.RED.value), gt(msg, 'ui')) | ||
|
||
def get_display_content(self) -> Tuple[QIcon, str]: | ||
""" | ||
获取需要显示的状态,由子类自行实现 | ||
:return: 显示的图标、文本 | ||
""" | ||
last = self.ctx.env_config.get('vgamepad_requirement', '') | ||
|
||
if last != self.get_requirement_time(): | ||
icon = FluentIcon.INFO.icon(color=FluentThemeColor.GOLD.value) | ||
msg = gt('需更新,请使用安装器更新', 'ui') | ||
else: | ||
icon = FluentIcon.INFO.icon(color=FluentThemeColor.DEFAULT_BLUE.value) | ||
msg = f"{gt('已安装', 'ui')}" + ' ' + last | ||
|
||
return icon, msg | ||
|
||
def get_requirement_time(self) -> Optional[str]: | ||
""" | ||
获取 requirements.txt 的最后更新时间 | ||
:return: | ||
""" | ||
log.info('获取依赖文件的最后修改时间') | ||
return cmd_utils.run_command([self.ctx.env_config.git_path, 'log', '-1', '--pretty=format:"%ai', '--', self.get_requirement_path()]) | ||
|
||
def install_requirements(self, progress_callback: Optional[Callable[[float, str], None]]) -> Tuple[bool, str]: | ||
""" | ||
安装依赖 | ||
:return: | ||
""" | ||
progress_callback(-1, '正在安装...安装过程可能需要安装驱动 正常安装即可') | ||
result = cmd_utils.run_command([self.ctx.env_config.python_path, '-m', 'pip', 'install', '--upgrade', '-r', | ||
self.get_requirement_path()]) | ||
success = result is not None | ||
msg = '运行依赖安装成功' if success else '运行依赖安装失败' | ||
return success, msg | ||
|
||
def get_requirement_path(self) -> str: | ||
return os.path.join( | ||
os_utils.get_work_dir(), | ||
self.ctx.project_config.get('vgamepad_requirements', 'requirements-gamepad.txt') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import sys | ||
|
||
from PySide6.QtWidgets import QApplication | ||
from qfluentwidgets import NavigationItemPosition, Theme, setTheme | ||
|
||
from one_dragon.gui.app.fluent_window_base import FluentWindowBase | ||
from one_dragon.gui.view.install_interface import InstallerInterface | ||
from one_dragon.gui.view.installer_setting_interface import InstallerSettingInterface | ||
from zzz_od.context.zzz_context import ZContext | ||
from zzz_od.gui.view.installer.extend_install_interface import ExtendInstallInterface | ||
|
||
|
||
class ZInstallerWindow(FluentWindowBase): | ||
|
||
def __init__(self, ctx: ZContext, win_title: str, parent=None): | ||
self.ctx: ZContext = ctx | ||
FluentWindowBase.__init__( | ||
self, | ||
ctx=ctx, | ||
win_title=win_title, | ||
parent=parent, | ||
app_icon='zzz_logo.ico' | ||
) | ||
|
||
def create_sub_interface(self): | ||
self.add_sub_interface(InstallerInterface(self.ctx, parent=self)) | ||
self.add_sub_interface(ExtendInstallInterface(self.ctx, parent=self)) | ||
self.add_sub_interface(InstallerSettingInterface(self.ctx, parent=self), position=NavigationItemPosition.BOTTOM) | ||
|
||
|
||
if __name__ == '__main__': | ||
app = QApplication(sys.argv) | ||
_ctx = ZContext() | ||
setTheme(Theme[_ctx.env_config.theme.upper()]) | ||
w = ZInstallerWindow(_ctx, f'{_ctx.project_config.project_name}-installer') | ||
w.show() | ||
app.exec() |