diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2d48b85..edc6068 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,9 +6,10 @@ + - + - + + + + + @@ -156,6 +181,7 @@ + diff --git a/frame/ContentView.py b/frame/ContentView.py index 6322abd..4e8259a 100644 --- a/frame/ContentView.py +++ b/frame/ContentView.py @@ -1,4 +1,61 @@ -from PyQt5.QtWidgets import QApplication, QWidget -from networkx import DiGraph -import networkx as nx +from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout +from graph.directed_acyclic_graph.DAGPresent import DAGActiveView, Direction +from parse.StoryMap import StoryMap, FragmentSlice, XAST_ParseTool +from graph.DataType import Arrow, Point +import sys +from typing import Dict,List +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() \ No newline at end of file diff --git a/graph/DataType.py b/graph/DataType.py index 100a964..e98f09d 100644 --- a/graph/DataType.py +++ b/graph/DataType.py @@ -12,15 +12,16 @@ class Pos: class Point: - def __init__(self, name:str): + def __init__(self, name:str, start_mark: bool): self.point_name = name + self.is_start = start_mark pass def name(self) -> str: return self.point_name def make_copy(self) -> 'Point': - return Point(self.point_name) + return Point(self.point_name, self.is_start) class Line: diff --git a/graph/__pycache__/DataType.cpython-312.pyc b/graph/__pycache__/DataType.cpython-312.pyc index 7644fdf..43b744f 100644 Binary files a/graph/__pycache__/DataType.cpython-312.pyc and b/graph/__pycache__/DataType.cpython-312.pyc differ diff --git a/graph/directed_acyclic_graph/DAGPresent.py b/graph/directed_acyclic_graph/DAGPresent.py index 955fdd4..d0ba754 100644 --- a/graph/directed_acyclic_graph/DAGPresent.py +++ b/graph/directed_acyclic_graph/DAGPresent.py @@ -86,7 +86,7 @@ class PenetrateNode(QGraphicsItem, GraphNode): self.data_bind: object = None pass - def resize(self, width: float): + def resize_width(self, width: float): self.width_store = width self.update() pass @@ -177,9 +177,10 @@ class Direction(Enum): class DAGActiveView(QGraphicsView): def __init__(self, orie: Direction, parent): QGraphicsView.__init__(self, parent) + self.setViewportUpdateMode(QGraphicsView.ViewportUpdateMode.FullViewportUpdate) self.layer_span = 200 - self.node_span = 50 + self.node_span = 20 self.orientation = orie self.scene_bind = QGraphicsScene(self) @@ -216,7 +217,7 @@ class DAGActiveView(QGraphicsView): all_graphics_nodes.append(curr_gnode) self.scene_bind.addItem(curr_gnode) else: - if layer_idx == 0: + if node.layer_bind.bind_point().is_start: curr_gnode = StoryFragmentNode(node.layer_bind.bind_point().point_name, StoryNodeType.StoryStartNode, self.font(), None) else: @@ -238,8 +239,8 @@ class DAGActiveView(QGraphicsView): width_max = max(width_max, n.boundingRect().width()) pass for n in all_graphics_nodes: - if n is PenetrateNode: - n.resize(width_max) + if hasattr(n, "resize_width"): + n.resize_width(width_max) pass pass diff --git a/graph/directed_acyclic_graph/__pycache__/DAGPresent.cpython-312.pyc b/graph/directed_acyclic_graph/__pycache__/DAGPresent.cpython-312.pyc new file mode 100644 index 0000000..92622b1 Binary files /dev/null and b/graph/directed_acyclic_graph/__pycache__/DAGPresent.cpython-312.pyc differ diff --git a/parse/StoryMap.py b/parse/StoryMap.py index d9ed95c..f90d359 100644 --- a/parse/StoryMap.py +++ b/parse/StoryMap.py @@ -83,7 +83,7 @@ class XAST_ParseTool: if node.getAttribute("name") == name: mem_node = StoryMap(name) mem_node.sort_index = int(node.getAttribute("sort")) - return (mem_node, node) + return mem_node, node pass return None @@ -134,6 +134,12 @@ class XAST_ParseTool: pass pass pass + + def get_story_graph(self) -> Dict[str, StoryMap]: + story_dict = storyline_list2map(self.story_list) + self.storylines_plait(story_dict) + return story_dict + pass diff --git a/parse/__pycache__/StoryMap.cpython-312.pyc b/parse/__pycache__/StoryMap.cpython-312.pyc index 84dda60..23db8e7 100644 Binary files a/parse/__pycache__/StoryMap.cpython-312.pyc and b/parse/__pycache__/StoryMap.cpython-312.pyc differ