Add: Event Reaction (#4706)

* Add: Event Reaction

* Update widgets.py

* Update widgets.py

* Update widgets.py

* Update widgets.py

* Update widgets.py
This commit is contained in:
iceynano 2025-04-01 00:56:05 +08:00 committed by GitHub
parent 3a1e851cad
commit 3133eaa2f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 67 additions and 6 deletions

View File

@ -314,6 +314,16 @@ pre.rich-traceback-code {
margin: 0;
}
.anim-rotate {
animation: rotate-keyframes 0.4s linear infinite
}
@keyframes rotate-keyframes {
100% {
transform: rotate(360deg)
}
}
#pywebio-scope-contents {
margin-top: 0;
overflow-y: auto;

View File

@ -113,6 +113,11 @@ class AlasGUI(Frame):
self.alas_mod = "alas"
self.alas_config = AzurLaneConfig("template")
self.initial()
# rendered state cache
self.rendered_cache = []
self.inst_cache = []
self.load_home = False
self.af_flag = False
@use_scope("aside", clear=True)
def set_aside(self) -> None:
@ -122,12 +127,11 @@ class AlasGUI(Frame):
buttons=[{"label": t("Gui.Aside.Home"), "value": "Home", "color": "aside"}],
onclick=[self.ui_develop],
)
for name in alas_instance():
put_icon_buttons(
Icon.RUN,
buttons=[{"label": name, "value": name, "color": "aside"}],
onclick=self.ui_alas,
)
put_scope("aside_instance",[
put_scope(f"alas-instance-{i}",[])
for i, _ in enumerate(alas_instance())
])
self.set_aside_status()
put_icon_buttons(
Icon.SETTING,
buttons=[
@ -140,6 +144,51 @@ class AlasGUI(Frame):
onclick=[lambda: go_app("manage", new_window=False)],
)
current_date = datetime.now().date()
if current_date.month == 4 and current_date.day == 1:
self.af_flag = True
@use_scope("aside_instance")
def set_aside_status(self) -> None:
flag = True
def update(name, seq):
with use_scope(f"alas-instance-{seq}", clear=True):
icon_html = Icon.RUN
rendered_state = ProcessManager.get_manager(inst).state
if rendered_state == 1 and self.af_flag:
icon_html = icon_html[:31] + ' anim-rotate' + icon_html[31:]
put_icon_buttons(
icon_html,
buttons=[{"label": name, "value": name, "color": "aside"}],
onclick=self.ui_alas,
)
return rendered_state
if not len(self.rendered_cache) or self.load_home:
# Reload when add/delete new instance | first start app.py | go to HomePage (HomePage load call force reload)
flag = False
self.inst_cache.clear()
self.inst_cache = alas_instance()
if flag:
for index, inst in enumerate(self.inst_cache):
# Check for state change
state = ProcessManager.get_manager(inst).state
if state != self.rendered_cache[index]:
self.rendered_cache[index] = update(inst, index)
flag = False
else:
self.rendered_cache.clear()
clear("aside_instance")
for index, inst in enumerate(self.inst_cache):
self.rendered_cache.append(update(inst, index))
self.load_home = False
if not flag:
# Redraw lost focus, now focus on aside button
aside_name = get_localstorage("aside")
self.active_button("aside", aside_name)
return
@use_scope("header_status")
def set_status(self, state: int) -> None:
"""
@ -1049,6 +1098,7 @@ class AlasGUI(Frame):
def show(self) -> None:
self._show()
self.load_home = True
self.set_aside()
self.init_aside(name="Home")
self.dev_set_menu()
@ -1196,6 +1246,7 @@ class AlasGUI(Frame):
)
self.task_handler.add(self.state_switch.g(), 2)
self.task_handler.add(self.set_aside_status, 2)
self.task_handler.add(visibility_state_switch.g(), 15)
self.task_handler.add(update_switch.g(), 1)
self.task_handler.start()