From 9e4b153aec8e613be5d2afc93e90c04c7cb6e8ce Mon Sep 17 00:00:00 2001 From: ikaros <327209194@qq.com> Date: Sun, 21 Apr 2024 20:47:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=BE=93=E5=85=A5=E6=A1=86=E4=B8=BA=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E6=A1=86=EF=BC=8C=E9=BB=98=E8=AE=A4=E8=AF=BB=E5=8F=96=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=B9=E7=9B=AE=E5=BD=95=E7=9A=84=E6=89=80=E6=9C=89?= =?UTF-8?q?json=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/common.py | 22 +++++++++++++++++++++- webui.py | 20 ++++++++++++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/utils/common.py b/utils/common.py index 68c3f130..a60a236c 100644 --- a/utils/common.py +++ b/utils/common.py @@ -1,7 +1,7 @@ # 导入所需的库 import re, random, requests, json import time -import os +import os, glob import logging from datetime import datetime from datetime import timedelta @@ -718,6 +718,25 @@ def get_all_file_paths(self, folder_path): return file_paths + # 获取指定路径下指定拓展名的文件名列表 + def get_specify_extension_names_in_folder(self, path: str, extension: str): + """ + 获取指定路径下指定拓展名的文件名列表 + + Parameters: + path (str): 指定的路径 + extension (str): 指定的拓展名(例如:.json、.txt、.jpg等) + + Returns: + list: 文件名列表 + """ + if not os.path.exists(path): + logging.error(f"路径 '{path}' 不存在") + return [] + + file_names = glob.glob(os.path.join(path, f"*{extension}")) + return [os.path.basename(file_name) for file_name in file_names] + def remove_extension_from_list(self, file_name_list): """ 将包含多个带有拓展名的文件名的列表中的拓展名去掉,只返回文件名部分组成的新列表 @@ -795,6 +814,7 @@ def get_live2d_model_name(self, path): return None + """ .]]@@ .@]] @@@@ O@@` ,]]]]]]]]]]]]. /]] /@]` diff --git a/webui.py b/webui.py index cf41425e..4e02101a 100644 --- a/webui.py +++ b/webui.py @@ -5413,10 +5413,22 @@ def update_echart_gift(): with ui.card().style(card_css): ui.label("配置模板") with ui.row(): - input_config_template_path = ui.input(label='配置模板路径', value="", placeholder='输入你需要加载或保存的配置文件路径,例如:直播带货.json') - - button_config_template_save = ui.button('保存webui配置到文件', on_click=lambda: config_template_save(input_config_template_path.value), color=button_internal_color).style(button_internal_css) - button_config_template_load = ui.button('读取模板到本地(慎点)', on_click=lambda: config_template_load(input_config_template_path.value), color=button_internal_color).style(button_internal_css) + # 获取指定路径下指定拓展名的文件名列表 + config_template_paths = common.get_specify_extension_names_in_folder("./", "*.json") + data_json = {} + for line in config_template_paths: + data_json[line] = line + select_config_template_path = ui.select( + label='配置模板路径', + options=data_json, + value="", + with_input=True, + new_value_mode='add-unique', + clearable=True + ) + + button_config_template_save = ui.button('保存webui配置到文件', on_click=lambda: config_template_save(select_config_template_path.value), color=button_internal_color).style(button_internal_css) + button_config_template_load = ui.button('读取模板到本地(慎点)', on_click=lambda: config_template_load(select_config_template_path.value), color=button_internal_color).style(button_internal_css)