2024-07-31 06:08:22 +00:00
|
|
|
import sys
|
|
|
|
from typing import Dict, List
|
|
|
|
|
2024-07-31 16:07:08 +00:00
|
|
|
from PyQt5.QtCore import QPoint
|
2024-08-01 00:57:25 +00:00
|
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow
|
|
|
|
from PyQt5.QtWidgets import QMenu
|
2024-07-31 06:08:22 +00:00
|
|
|
|
2024-07-31 03:47:09 +00:00
|
|
|
from graph.DataType import Arrow, Point
|
2024-08-01 00:57:25 +00:00
|
|
|
from graph.directed_acyclic_graph.DAGPresent import DAGActiveView
|
2024-07-31 06:08:22 +00:00
|
|
|
from parse.StoryMap import StoryMap, XAST_ParseTool
|
2024-07-31 03:47:09 +00:00
|
|
|
from parse.ast_load import global_ast_path
|
2024-07-30 14:30:59 +00:00
|
|
|
|
2024-07-31 03:47:09 +00:00
|
|
|
|
|
|
|
class FragmentPoint(Point):
|
2024-07-31 16:07:08 +00:00
|
|
|
def __init__(self, name: str):
|
|
|
|
Point.__init__(self, name)
|
2024-07-31 03:47:09 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2024-07-31 16:07:08 +00:00
|
|
|
class ContentWindow(QMainWindow):
|
2024-07-31 03:47:09 +00:00
|
|
|
def __init__(self, parent):
|
2024-07-31 16:07:08 +00:00
|
|
|
QMainWindow.__init__(self, parent)
|
|
|
|
self.fragment_view = DAGActiveView(self)
|
|
|
|
self.setCentralWidget(self.fragment_view)
|
|
|
|
self.fragment_view.nodes_clicked.connect(self.print_node_list)
|
|
|
|
self.present_graph: Dict[str, StoryMap] = None
|
2024-07-31 03:47:09 +00:00
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
def present_stories_graph(self, graph: Dict[str, StoryMap]) -> None:
|
2024-07-31 16:07:08 +00:00
|
|
|
self.present_graph = graph
|
|
|
|
|
2024-07-31 03:47:09 +00:00
|
|
|
arrows: List[Arrow] = []
|
|
|
|
for story_name in graph:
|
|
|
|
fragments = graph[story_name].slice_list
|
|
|
|
for fragi in range(1, len(fragments)):
|
|
|
|
start_frag = fragments[fragi - 1]
|
|
|
|
start_node_label = f"{start_frag.parent_story}&{start_frag.is_define_node[1]}"
|
|
|
|
if not start_frag.is_define_node[0]:
|
|
|
|
start_node_label = f"{start_frag.story_refer}&{start_frag.fragm_refer}"
|
|
|
|
if fragi == 1:
|
|
|
|
start_node_label = story_name
|
|
|
|
|
|
|
|
end_frag = fragments[fragi]
|
|
|
|
end_node_label = f"{end_frag.parent_story}&{end_frag.is_define_node[1]}"
|
|
|
|
if not end_frag.is_define_node[0]:
|
|
|
|
end_node_label = f"{end_frag.story_refer}&{end_frag.fragm_refer}"
|
|
|
|
|
|
|
|
arrows.append(Arrow(
|
2024-07-31 16:07:08 +00:00
|
|
|
FragmentPoint(start_node_label),
|
|
|
|
FragmentPoint(end_node_label))
|
2024-07-31 03:47:09 +00:00
|
|
|
)
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
self.fragment_view.update_with_edges(arrows)
|
|
|
|
pass
|
|
|
|
|
2024-07-31 16:07:08 +00:00
|
|
|
def print_node_list(self, xpos, ypos, list):
|
|
|
|
if len(list) == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
if len(list) > 1:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
node_x = list[0]
|
|
|
|
if node_x[0].startswith("node"):
|
|
|
|
node_sections = [s for s in node_x[1].split("&") if s != ""]
|
|
|
|
if len(node_sections) == 1:
|
|
|
|
story = self.present_graph[node_sections[0]]
|
|
|
|
node_names = [node_sections[0]]
|
|
|
|
for slice in story.slice_list[1:]:
|
|
|
|
if slice.is_define_node[0]:
|
|
|
|
node_names.append(f"{slice.parent_story}&{slice.is_define_node[1]}")
|
|
|
|
else:
|
|
|
|
node_names.append(f"{slice.story_refer}&{slice.fragm_refer}")
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
self.fragment_view.highlight_graph_link(node_names)
|
|
|
|
pass
|
|
|
|
elif len(node_sections) > 1:
|
|
|
|
story_node = self.present_graph[node_sections[0]]
|
|
|
|
fragm_node = story_node.get_fragment_defined(node_sections[1])
|
|
|
|
|
|
|
|
story_list = [node_sections[0]]
|
|
|
|
for vsname in fragm_node.refers_slice:
|
|
|
|
if vsname not in story_list:
|
|
|
|
story_list.append(vsname)
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
if len(story_list) == 1:
|
|
|
|
self.print_node_list(xpos, ypos, [("node", story_list[0])])
|
|
|
|
elif len(story_list) > 1:
|
|
|
|
menu = QMenu()
|
|
|
|
for story in story_list:
|
|
|
|
def trigger(story_name:str):
|
|
|
|
return lambda : self.print_node_list(xpos, ypos, [("node", story_name)])
|
|
|
|
|
|
|
|
menu.addAction(f"story/{story}", trigger(story))
|
|
|
|
pass
|
|
|
|
|
|
|
|
menu.exec(self.fragment_view.mapToGlobal(QPoint(xpos, ypos)))
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
print(story_list)
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
2024-07-31 03:47:09 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
view = ContentWindow(None)
|
|
|
|
view.show()
|
|
|
|
|
|
|
|
tool = XAST_ParseTool(global_ast_path)
|
|
|
|
view.present_stories_graph(tool.get_story_graph())
|
|
|
|
|
2024-07-31 16:07:08 +00:00
|
|
|
# view.fragment_view.highlight_graph_link(["血脉的源头", "血脉的源头&待续"])
|
|
|
|
|
2024-07-31 03:47:09 +00:00
|
|
|
app.exec()
|