fix: 修复消息处理导致的闪退问题
This commit is contained in:
@@ -18,7 +18,7 @@ class AtomState(Enum):
|
|||||||
class MemScreen(Screen):
|
class MemScreen(Screen):
|
||||||
BINDINGS = [
|
BINDINGS = [
|
||||||
("q", "pop_screen", "返回"),
|
("q", "pop_screen", "返回"),
|
||||||
("p", "pop_screen", "上一个"),
|
#("p", "prev", "上一个"),
|
||||||
("d", "toggle_dark", "改变色调"),
|
("d", "toggle_dark", "改变色调"),
|
||||||
("v", "play_voice", "朗读"),
|
("v", "play_voice", "朗读"),
|
||||||
]
|
]
|
||||||
@@ -29,30 +29,35 @@ class MemScreen(Screen):
|
|||||||
def __init__(self, atoms: list, name: str | None = None, id: str | None = None, classes: str | None = None) -> None:
|
def __init__(self, atoms: list, name: str | None = None, id: str | None = None, classes: str | None = None) -> None:
|
||||||
super().__init__(name, id, classes)
|
super().__init__(name, id, classes)
|
||||||
self.atoms = atoms
|
self.atoms = atoms
|
||||||
#print(atoms)
|
|
||||||
self.phaser = Phaser(atoms)
|
self.phaser = Phaser(atoms)
|
||||||
|
#print(self.phaser.state)
|
||||||
self.procession: Procession = self.phaser.current_procession() # type: ignore
|
self.procession: Procession = self.phaser.current_procession() # type: ignore
|
||||||
|
#print(self.phaser.state)
|
||||||
|
|
||||||
def current_widget(self):
|
def current_widget(self):
|
||||||
|
try:
|
||||||
self.fission = Fission(self.procession.current_atom, self.phaser.state)
|
self.fission = Fission(self.procession.current_atom, self.phaser.state)
|
||||||
puzzle_info = next(self.fission.generate())
|
puzzle_info = next(self.fission.generate())
|
||||||
print(puzzle_info)
|
print(puzzle_info)
|
||||||
return shim.puzzle2widget[puzzle_info["puzzle"]](atom = self.procession.current_atom, alia = puzzle_info["alia"])
|
return shim.puzzle2widget[puzzle_info["puzzle"]](atom = self.procession.current_atom, alia = puzzle_info["alia"])
|
||||||
|
except (KeyError, StopIteration, AttributeError) as e:
|
||||||
|
print(f"Fission error: {e}")
|
||||||
|
return Static("无法生成谜题")
|
||||||
#print(shim.puzzle2widget[puzzle_info["puzzle"]])
|
#print(shim.puzzle2widget[puzzle_info["puzzle"]])
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Header(show_clock=True)
|
yield Header(show_clock=True)
|
||||||
with Center():
|
with Center():
|
||||||
yield Static(f"当前进度: {self.procession.process()}/{self.procession.total_length()}")
|
yield Static(f"当前进度: {self.procession.process()}/{self.procession.total_length()}")
|
||||||
#self.mount(self.current_widget()) # type: ignore
|
self.mount(self.current_widget()) # type: ignore
|
||||||
yield Button("重新学习此单元", id="re-recognize", variant="warning")
|
#yield Button("重新学习此单元", id="re-recognize", variant="warning")
|
||||||
yield Footer()
|
yield Footer()
|
||||||
|
|
||||||
def on_mount(self):
|
def on_mount(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_button_pressed(self, event):
|
def on_button_pressed(self, event):
|
||||||
pass
|
event.stop()
|
||||||
|
|
||||||
def action_play_voice(self):
|
def action_play_voice(self):
|
||||||
"""朗读当前内容"""
|
"""朗读当前内容"""
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ class PreparationScreen(Screen):
|
|||||||
yield Header(show_clock=True)
|
yield Header(show_clock=True)
|
||||||
with Container(id="vice_container"):
|
with Container(id="vice_container"):
|
||||||
yield Label(f"准备就绪: [b]{self.nucleon_file.stem}[/b]\n")
|
yield Label(f"准备就绪: [b]{self.nucleon_file.stem}[/b]\n")
|
||||||
yield Label(f"内容源文件对象: ./nucleon/[b]{self.nucleon_file.name}[/b].toml")
|
yield Label(f"内容源文件对象: ./nucleon/[b]{self.nucleon_file.name}[/b]")
|
||||||
yield Label(f"元数据文件对象: ./electron/[b]{self.electron_file.name}[/b].toml")
|
yield Label(f"元数据文件对象: ./electron/[b]{self.electron_file.name}[/b]")
|
||||||
yield Label(f"\n单元数量: {len(self.nucleons_with_orbital)}\n")
|
yield Label(f"\n单元数量: {len(self.nucleons_with_orbital)}\n")
|
||||||
|
|
||||||
yield Button(
|
yield Button(
|
||||||
@@ -75,7 +75,8 @@ class PreparationScreen(Screen):
|
|||||||
def action_quit_app(self):
|
def action_quit_app(self):
|
||||||
self.app.exit()
|
self.app.exit()
|
||||||
|
|
||||||
def on_button_pressed(self, event) -> None:
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||||
|
event.stop()
|
||||||
if event.button.id == "start_memorizing_button":
|
if event.button.id == "start_memorizing_button":
|
||||||
atoms = list()
|
atoms = list()
|
||||||
for nucleon, orbital in self.nucleons_with_orbital:
|
for nucleon, orbital in self.nucleons_with_orbital:
|
||||||
@@ -98,3 +99,4 @@ class PreparationScreen(Screen):
|
|||||||
self.app.push_screen(memscreen)
|
self.app.push_screen(memscreen)
|
||||||
elif event.button.id == "precache_button":
|
elif event.button.id == "precache_button":
|
||||||
self.action_precache()
|
self.action_precache()
|
||||||
|
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
"""
|
||||||
|
Particle 模块 - 粒子对象系统
|
||||||
|
|
||||||
|
提供闪卡所需对象, 使用物理学粒子的领域驱动设计
|
||||||
|
"""
|
||||||
|
|
||||||
from .electron import Electron
|
from .electron import Electron
|
||||||
from .nucleon import Nucleon
|
from .nucleon import Nucleon
|
||||||
from .orbital import Orbital
|
from .orbital import Orbital
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class Phaser():
|
|||||||
|
|
||||||
def current_procession(self):
|
def current_procession(self):
|
||||||
for i in self.processions:
|
for i in self.processions:
|
||||||
|
i: Procession
|
||||||
if not i.state == ProcessionState.FINISHED:
|
if not i.state == ProcessionState.FINISHED:
|
||||||
self.state = i.phase
|
self.state = i.phase
|
||||||
return i
|
return i
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ class Procession():
|
|||||||
def forward(self, step = 1):
|
def forward(self, step = 1):
|
||||||
self.cursor += step
|
self.cursor += step
|
||||||
if self.cursor == len(self.queue):
|
if self.cursor == len(self.queue):
|
||||||
self.state: ProcessionState = ProcessionState.FINISHED
|
self.state = ProcessionState.FINISHED
|
||||||
else:
|
else:
|
||||||
self.state: ProcessionState = ProcessionState.RUNNING
|
self.state = ProcessionState.RUNNING
|
||||||
try:
|
try:
|
||||||
self.current_atom = self.queue[self.cursor]
|
self.current_atom = self.queue[self.cursor]
|
||||||
return 1 # 成功
|
return 1 # 成功
|
||||||
|
|||||||
Reference in New Issue
Block a user