63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
import sys
|
|
from typing import Dict, List
|
|
|
|
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
|
|
|
|
from graph.DataType import Arrow, Point
|
|
from graph.directed_acyclic_graph.DAGPresent import DAGActiveView, Direction
|
|
from parse.StoryMap import StoryMap, XAST_ParseTool
|
|
from parse.ast_load import global_ast_path
|
|
|
|
|
|
class FragmentPoint(Point):
|
|
def __init__(self, name: str, start_mark: bool):
|
|
Point.__init__(self, name, start_mark)
|
|
pass
|
|
|
|
|
|
class ContentWindow(QWidget):
|
|
def __init__(self, parent):
|
|
QWidget.__init__(self, parent)
|
|
layout = QVBoxLayout(self)
|
|
self.fragment_view = DAGActiveView(Direction.RankLR, self)
|
|
layout.addWidget(self.fragment_view)
|
|
pass
|
|
pass
|
|
|
|
def present_stories_graph(self, graph: Dict[str, StoryMap]) -> None:
|
|
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(
|
|
FragmentPoint(start_node_label, fragi == 1),
|
|
FragmentPoint(end_node_label, False))
|
|
)
|
|
pass
|
|
pass
|
|
|
|
self.fragment_view.update_with_edges(arrows)
|
|
pass
|
|
|
|
|
|
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())
|
|
|
|
app.exec() |