fix: 修复消息处理导致的闪退问题
This commit is contained in:
@@ -18,7 +18,7 @@ class AtomState(Enum):
|
||||
class MemScreen(Screen):
|
||||
BINDINGS = [
|
||||
("q", "pop_screen", "返回"),
|
||||
("p", "pop_screen", "上一个"),
|
||||
#("p", "prev", "上一个"),
|
||||
("d", "toggle_dark", "改变色调"),
|
||||
("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:
|
||||
super().__init__(name, id, classes)
|
||||
self.atoms = atoms
|
||||
#print(atoms)
|
||||
self.phaser = Phaser(atoms)
|
||||
#print(self.phaser.state)
|
||||
self.procession: Procession = self.phaser.current_procession() # type: ignore
|
||||
#print(self.phaser.state)
|
||||
|
||||
def current_widget(self):
|
||||
self.fission = Fission(self.procession.current_atom, self.phaser.state)
|
||||
puzzle_info = next(self.fission.generate())
|
||||
print(puzzle_info)
|
||||
return shim.puzzle2widget[puzzle_info["puzzle"]](atom = self.procession.current_atom, alia = puzzle_info["alia"])
|
||||
try:
|
||||
self.fission = Fission(self.procession.current_atom, self.phaser.state)
|
||||
puzzle_info = next(self.fission.generate())
|
||||
print(puzzle_info)
|
||||
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"]])
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(show_clock=True)
|
||||
with Center():
|
||||
yield Static(f"当前进度: {self.procession.process()}/{self.procession.total_length()}")
|
||||
#self.mount(self.current_widget()) # type: ignore
|
||||
yield Button("重新学习此单元", id="re-recognize", variant="warning")
|
||||
self.mount(self.current_widget()) # type: ignore
|
||||
#yield Button("重新学习此单元", id="re-recognize", variant="warning")
|
||||
yield Footer()
|
||||
|
||||
def on_mount(self):
|
||||
pass
|
||||
|
||||
def on_button_pressed(self, event):
|
||||
pass
|
||||
event.stop()
|
||||
|
||||
def action_play_voice(self):
|
||||
"""朗读当前内容"""
|
||||
|
||||
Reference in New Issue
Block a user