discopop-gui 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. discopop_gui/ClassMaps/Frames.py +15 -0
  2. discopop_gui/ClassMaps/ViewableCanvases.py +14 -0
  3. discopop_gui/ClassMaps/__init__.py +0 -0
  4. discopop_gui/Constants.py +10 -0
  5. discopop_gui/Enums/EdgeType.py +14 -0
  6. discopop_gui/Enums/FrameType.py +15 -0
  7. discopop_gui/Enums/ViewableCanvasTypes.py +14 -0
  8. discopop_gui/Enums/ViewerMode.py +14 -0
  9. discopop_gui/Enums/__init__.py +0 -0
  10. discopop_gui/Exceptions/VisualizerNotDefined.py +11 -0
  11. discopop_gui/Exceptions/__init__.py +0 -0
  12. discopop_gui/Extendables/Plottable.py +150 -0
  13. discopop_gui/Extendables/__init__.py +0 -0
  14. discopop_gui/Objects/CanvasItems/Popup.py +73 -0
  15. discopop_gui/Objects/CanvasItems/TreeEdges/Base.py +30 -0
  16. discopop_gui/Objects/CanvasItems/TreeEdges/Dependency.py +84 -0
  17. discopop_gui/Objects/CanvasItems/TreeEdges/Main.py +30 -0
  18. discopop_gui/Objects/CanvasItems/TreeEdges/__init__.py +0 -0
  19. discopop_gui/Objects/CanvasItems/TreeNode.py +945 -0
  20. discopop_gui/Objects/CanvasItems/__init__.py +0 -0
  21. discopop_gui/Objects/Canvases/RoundedSquareButtons/Cross.py +45 -0
  22. discopop_gui/Objects/Canvases/RoundedSquareButtons/Magnifier.py +21 -0
  23. discopop_gui/Objects/Canvases/RoundedSquareButtons/Mouse.py +31 -0
  24. discopop_gui/Objects/Canvases/RoundedSquareButtons/Panner.py +29 -0
  25. discopop_gui/Objects/Canvases/RoundedSquareButtons/Plus.py +44 -0
  26. discopop_gui/Objects/Canvases/RoundedSquareButtons/RoundedSquareButton.py +69 -0
  27. discopop_gui/Objects/Canvases/RoundedSquareButtons/__init__.py +0 -0
  28. discopop_gui/Objects/Canvases/Viewables/Base.py +235 -0
  29. discopop_gui/Objects/Canvases/Viewables/WithTrees.py +311 -0
  30. discopop_gui/Objects/Canvases/Viewables/__init__.py +0 -0
  31. discopop_gui/Objects/Canvases/__init__.py +0 -0
  32. discopop_gui/Objects/Frames/Base.py +22 -0
  33. discopop_gui/Objects/Frames/CanvasViewerWithTrees.py +343 -0
  34. discopop_gui/Objects/Frames/MultiFrame.py +81 -0
  35. discopop_gui/Objects/Frames/__init__.py +0 -0
  36. discopop_gui/Objects/__init__.py +0 -0
  37. discopop_gui/Types/FrameT.py +13 -0
  38. discopop_gui/Types/T.py +11 -0
  39. discopop_gui/Types/ViewableCanvasT.py +13 -0
  40. discopop_gui/Types/__init__.py +0 -0
  41. discopop_gui/Visualizers/Base.py +116 -0
  42. discopop_gui/Visualizers/WithSidebar.py +212 -0
  43. discopop_gui/Visualizers/__init__.py +0 -0
  44. discopop_gui/__init__.py +0 -0
  45. discopop_gui/py.typed +0 -0
  46. discopop_gui/utils/TreeNode.py +47 -0
  47. discopop_gui/utils/__init__.py +0 -0
  48. discopop_gui-0.0.1.dist-info/METADATA +78 -0
  49. discopop_gui-0.0.1.dist-info/RECORD +53 -0
  50. discopop_gui-0.0.1.dist-info/WHEEL +5 -0
  51. discopop_gui-0.0.1.dist-info/licenses/LICENSE +29 -0
  52. discopop_gui-0.0.1.dist-info/top_level.txt +1 -0
  53. discopop_gui-0.0.1.dist-info/zip-safe +1 -0
@@ -0,0 +1,15 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ from discopop_gui.Enums.FrameType import FrameType
10
+
11
+ FramesMap = {
12
+ "Base": FrameType.BASE,
13
+ "MultiFrame": FrameType.MULTI_FRAME,
14
+ "CanvasViewerWithTrees": FrameType.CANVAS_VIEWER_WITH_TREES,
15
+ }
@@ -0,0 +1,14 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ from discopop_gui.Enums.ViewableCanvasTypes import ViewableCanvasTypes
10
+
11
+ ViewableCanvasesMap = {
12
+ "Base": ViewableCanvasTypes.BASE,
13
+ "WithTrees": ViewableCanvasTypes.WITH_TREES,
14
+ }
File without changes
@@ -0,0 +1,10 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ TREE_NODES_SPACING: float = 100
10
+ TREE_NODE_RADIUS: float = 40
@@ -0,0 +1,14 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ from enum import Enum, auto
10
+
11
+
12
+ class EdgeType(Enum):
13
+ MAIN = auto()
14
+ DEPENDENCY = auto()
@@ -0,0 +1,15 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ from enum import Enum, auto
10
+
11
+
12
+ class FrameType(Enum):
13
+ BASE = auto()
14
+ MULTI_FRAME = auto()
15
+ CANVAS_VIEWER_WITH_TREES = auto()
@@ -0,0 +1,14 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ from enum import Enum, auto
10
+
11
+
12
+ class ViewableCanvasTypes(Enum):
13
+ BASE = auto()
14
+ WITH_TREES = auto()
@@ -0,0 +1,14 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ from enum import Enum, auto
10
+
11
+
12
+ class ViewerMode(Enum):
13
+ MAIN = auto()
14
+ ZOOM = auto()
File without changes
@@ -0,0 +1,11 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+
10
+ class VisualizerNotDefined(Exception):
11
+ pass
File without changes
@@ -0,0 +1,150 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ from typing import Any, Callable, Dict, List
10
+
11
+ from matplotlib.axes import Axes
12
+ from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg, NavigationToolbar2QT # type: ignore
13
+ from matplotlib.figure import Figure
14
+ from PySide6.QtWidgets import QVBoxLayout, QWidget
15
+
16
+ from discopop_gui.Visualizers.Base import Base
17
+ from discopop_gui.Objects.Frames.Base import Base as BaseFrame
18
+ from discopop_gui.Objects.Frames.MultiFrame import MultiFrame
19
+ from discopop_gui.Objects.Frames.CanvasViewerWithTrees import CanvasViewerWithTrees
20
+ from discopop_gui.Exceptions.VisualizerNotDefined import VisualizerNotDefined
21
+
22
+
23
+ class Plottable:
24
+ def __init__(self, visualizer: Base | None = None) -> None:
25
+ self._visualizer = visualizer
26
+
27
+ def __getstate__(self) -> Dict[str, Any]:
28
+ # The visualizer holds Qt widgets it draws on; a pickled or dumped graph (detection_result_dump.json)
29
+ # must not carry them, the copy is not plottable.
30
+ state = self.__dict__.copy()
31
+ state["_visualizer"] = None
32
+ return state
33
+
34
+ def __setstate__(self, state: Dict[str, Any]) -> None:
35
+ self.__dict__.update(state)
36
+ self.__dict__.setdefault("_visualizer", None)
37
+
38
+ def plottable(self) -> bool:
39
+ if self._visualizer is None:
40
+ return False
41
+
42
+ return True
43
+
44
+ def create_frame(self, name: str) -> BaseFrame:
45
+ if self._visualizer is None:
46
+ raise VisualizerNotDefined()
47
+
48
+ return self._visualizer.create_frame(name, BaseFrame)
49
+
50
+ def create_multi_frame(self, name: str, rows: int, columns: int) -> MultiFrame:
51
+ if self._visualizer is None:
52
+ raise VisualizerNotDefined()
53
+
54
+ if rows < 1 or columns < 1:
55
+ raise ValueError("Rows and columns must be >= 1")
56
+
57
+ def frame_builder(parent: QWidget) -> MultiFrame:
58
+ return MultiFrame(parent)
59
+
60
+ frame = self._visualizer.create_frame(name, frame_builder)
61
+
62
+ for row in range(rows):
63
+ frame._layout.setRowStretch(row, 1)
64
+
65
+ for column in range(columns):
66
+ frame._layout.setColumnStretch(column, 1)
67
+
68
+ inner_frames: List[BaseFrame] = []
69
+
70
+ for i in range(rows * columns):
71
+ row = i // columns
72
+ column = i % columns
73
+
74
+ inner_frame = frame.create_frame(row, column, lambda parent: BaseFrame(parent))
75
+ inner_frames.append(inner_frame)
76
+
77
+ frame.initialize(inner_frames)
78
+ return frame
79
+
80
+ def set_filter_callback(self, callback: Callable[[str], None]) -> None:
81
+ if self._visualizer is None:
82
+ raise VisualizerNotDefined()
83
+
84
+ self._visualizer.set_filter_callback(callback)
85
+
86
+ def delete_frame(self, frame_id: int) -> None:
87
+ if self._visualizer is None:
88
+ raise VisualizerNotDefined()
89
+
90
+ self._visualizer.delete_frame(frame_id)
91
+
92
+ def create_plot(self, name: str) -> Axes:
93
+ if self._visualizer is None:
94
+ raise VisualizerNotDefined()
95
+
96
+ frame: BaseFrame = self._visualizer.create_frame(name, BaseFrame)
97
+ layout = QVBoxLayout(frame)
98
+ layout.setContentsMargins(0, 0, 0, 0)
99
+
100
+ figure = Figure()
101
+ axes = figure.add_subplot(111)
102
+ axes.set_title("Task graph")
103
+ canvas = FigureCanvasQTAgg(figure)
104
+ canvas.draw()
105
+ toolbar = NavigationToolbar2QT(canvas, frame)
106
+
107
+ layout.addWidget(canvas, 1)
108
+ layout.addWidget(toolbar)
109
+ return axes
110
+
111
+ def create_plottable(self, name: str) -> CanvasViewerWithTrees:
112
+ if self._visualizer is None:
113
+ raise VisualizerNotDefined()
114
+
115
+ def frame_builder(parent: QWidget) -> CanvasViewerWithTrees:
116
+ return CanvasViewerWithTrees(parent)
117
+
118
+ frame = self._visualizer.create_frame(name, frame_builder)
119
+
120
+ return frame
121
+
122
+ def create_multi_plot(self, name: str, inner_plot_titles: list[str], rows: int, columns: int) -> list[Axes]:
123
+ frame = self.create_multi_frame(name, rows, columns)
124
+ axeses = []
125
+
126
+ for index in range(rows * columns):
127
+ inner_frame = frame.get_from_inner(index)
128
+ layout = QVBoxLayout(inner_frame)
129
+ layout.setContentsMargins(0, 0, 0, 0)
130
+
131
+ figure = Figure()
132
+ axes = figure.add_subplot(111)
133
+ axes.set_title(inner_plot_titles[index])
134
+ canvas = FigureCanvasQTAgg(figure)
135
+ canvas.draw()
136
+ toolbar = NavigationToolbar2QT(canvas, inner_frame)
137
+
138
+ layout.addWidget(canvas, 1)
139
+ layout.addWidget(toolbar)
140
+ axeses.append(axes)
141
+
142
+ return axeses
143
+
144
+ def run_visualizer(self) -> None:
145
+ if self._visualizer is not None:
146
+ self._visualizer.run()
147
+
148
+ def clear_visualizer(self) -> None:
149
+ if self._visualizer is not None:
150
+ self._visualizer.clear()
File without changes
@@ -0,0 +1,73 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import Callable
12
+
13
+ from PySide6.QtCore import QPoint
14
+ from PySide6.QtWidgets import QFrame, QPushButton, QVBoxLayout, QWidget
15
+
16
+
17
+ class Popup(QFrame):
18
+ def __init__(self, parent: QWidget, minimum_width: int = 150) -> None:
19
+ super().__init__(parent)
20
+ self._minimum_width = minimum_width
21
+ self._button_height = 30
22
+ self._buttons: dict[str, QPushButton] = {}
23
+
24
+ self.setFrameShape(QFrame.Shape.Box)
25
+
26
+ self.setStyleSheet(
27
+ "QFrame { background: #f2f2f2; border: 1px solid #999999; }"
28
+ "QPushButton { background: #ffffff; border: 0px; text-align: left; padding: 0 8px; }"
29
+ "QPushButton:hover { background: #cfe8ff; }"
30
+ )
31
+
32
+ self._layout = QVBoxLayout(self)
33
+ self._layout.setContentsMargins(2, 2, 2, 2)
34
+ self._layout.setSpacing(0)
35
+ self.hide()
36
+
37
+ def _update_layout(self) -> None:
38
+ for button in self._buttons.values():
39
+ button.setFixedHeight(self._button_height)
40
+
41
+ self.setMinimumWidth(self._minimum_width)
42
+ self.adjustSize()
43
+
44
+ def add_button(self, button_id: str, callback: Callable[[], None]) -> None:
45
+ button = QPushButton(button_id, self)
46
+
47
+ def on_click() -> None:
48
+ if self.isVisible():
49
+ self.hide()
50
+ callback()
51
+
52
+ button.clicked.connect(on_click)
53
+ self._layout.addWidget(button)
54
+ self._buttons[button_id] = button
55
+ self._update_layout()
56
+
57
+ def remove_button(self, button_id: str) -> None:
58
+ button = self._buttons.pop(button_id, None)
59
+
60
+ if button is not None:
61
+ self._layout.removeWidget(button)
62
+ button.deleteLater()
63
+ self._update_layout()
64
+
65
+ def clear_buttons(self) -> None:
66
+ for button_id in list(self._buttons):
67
+ self.remove_button(button_id)
68
+
69
+ def show_at(self, position: QPoint) -> None:
70
+ self._update_layout()
71
+ self.move(position)
72
+ self.raise_()
73
+ self.show()
@@ -0,0 +1,30 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ from typing import Generic, Callable, Dict, Any
10
+
11
+ from discopop_gui.Types.T import T
12
+
13
+
14
+ class Base(Generic[T]):
15
+ def __init__(self, source_node_id: T, target_node_id: T):
16
+ self._source_node_id = source_node_id
17
+ self._target_node_id = target_node_id
18
+
19
+ def get_source_node_id(self) -> T:
20
+ return self._source_node_id
21
+
22
+ def get_target_node_id(self) -> T:
23
+ return self._target_node_id
24
+
25
+ def serialize(self) -> Dict[str, Any]:
26
+ return {"source_node_id": str(self._source_node_id), "target_node_id": str(self._target_node_id)}
27
+
28
+ def deserialize(self, data: Dict[str, Any], converter: Callable[[str], T]) -> None:
29
+ self._source_node_id = converter(data["source_node_id"])
30
+ self._target_node_id = converter(data["target_node_id"])
@@ -0,0 +1,84 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ from collections import deque
10
+ from typing import Generic, Callable, Dict, Any
11
+
12
+ from discopop_gui.Types.T import T
13
+ from discopop_gui.Objects.CanvasItems.TreeEdges.Base import Base
14
+
15
+
16
+ class Dependency(Base[T], Generic[T]):
17
+ def __init__(self, source_node_id: T, target_node_id: T, highest_common_node_id: T | None = None):
18
+ super().__init__(source_node_id, target_node_id)
19
+
20
+ self._highest_common_node_id = highest_common_node_id
21
+ self._climbed_source_node_ids: deque[T] = deque()
22
+ self._climbed_target_node_ids: deque[T] = deque()
23
+
24
+ def get_highest_common_node_id(self) -> T | None:
25
+ return self._highest_common_node_id
26
+
27
+ def climb_source_node_id(self, node_id: T) -> bool:
28
+ if node_id == self._highest_common_node_id:
29
+ return False
30
+
31
+ self._climbed_source_node_ids.append(self._source_node_id)
32
+ self._source_node_id = node_id
33
+ return True
34
+
35
+ def climb_target_node_id(self, node_id: T) -> bool:
36
+ if node_id == self._highest_common_node_id:
37
+ return False
38
+
39
+ self._climbed_target_node_ids.append(self._target_node_id)
40
+ self._target_node_id = node_id
41
+ return True
42
+
43
+ def pop_climbed_source_node_id(self) -> T | None:
44
+ if not self._climbed_source_node_ids:
45
+ return None
46
+
47
+ self._source_node_id = self._climbed_source_node_ids.pop()
48
+ return self._source_node_id
49
+
50
+ def pop_climbed_target_node_id(self) -> T | None:
51
+ if not self._climbed_target_node_ids:
52
+ return None
53
+
54
+ self._target_node_id = self._climbed_target_node_ids.pop()
55
+ return self._target_node_id
56
+
57
+ def copy(self) -> "Dependency[T]":
58
+ dependency = Dependency(
59
+ self._source_node_id,
60
+ self._target_node_id,
61
+ self._highest_common_node_id,
62
+ )
63
+
64
+ dependency._climbed_source_node_ids = self._climbed_source_node_ids.copy()
65
+ dependency._climbed_target_node_ids = self._climbed_target_node_ids.copy()
66
+
67
+ return dependency
68
+
69
+ def serialize(self) -> Dict[str, Any]:
70
+ output = super().serialize()
71
+ output["highest_common_node_id"] = (
72
+ str(self._highest_common_node_id) if self._highest_common_node_id is not None else None
73
+ )
74
+ output["climbed_source_node_ids"] = [str(node_id) for node_id in self._climbed_source_node_ids]
75
+ output["climbed_target_node_ids"] = [str(node_id) for node_id in self._climbed_target_node_ids]
76
+ return output
77
+
78
+ def deserialize(self, data: Dict[str, Any], converter: Callable[[str], T]) -> None:
79
+ super().deserialize(data, converter)
80
+ self._highest_common_node_id = (
81
+ converter(data["highest_common_node_id"]) if data["highest_common_node_id"] is not None else None
82
+ )
83
+ self._climbed_source_node_ids = deque(converter(node_id) for node_id in data["climbed_source_node_ids"])
84
+ self._climbed_target_node_ids = deque(converter(node_id) for node_id in data["climbed_target_node_ids"])
@@ -0,0 +1,30 @@
1
+ # This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
2
+ #
3
+ # Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
4
+ #
5
+ # This software may be modified and distributed under the terms of
6
+ # the 3-Clause BSD License. See the LICENSE file in the package base
7
+ # directory for details.
8
+
9
+ from typing import Generic, Callable, Dict, Any
10
+
11
+ from PySide6.QtWidgets import QGraphicsLineItem
12
+
13
+ from discopop_gui.Types.T import T
14
+ from discopop_gui.Objects.CanvasItems.TreeEdges.Base import Base
15
+
16
+
17
+ class Main(Base[T], Generic[T]):
18
+ def __init__(self, canvas_edge: QGraphicsLineItem, source_node_id: T, target_node_id: T):
19
+ super().__init__(source_node_id, target_node_id)
20
+ self._canvas_edge = canvas_edge
21
+
22
+ def get_canvas_edge(self) -> QGraphicsLineItem:
23
+ return self._canvas_edge
24
+
25
+ def serialize(self) -> Dict[str, Any]:
26
+ output = super().serialize()
27
+ return output
28
+
29
+ def deserialize(self, data: Dict[str, Any], converter: Callable[[str], T]) -> None:
30
+ super().deserialize(data, converter)
File without changes