From 4d6d1f1b602a4d77ab478a68e1b9e5482b97773d Mon Sep 17 00:00:00 2001 From: david-ajax Date: Wed, 30 Jul 2025 23:10:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E9=80=94=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.py | 0 compositions.py | 57 +++++++++++++++++++++++++++++++++++++++++++++ nucleon/陈情表.toml | 4 ++-- particles.py | 22 ++++++++++++++++- reactor.py | 29 ++++++++++++++--------- 5 files changed, 98 insertions(+), 14 deletions(-) delete mode 100644 composer.py create mode 100644 compositions.py diff --git a/composer.py b/composer.py deleted file mode 100644 index e69de29..0000000 diff --git a/compositions.py b/compositions.py new file mode 100644 index 0000000..22e6f01 --- /dev/null +++ b/compositions.py @@ -0,0 +1,57 @@ +from textual.app import App, ComposeResult +from textual.events import Event +from textual.widgets import Header, Footer, ListView, ListItem, Label, Static, Button +from textual.containers import Container, Horizontal +from textual.screen import Screen +import pathlib +import particles as pt + +class Composition(): + def __init__(self, screen: Screen, atom): + self.screen = screen + self.atom = atom + def compose(self): + yield Label("示例标签", id="testlabel") + yield Button("示例按钮", id="testbtn") + def handler(self, event): + print(event.button.id) + self.screen.query_one("#testlabel", Label).update("hi") + +class Recognition(Composition): + def __init__(self, screen: Screen, atom): + pass + +# TEST + +class TestScreen(Screen): + def __init__(self): + super().__init__(name=None, id=None, classes=None) + self.comp = Composition(self, pt.Atom.advanced_placeholder()) + def compose(self) -> ComposeResult: + yield Header(show_clock=True) + yield from self.comp.compose() + yield Footer() + def on_mount(self) -> None: + pass + + def on_button_pressed(self, event: Event) -> None: + self.comp.handler(event) + + def action_quit_app(self) -> None: + self.app.exit() + +class AppLauncher(App): + CSS_PATH = "styles.tcss" + TITLE = '测试布局' + BINDINGS = [("escape", "quit", "退出"), ("d", "toggle_dark", "改变色调")] + SCREENS = { + "testscreen": TestScreen, + } + + def on_mount(self) -> None: + self.action_toggle_dark() + self.push_screen("testscreen") + +if __name__ == "__main__": + app = AppLauncher() + app.run() diff --git a/nucleon/陈情表.toml b/nucleon/陈情表.toml index f8004aa..f385a37 100644 --- a/nucleon/陈情表.toml +++ b/nucleon/陈情表.toml @@ -9,9 +9,9 @@ translation = "语句翻译" # 记忆时显示的额外信息 additional_inf = ["translation", "note"] # 填空测试 -fill_blank = ["translation"] +fill_blank_test = ["translation"] # 选择题测试 -draw_card = ["keyword_note"] +draw_card_test = ["keyword_note"] ["臣密言:臣以险衅, 夙遭闵凶."] note = [] diff --git a/particles.py b/particles.py index 7e2843f..6380d09 100644 --- a/particles.py +++ b/particles.py @@ -243,4 +243,24 @@ class ElectronUnion(): class Atom(): @staticmethod def placeholder(): - return (Electron.placeholder(), Nucleon.placeholder()) \ No newline at end of file + return (Electron.placeholder(), Nucleon.placeholder(), {}) + + @staticmethod + def advanced_placeholder(): + return ( + Electron("两只黄鹤鸣翠柳", {}), + Nucleon("两只黄鹤鸣翠柳", {"note": [], + "translation": "臣子李密陈言:我因命运不好,小时候遭遇到了不幸", + "keyword_note": {"险衅":"凶险祸患(这里指命运不好)", "夙":"早时,这里指年幼的时候", "闵":"通'悯',指可忧患的事", "凶":"不幸,指丧父"}}), + { + "keydata":{ + "note": "笔记", + "keyword_note": "关键词翻译", + "translation": "语句翻译"}, + "testdata":{ + "additional_inf": ["translation", "note"], + "fill_blank_test": ["translation"], + "draw_card_test": ["keyword_note"] + }, + "is_new_activation": 0 + }) \ No newline at end of file diff --git a/reactor.py b/reactor.py index 8abb0b8..df387e9 100644 --- a/reactor.py +++ b/reactor.py @@ -2,20 +2,24 @@ import typing import particles as pt import pathlib import auxiliary as aux +import compositions class Apparatus(): """反应器对象, 处理一个原子的记忆工作, 并反馈到布局""" def __init__(self, atom): - self.electron = atom[0] - self.nucleon = atom[1] - - def report(self): + self.electron: pt.Electron = atom[0] + self.nucleon: pt.Nucleon = atom[1] + self.positron: dict = atom[2] + self.testdata = self.positron["testdata"] + + def iterator(self): pass - def assess(self): - pass + def composer(self): + if self.positron["is_new_activation"] == 1: + self.positron["is_new_activation"] = 0 - def iterate(self): + def updater(self): pass @@ -35,23 +39,26 @@ class Reactor(): def electron_dict_get_fallback(key) -> pt.Electron: value = self.electron_dict.get(key) - # 如果值不存在,则设置默认值 if value is None: value = pt.Electron(key, {}) # 获取默认值 self.electron_dict[key] = value # 将默认值存入字典 electron_file.sync() - return value # 返回获取的值(可能是默认值) for nucleon in nucleon_file.nucleons: - atom = (electron_dict_get_fallback(nucleon.content), nucleon) + # atom = (Electron, Nucleon, Positron) 即 (记忆元数据, 内容元数据, 运行时数据) + atom = (electron_dict_get_fallback(nucleon.content), nucleon, {}) # 使用 "Positron" 代称 atom[2] + atom[2]["testdata"] = nucleon_file.testdata + atom[2]["keydata"] = nucleon_file.keydata if atom[0]["is_activated"] == 0: if counter > 0: + atom[2]["is_new_activation"] = 1 atom[0]["is_activated"] = 1 self.atoms_new.append(atom) counter -= 1 else: + atom[2]["is_new_activation"] = 0 if int(atom[0]["next_date"]) <= aux.get_daystamp(): atom[0]["last_date"] = aux.get_daystamp() self.atoms_review.append(atom) @@ -61,7 +68,7 @@ class Reactor(): self.failed: list self.round_title: str self.reported: set - self.current_atom: typing.Tuple[pt.Electron, pt.Nucleon] + self.current_atom: typing.Tuple[pt.Electron, pt.Nucleon, dict] self.round_set = 0 self.current_atom = pt.Atom.placeholder()