Content-Length: 350657 | pFad | http://github.com/algorithm-visualizer/tracers.py/commit/17a3a930853a5a0cd553862bdb21a69ec57f2e44

27 Add key as an instance attribute of Commander · algorithm-visualizer/tracers.py@17a3a93 · GitHub
Skip to content

Commit 17a3a93

Browse files
MarkKoz64json
authored andcommitted
Add key as an instance attribute of Commander
* Create a separate command() method that is an instance method * Change destroy() to an instance method * Change set() and reset() to instance methods * Make Tracer pass nothing instead of None for the title when title is not given * Make delay() pass nothing instead of None for the lineNumber when lineNumber isn't given
1 parent a956418 commit 17a3a93

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

algorithm_visualizer/commander.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import string
2-
from typing import Any, Dict, List
2+
from typing import Any, Dict, List, Optional
33

44
from algorithm_visualizer import randomize
55

@@ -14,10 +14,11 @@ class Commander:
1414

1515
def __init__(self, *args):
1616
self._objectCount += 1
17+
self.key = self._keyRandomizer.create()
1718
self.command(self.__class__.__name__, *args)
1819

1920
@classmethod
20-
def command(cls, method: str, *args, key: str = _keyRandomizer.create()):
21+
def _command(cls, key: Optional[str], method: str, *args):
2122
cmd = {
2223
"key": key,
2324
"method": method,
@@ -30,7 +31,9 @@ def command(cls, method: str, *args, key: str = _keyRandomizer.create()):
3031
elif cls._objectCount > _MAX_OBJECTS:
3132
raise RuntimeError("Too Many Objects")
3233

33-
@classmethod
34-
def destroy(cls):
35-
cls._objectCount -= 1
36-
cls.command("destroy")
34+
def command(self, method: str, *args):
35+
self._command(self.key, method, *args)
36+
37+
def destroy(self):
38+
self._objectCount -= 1
39+
self.command("destroy")

algorithm_visualizer/tracer.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ def __init__(self, title: str = None):
1010

1111
@classmethod
1212
def delay(cls, lineNumber: int = None):
13-
cls.command("delay", lineNumber)
13+
if lineNumber is None:
14+
cls._command(None, "delay")
15+
else:
16+
cls._command(None, "delay", lineNumber)
1417

15-
@classmethod
16-
def set(cls):
17-
cls.command("set")
18+
def set(self):
19+
self.command("set")
1820

19-
@classmethod
20-
def reset(cls):
21-
cls.command("reset")
21+
def reset(self):
22+
self.command("reset")

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/algorithm-visualizer/tracers.py/commit/17a3a930853a5a0cd553862bdb21a69ec57f2e44

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy