更新用户界面, 修复总复习

This commit is contained in:
2025-09-14 01:54:33 +08:00
parent 50a5b9b108
commit 19d0e32b6f
12 changed files with 93 additions and 49 deletions

View File

@@ -155,7 +155,7 @@ class Nucleon:
return Nucleon("核子对象样例内容", {})
class NucleonUnion:
class NucleonUnion():
"""
替代原有 NucleonFile 类, 支持复杂逻辑
@@ -171,7 +171,7 @@ class NucleonUnion:
path (Path): 包含核子数据的文件路径。
"""
def __init__(self, path):
def __init__(self, path: pathlib.Path):
self.path = path
self.name = path.name.replace(path.suffix, "")
with open(path, 'r') as f:
@@ -190,6 +190,12 @@ class NucleonUnion:
def __len__(self):
return len(self.nucleons)
def linked_electron_union(self):
if (self.path.parent / '..' / 'electron' / self.path.name).exists():
return ElectronUnion(self.path.parent / '..' / 'electron' / self.path.name)
else:
return 0
def save(self):
with open(self.path, 'w') as f:
@@ -199,9 +205,9 @@ class NucleonUnion:
class ElectronUnion:
"""取代原有 ElectronFile 类, 以支持复杂逻辑"""
def __init__(self, path):
self.path = path
print(path)
self.name = path.name.replace(path.suffix, "")
with open(path, 'r') as f:
all = toml.load(f)
@@ -214,8 +220,14 @@ class ElectronUnion:
self.electrons_dict = {i.content: i for i in lst}
def sync(self):
"""同步 electrons_dict 中新增对到 electrons 中"""
"""同步 electrons_dict 中新增对到 electrons 中, 仅用于缺省初始化不存在映射时调用"""
self.electrons = self.electrons_dict.values()
def __len__(self):
return len(self.electrons)
def linked_nucleon_union(self):
return NucleonUnion(self.path.parent / '..' / 'nucleon' / self.path.name)
def save(self):
# print(1)
@@ -227,34 +239,6 @@ class ElectronUnion:
toml.dump(tmp, f)
"""
class AtomicFile():
def __init__(self, path, type_="unknown"):
self.path = path
self.type_ = type_
if type_ == "nucleon":
self.name, self.datalist = Nucleon.import_from_file(pathlib.Path(path))
if type_ == "electron":
self.name, self.datalist = Electron.import_from_file(pathlib.Path(path))
def save(self):
dictobj = {i.content: i.export_data() for i in self.datalist}
print(dictobj)
if self.type_ == "nucleon":
Nucleon.save_to_file(dictobj, self.path)
if self.type_ == "electron":
Electron.save_to_file(dictobj, self.path)
def get_full_content(self):
if self.type_ == "nucleon":
text = ""
for i in self.datalist:
text += i.content
return text
return ""
def get_len(self):
return len(self.datalist)
"""
class Atom:
@staticmethod
def placeholder():