-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
59 lines (46 loc) · 2.09 KB
/
run.py
File metadata and controls
59 lines (46 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
#Look at the comments to see what this code is doing
#argparse & sys are two Python libraries being imported
import argparse, sys
#wall and effects are two of our other Python scripts
#the entire effects file is being imported
#Only the Wall class from the wall file is being imported
from wall import Wall
import effects
if __name__ == "__main__":
#If we don't know what a command or function does we can look it up in the docs.
#Looking up argparse.ArgumentParser() takes us to:
#https://docs.python.org/2/library/argparse.html
parser = argparse.ArgumentParser()
#When we run the script from the command line,
#we can give it some additional arguments as defined here.
parser.add_argument("-w", "--width", type=int,
action="store", dest="width",
default=8, help="wall width")
parser.add_argument("-t", "--height", type=int,
action="store", dest="height",
default=8, help="wall height")
parser.add_argument("-e", "--effects",
nargs='+', dest="effects",
help="specific effects you wish to run")
args = parser.parse_args()
#We set a variable called wall
#which takes the class Wall (imported above)
#and calls it with either default width & height or
#whatever width and height we defined in the args as above
wall = Wall(args.width, args.height)
#If an effects arg was defined, use it for effects_to_run
#Otherwise run all effects from the effects script imported above
#Save this in a variable called effects_to_run as a list
if args.effects:
effects_to_run = [getattr(effects, a) for a in args.effects \
if hasattr(effects, a)]
else:
effects_to_run = effects.Effects
#Loop through effects to run
#Print that effect's name in the Python terminal
#Run that effect in the Tkinter window
for effect in effects_to_run:
new_effect = effect(wall)
print(new_effect.__class__.__name__)
new_effect.run()