Skip to content

Commit 2cf1c9d

Browse files
MarkKoz64json
authored andcommitted
Implement layouts
1 parent eabe4f8 commit 2cf1c9d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

algorithm_visualizer/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
from algorithm_visualizer import randomize as Randomize
77
from algorithm_visualizer.commander import Commander
8+
from algorithm_visualizer.layouts import *
89
from algorithm_visualizer.tracers import *
910

1011
__all__ = (
1112
"Randomize", "Commander",
12-
"Array1DTracer", "Array2DTracer", "ChartTracer", "GraphTracer", "LogTracer", "Tracer"
13+
"Array1DTracer", "Array2DTracer", "ChartTracer", "GraphTracer", "LogTracer", "Tracer",
14+
"HorizontalLayout", "Layout", "VerticalLayout"
1315
)
1416

1517
# Types which are serializable by the default JSONEncoder

algorithm_visualizer/layouts.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import List
2+
3+
from algorithm_visualizer import Commander
4+
5+
class Layout(Commander):
6+
def __init__(self, children: List[Commander]):
7+
super().__init__([c.key for c in children])
8+
9+
@classmethod
10+
def setRoot(cls, child: Commander):
11+
cls._command(None, "setRoot", child.key)
12+
13+
def add(self, child: Commander, index: int = None):
14+
if index is None:
15+
self.command("add", child.key)
16+
else:
17+
self.command("add", child.key, index)
18+
19+
def remove(self, child: Commander):
20+
self.command("remove", child.key)
21+
22+
def removeAll(self):
23+
self.command("removeAll")
24+
25+
26+
class HorizontalLayout(Layout):
27+
pass
28+
29+
30+
class VerticalLayout(Layout):
31+
pass

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy