中途改进
This commit is contained in:
57
compositions.py
Normal file
57
compositions.py
Normal 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()
|
@@ -9,9 +9,9 @@ translation = "语句翻译"
|
|||||||
# 记忆时显示的额外信息
|
# 记忆时显示的额外信息
|
||||||
additional_inf = ["translation", "note"]
|
additional_inf = ["translation", "note"]
|
||||||
# 填空测试
|
# 填空测试
|
||||||
fill_blank = ["translation"]
|
fill_blank_test = ["translation"]
|
||||||
# 选择题测试
|
# 选择题测试
|
||||||
draw_card = ["keyword_note"]
|
draw_card_test = ["keyword_note"]
|
||||||
|
|
||||||
["臣密言:臣以险衅, 夙遭闵凶."]
|
["臣密言:臣以险衅, 夙遭闵凶."]
|
||||||
note = []
|
note = []
|
||||||
|
22
particles.py
22
particles.py
@@ -243,4 +243,24 @@ class ElectronUnion():
|
|||||||
class Atom():
|
class Atom():
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def placeholder():
|
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
|
||||||
|
})
|
29
reactor.py
29
reactor.py
@@ -2,20 +2,24 @@ import typing
|
|||||||
import particles as pt
|
import particles as pt
|
||||||
import pathlib
|
import pathlib
|
||||||
import auxiliary as aux
|
import auxiliary as aux
|
||||||
|
import compositions
|
||||||
|
|
||||||
class Apparatus():
|
class Apparatus():
|
||||||
"""反应器对象, 处理一个原子的记忆工作, 并反馈到布局"""
|
"""反应器对象, 处理一个原子的记忆工作, 并反馈到布局"""
|
||||||
def __init__(self, atom):
|
def __init__(self, atom):
|
||||||
self.electron = atom[0]
|
self.electron: pt.Electron = atom[0]
|
||||||
self.nucleon = atom[1]
|
self.nucleon: pt.Nucleon = atom[1]
|
||||||
|
self.positron: dict = atom[2]
|
||||||
def report(self):
|
self.testdata = self.positron["testdata"]
|
||||||
|
|
||||||
|
def iterator(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def assess(self):
|
def composer(self):
|
||||||
pass
|
if self.positron["is_new_activation"] == 1:
|
||||||
|
self.positron["is_new_activation"] = 0
|
||||||
|
|
||||||
def iterate(self):
|
def updater(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -35,23 +39,26 @@ class Reactor():
|
|||||||
|
|
||||||
def electron_dict_get_fallback(key) -> pt.Electron:
|
def electron_dict_get_fallback(key) -> pt.Electron:
|
||||||
value = self.electron_dict.get(key)
|
value = self.electron_dict.get(key)
|
||||||
|
|
||||||
# 如果值不存在,则设置默认值
|
# 如果值不存在,则设置默认值
|
||||||
if value is None:
|
if value is None:
|
||||||
value = pt.Electron(key, {}) # 获取默认值
|
value = pt.Electron(key, {}) # 获取默认值
|
||||||
self.electron_dict[key] = value # 将默认值存入字典
|
self.electron_dict[key] = value # 将默认值存入字典
|
||||||
electron_file.sync()
|
electron_file.sync()
|
||||||
|
|
||||||
return value # 返回获取的值(可能是默认值)
|
return value # 返回获取的值(可能是默认值)
|
||||||
|
|
||||||
for nucleon in nucleon_file.nucleons:
|
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 atom[0]["is_activated"] == 0:
|
||||||
if counter > 0:
|
if counter > 0:
|
||||||
|
atom[2]["is_new_activation"] = 1
|
||||||
atom[0]["is_activated"] = 1
|
atom[0]["is_activated"] = 1
|
||||||
self.atoms_new.append(atom)
|
self.atoms_new.append(atom)
|
||||||
counter -= 1
|
counter -= 1
|
||||||
else:
|
else:
|
||||||
|
atom[2]["is_new_activation"] = 0
|
||||||
if int(atom[0]["next_date"]) <= aux.get_daystamp():
|
if int(atom[0]["next_date"]) <= aux.get_daystamp():
|
||||||
atom[0]["last_date"] = aux.get_daystamp()
|
atom[0]["last_date"] = aux.get_daystamp()
|
||||||
self.atoms_review.append(atom)
|
self.atoms_review.append(atom)
|
||||||
@@ -61,7 +68,7 @@ class Reactor():
|
|||||||
self.failed: list
|
self.failed: list
|
||||||
self.round_title: str
|
self.round_title: str
|
||||||
self.reported: set
|
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.round_set = 0
|
||||||
self.current_atom = pt.Atom.placeholder()
|
self.current_atom = pt.Atom.placeholder()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user