mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-21 09:05:34 +08:00
Opt: Reads existing json files in multi-instances
This commit is contained in:
17
gui.py
17
gui.py
@@ -152,7 +152,7 @@ class AlasGUI:
|
|||||||
self.contents,
|
self.contents,
|
||||||
], size="auto 1fr").style("container-all")
|
], size="auto 1fr").style("container-all")
|
||||||
).style("container-gui")
|
).style("container-gui")
|
||||||
|
|
||||||
self.logs = ScrollableCode()
|
self.logs = ScrollableCode()
|
||||||
|
|
||||||
def set_aside(self):
|
def set_aside(self):
|
||||||
@@ -170,12 +170,11 @@ class AlasGUI:
|
|||||||
# "Gui.Aside.Performance"), "value": "performance", "color": "aside"}], onclick=[self.ui_performance]),
|
# "Gui.Aside.Performance"), "value": "performance", "color": "aside"}], onclick=[self.ui_performance]),
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: generate this from config
|
|
||||||
self.aside.append(
|
self.aside.append(
|
||||||
put_icon_buttons(Icon.RUN, buttons=[
|
*[put_icon_buttons(
|
||||||
{"label": "Alas", "value": "alas", "color": "aside"}], onclick=self.ui_alas),
|
Icon.RUN, buttons=[{"label": name, "value": name, "color": "aside"}],
|
||||||
put_icon_buttons(Icon.RUN, buttons=[
|
onclick=self.ui_alas)
|
||||||
{"label": "Alas2", "value": "alas2", "color": "aside"}], onclick=self.ui_alas),
|
for name in alas_instance()]
|
||||||
)
|
)
|
||||||
|
|
||||||
def kill_thread(self):
|
def kill_thread(self):
|
||||||
@@ -196,7 +195,7 @@ class AlasGUI:
|
|||||||
if self._status == status:
|
if self._status == status:
|
||||||
return
|
return
|
||||||
self._status = status
|
self._status = status
|
||||||
|
|
||||||
if status == 1:
|
if status == 1:
|
||||||
s = put_row([
|
s = put_row([
|
||||||
put_loading(color='success').style("width:1.5rem;height:1.5rem;border:.2em solid currentColor;border-right-color:transparent;"),
|
put_loading(color='success').style("width:1.5rem;height:1.5rem;border:.2em solid currentColor;border-right-color:transparent;"),
|
||||||
@@ -217,7 +216,7 @@ class AlasGUI:
|
|||||||
], size='auto 2px 1fr')
|
], size='auto 2px 1fr')
|
||||||
else:
|
else:
|
||||||
s = ''
|
s = ''
|
||||||
|
|
||||||
self.status.reset(s)
|
self.status.reset(s)
|
||||||
|
|
||||||
|
|
||||||
@@ -251,7 +250,7 @@ class AlasGUI:
|
|||||||
], onclick=self.alas_set_group).style(f'--menu-{task}--') for task in tasks]
|
], onclick=self.alas_set_group).style(f'--menu-{task}--') for task in tasks]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.alas_overview()
|
self.alas_overview()
|
||||||
|
|
||||||
def alas_set_group(self, task):
|
def alas_set_group(self, task):
|
||||||
|
|||||||
@@ -114,10 +114,10 @@ def write_file(file, data):
|
|||||||
with open(file, mode='w', encoding='utf-8') as f:
|
with open(file, mode='w', encoding='utf-8') as f:
|
||||||
if isinstance(data, list):
|
if isinstance(data, list):
|
||||||
yaml.safe_dump_all(data, f, default_flow_style=False, encoding='utf-8', allow_unicode=True,
|
yaml.safe_dump_all(data, f, default_flow_style=False, encoding='utf-8', allow_unicode=True,
|
||||||
sort_keys=False)
|
sort_keys=False)
|
||||||
else:
|
else:
|
||||||
yaml.safe_dump(data, f, default_flow_style=False, encoding='utf-8', allow_unicode=True,
|
yaml.safe_dump(data, f, default_flow_style=False, encoding='utf-8', allow_unicode=True,
|
||||||
sort_keys=False)
|
sort_keys=False)
|
||||||
elif ext == '.json':
|
elif ext == '.json':
|
||||||
with open(file, mode='w', encoding='utf-8') as f:
|
with open(file, mode='w', encoding='utf-8') as f:
|
||||||
s = json.dumps(data, indent=2, ensure_ascii=False, sort_keys=False, default=str)
|
s = json.dumps(data, indent=2, ensure_ascii=False, sort_keys=False, default=str)
|
||||||
@@ -130,7 +130,7 @@ def iter_folder(folder, ext=None):
|
|||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
folder (str):
|
folder (str):
|
||||||
ext (str): File extension
|
ext (str): File extension, such as `.yaml`
|
||||||
|
|
||||||
Yields:
|
Yields:
|
||||||
str: Absolute path of files
|
str: Absolute path of files
|
||||||
@@ -144,6 +144,19 @@ def iter_folder(folder, ext=None):
|
|||||||
yield os.path.join(folder, file)
|
yield os.path.join(folder, file)
|
||||||
|
|
||||||
|
|
||||||
|
def alas_instance():
|
||||||
|
"""
|
||||||
|
Returns:
|
||||||
|
list[str]: Name of all Alas instances, except `template`.
|
||||||
|
"""
|
||||||
|
out = []
|
||||||
|
for file in os.listdir('./config'):
|
||||||
|
name, extension = os.path.splitext(file)
|
||||||
|
if name != 'template' and extension == '.json':
|
||||||
|
out.append(name)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
def deep_get(d, keys, default=None):
|
def deep_get(d, keys, default=None):
|
||||||
"""
|
"""
|
||||||
Get values in dictionary safely.
|
Get values in dictionary safely.
|
||||||
|
|||||||
Reference in New Issue
Block a user