Skip to content

Commit

Permalink
Merge pull request #772 from Ikaros-521/owner
Browse files Browse the repository at this point in the history
修改默认配置输入框为下拉框,默认读取项目根目录的所有json文件
  • Loading branch information
Ikaros-521 committed Apr 21, 2024
2 parents 055c415 + 9e4b153 commit 119b8c4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
22 changes: 21 additions & 1 deletion utils/common.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
"""
将包含多个带有拓展名的文件名的列表中的拓展名去掉,只返回文件名部分组成的新列表
Expand Down Expand Up @@ -795,6 +814,7 @@ def get_live2d_model_name(self, path):
return None



"""
.]]@@ .@]] @@@@ O@@` ,]]]]]]]]]]]]. /]] /@]`
Expand Down
20 changes: 16 additions & 4 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5448,10 +5448,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)



Expand Down

0 comments on commit 119b8c4

Please sign in to comment.