Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor gui #113

Merged
merged 14 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 2 additions & 207 deletions gui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,209 +1,4 @@
# 一个用户config的GUI显示
from nicegui import ui, run
import requests
from .show_gui import show_gui

import os
from gui.components.run_baah_in_gui import run_baah_task
from gui.pages.Setting_BAAH import set_BAAH
from gui.pages.Setting_Craft import set_craft
from gui.pages.Setting_cafe import set_cafe
from gui.pages.Setting_emulator import set_emulator
from gui.pages.Setting_event import set_event
from gui.pages.Setting_exchange import set_exchange
from gui.pages.Setting_hard import set_hard
from gui.pages.Setting_normal import set_normal
from gui.pages.Setting_other import set_other
from gui.pages.Setting_server import set_server
from gui.pages.Setting_shop import set_shop
from gui.pages.Setting_special import set_special
from gui.pages.Setting_task_order import set_task_order
from gui.pages.Setting_timetable import set_timetable
from gui.pages.Setting_wanted import set_wanted
from gui.pages.Setting_notification import set_notification
from gui.pages.Setting_vpn import set_vpn
from gui.pages.Setting_Assault import set_assault
from gui.pages.Setting_BuyAP import set_buyAP
from gui.pages.Setting_UserTask import set_usertask


@ui.refreshable
def show_gui(load_json_name, config, shared_software_config):

# wish users do not use example.json, so use bigger and red font to remind users
if load_json_name == "example.json":
ui.label(config.get_text("notice_example_json")).style("font-size: 30px; color: red;")

config.parse_user_config(load_json_name)

# myAllTask里面的key与GUI显示的key的映射
real_taskname_to_show_taskname = {
"登录游戏":config.get_text("task_login_game"),
"清momotalk":config.get_text("task_clear_momotalk"),
"咖啡馆":config.get_text("task_cafe"),
"咖啡馆只摸头":config.get_text("task_cafe_deprecated"), # 为了兼容以前的配置里的咖啡馆只摸头,这里只改显示名
"课程表":config.get_text("task_timetable"),
"社团":config.get_text("task_club"),
"制造":config.get_text("task_craft"),
"商店":config.get_text("task_shop"),
"购买AP":config.get_text("task_buy_ap"),
"悬赏通缉":config.get_text("task_wanted"),
"特殊任务":config.get_text("task_special"),
"学园交流会":config.get_text("task_exchange"),
"战术大赛":config.get_text("task_contest"),
"困难关卡":config.get_text("task_hard"),
"活动关卡":config.get_text("task_event"),
"总力战":config.get_text("task_assault"),
"每日任务":config.get_text("task_daily"),
"邮件":config.get_text("task_mail"),
"普通关卡":config.get_text("task_normal"),
"普通推图":config.get_text("push_normal"),
"困难推图":config.get_text("push_hard"),
"主线剧情":config.get_text("push_main_story"),
"自定义任务":config.get_text("task_user_def_task"),
}

# =============================================

# =============================================

with ui.row().style('min-width: 800px; display: flex; flex-direction: row;flex-wrap: nowrap;'):
with ui.column().style('height:80vh;min-width: 200px; width: 10vw; overflow: auto;flex-grow: 1; position: sticky; top: 0px;'):
with ui.card().style('overflow: auto;'):
ui.link("BAAH", '#BAAH')
ui.link(config.get_text("setting_emulator"), '#EMULATOR')
ui.link(config.get_text("setting_server"), '#SERVER')
ui.link(config.get_text("setting_vpn"), '#VPN')
ui.link(config.get_text("setting_task_order"), '#TASK_ORDER')
ui.link(config.get_text("setting_notification"), '#NOTIFICATION')
# ui.link(config.get_text("setting_next_config"), '#NEXT_CONFIG')
ui.link(config.get_text("task_cafe"), '#CAFE')
ui.link(config.get_text("task_timetable"), '#TIME_TABLE')
ui.link(config.get_text("task_craft"), '#CRAFT')
ui.link(config.get_text("task_shop"), '#SHOP_NORMAL')
ui.link(config.get_text("task_buy_ap"), '#BUY_AP')
ui.link(config.get_text("task_wanted"), '#WANTED')
ui.link(config.get_text("task_special"), '#SPECIAL_TASK')
ui.link(config.get_text("task_exchange"), '#EXCHANGE')
ui.link(config.get_text("task_event"), '#ACTIVITY')
ui.link(config.get_text("task_assault"), '#ASSAULT')
ui.link(config.get_text("task_hard"), '#HARD')
ui.link(config.get_text("task_normal"), '#NORMAL')
ui.link(config.get_text("task_user_def_task"), '#USER_DEF_TASK')
ui.link(config.get_text("setting_other"), '#TOOL_PATH')


with ui.column().style('flex-grow: 4; width: 50vw;'):

set_BAAH(config, shared_software_config)

# 模拟器配置
set_emulator(config)

# 服务器配置
set_server(config)

# 自己的加速器配置
set_vpn(config)

# 任务执行顺序,后续配置文件
set_task_order(config, real_taskname_to_show_taskname)

# 通知
set_notification(config, shared_software_config)

# 咖啡馆
set_cafe(config)

# 课程表
set_timetable(config)

# 制造
set_craft(config)

# 商店
set_shop(config)

# 购买AP
set_buyAP(config)

# 悬赏通缉
set_wanted(config)

# 特殊任务
set_special(config)

# 学园交流会
set_exchange(config)

# 活动关卡
set_event(config)

# 总力战
set_assault(config)

# 困难关卡
set_hard(config, shared_software_config)

# 普通关卡
set_normal(config)

# 用户定义任务
set_usertask(config)

# 其他设置
set_other(config, load_json_name)

msg_obj = {
"stop_signal": 0,
"runing_signal": 0
}

# GUI运行BAAH打印日志的区域
with ui.column().style('flex-grow: 1;width: 30vw;position:sticky; top: 0px;'):
output_card = ui.card().style('width: 30vw; height: 80vh;overflow-y: auto;')
with output_card:
logArea = ui.log(max_lines=1000).classes('w-full h-full')

with ui.column().style('width: 10vw; overflow: auto; position: fixed; bottom: 40px; right: 20px;min-width: 150px;'):

def save_and_alert():
config.save_user_config(load_json_name)
config.save_software_config()
shared_software_config.save_software_config()
ui.notify(config.get_text("notice_save_success"))
ui.button(config.get_text("button_save"), on_click=save_and_alert)

def save_and_alert_and_run_in_terminal():
config.save_user_config(load_json_name)
config.save_software_config()
shared_software_config.save_software_config()
ui.notify(config.get_text("notice_save_success"))
ui.notify(config.get_text("notice_start_run"))
# 打开同目录中的BAAH.exe,传入当前config的json文件名
os.system(f'start BAAH.exe "{load_json_name}"')
ui.button(config.get_text("button_save_and_run_terminal"), on_click=save_and_alert_and_run_in_terminal)

# ======Run in GUI======
async def save_and_alert_and_run():
config.save_user_config(load_json_name)
config.save_software_config()
shared_software_config.save_software_config()
ui.notify(config.get_text("notice_save_success"))
ui.notify(config.get_text("notice_start_run"))
# 打开同目录中的BAAH.exe,传入当前config的json文件名
# os.system(f'start BAAH.exe "{load_jsonname}"')
msg_obj["runing_signal"] = 1
await run.io_bound(run_baah_task, msg_obj, logArea, config)
ui.button(config.get_text("button_save_and_run_gui"), on_click=save_and_alert_and_run).bind_visibility_from(msg_obj, "runing_signal", backward=lambda x:x == 0)

async def stop_run() -> None:
msg_obj["stop_signal"] = 1
ui.button(config.get_text("notice_finish_run"), on_click=stop_run, color='red').bind_visibility_from(msg_obj, "runing_signal", backward=lambda x:x == 1)

ui.button("...").bind_visibility_from(msg_obj, "runing_signal", backward=lambda x:x == 0.25)

# ================

# 加载完毕保存一下config,应用最新的对config的更改
config.save_user_config(load_json_name)
config.save_software_config()
__all__ = ["show_gui"]
19 changes: 11 additions & 8 deletions gui/components/check_update.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from ..define import gui_shared_config

from nicegui import ui, run
import time
import requests
import os

async def only_check_version(config):

async def only_check_version():
# 比较访问https://gitee.com/api/v5/repos/sammusen/BAAH/releases/latest和https://api.github.com/repos/sanmusen214/BAAH/releases/latest哪一个快
urls={
"gitee":"https://gitee.com/api/v5/repos/sammusen/BAAH/releases/latest",
Expand Down Expand Up @@ -31,22 +34,22 @@ async def only_check_version(config):
resultdict = {}
# 如果两个网站都访问失败
if len(eachtime) == 0:
ui.notify(config.get_text("notice_fail"))
ui.notify(gui_shared_config.get_text("notice_fail"))
resultdict["status"] = False
resultdict["msg"] = f'{config.get_text("notice_fail")} Fail to connect Github/Gitee'
resultdict["msg"] = f'{gui_shared_config.get_text("notice_fail")} Fail to connect Github/Gitee'
return resultdict
# 找到访问时间最短的网站key
fastestkey = min(eachtime, key=eachtime.get)
# 判断是否需要更新
if config.get_one_version_num(eachnewesttag[fastestkey]) > config.get_one_version_num():
ui.notify(f'{config.get_text("notice_get_new_version")}: {eachnewesttag[fastestkey]} ({fastestkey})')
if gui_shared_config.get_one_version_num(eachnewesttag[fastestkey]) > gui_shared_config.get_one_version_num():
ui.notify(f'{gui_shared_config.get_text("notice_get_new_version")}: {eachnewesttag[fastestkey]} ({fastestkey})')
resultdict["status"] = True
resultdict["msg"] = f'{config.get_text("notice_get_new_version")}: {eachnewesttag[fastestkey]} ({fastestkey})'
resultdict["msg"] = f'{gui_shared_config.get_text("notice_get_new_version")}: {eachnewesttag[fastestkey]} ({fastestkey})'
resultdict["urls"] = eachdowloadurl[fastestkey]
else:
ui.notify(config.get_text("notice_no_new_version"))
ui.notify(gui_shared_config.get_text("notice_no_new_version"))
resultdict["status"] = False
resultdict["msg"] = config.get_text("notice_no_new_version")
resultdict["msg"] = gui_shared_config.get_text("notice_no_new_version")
return resultdict

# 检查更新
Expand Down
5 changes: 5 additions & 0 deletions gui/define.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from modules.configs.MyConfig import MyConfigger


# 构造一个config,用于在tab间共享softwareconfigdict
gui_shared_config = MyConfigger()
1 change: 1 addition & 0 deletions gui/pages/Setting_BAAH.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from nicegui import ui, app
from gui.components.check_update import get_newest_version


def set_BAAH(config, shared_softwareconfig):

def select_language(value):
Expand Down
5 changes: 2 additions & 3 deletions gui/pages/Setting_task_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ def task_order():
with ui.row():
ui.label(f'{config.get_text("config_task")} {i+1}:')
atask = ui.select(real_taskname_to_show_taskname,
value=config.userconfigdict["TASK_ORDER"][i],
on_change=lambda v,i=i: config.userconfigdict["TASK_ORDER"].__setitem__(i, v.value),
)
value=config.userconfigdict["TASK_ORDER"][i],
on_change=lambda v: config.userconfigdict["TASK_ORDER"].__setitem__(i, v.value))
acheck = ui.checkbox(config.get_text("button_enable"), value=config.userconfigdict["TASK_ACTIVATE"][i], on_change=lambda v,i=i: config.userconfigdict["TASK_ACTIVATE"].__setitem__(i, v.value))
if i==0:
atask.set_enabled(False)
Expand Down
Loading