#!/usr/bin/env python3 from textual.app import ComposeResult from textual.widgets import Header, Footer, Label, Static, Button from textual.containers import Center from textual.screen import Screen from enum import Enum, auto from heurams.context import config_var from heurams.kernel.reactor import * import heurams.kernel.particles as pt import heurams.kernel.puzzles as pz from .. import shim class AtomState(Enum): FAILED = auto() NORMAL = auto() class MemScreen(Screen): BINDINGS = [ ("q", "pop_screen", "返回"), #("p", "prev", "上一个"), ("d", "toggle_dark", "改变色调"), ("v", "play_voice", "朗读"), ] if config_var.get()["quick_pass"]: BINDINGS.append(("k", "quick_pass", "跳过")) 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 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): 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"调度展开出错: {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") yield Footer() def on_mount(self): pass def on_button_pressed(self, event): event.stop() def action_play_voice(self): """朗读当前内容""" pass def action_toggle_dark(self): self.app.action_toggle_dark() def action_pop_screen(self): self.app.pop_screen()