中途改进

This commit is contained in:
2025-07-30 23:10:43 +08:00
parent 722ae6f72c
commit 4d6d1f1b60
5 changed files with 98 additions and 14 deletions

View File

57
compositions.py Normal file
View File

@@ -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()

View File

@@ -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 = []

View File

@@ -243,4 +243,24 @@ class ElectronUnion():
class Atom():
@staticmethod
def placeholder():
return (Electron.placeholder(), Nucleon.placeholder())
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
})

View File

@@ -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()