/
main.py
99 lines (77 loc) · 2.42 KB
/
main.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# -*- coding: UTF-8 -*-
__author__ = "Jaime Rivera <jaime.rvq@gmail.com>"
__copyright__ = "Copyright 2022, Jaime Rivera"
__credits__ = []
__license__ = "MIT License"
import argparse
import os
import sys
from PySide2.QtWidgets import QApplication
from all_nodes.analytics import analytics
from all_nodes.graphic.widgets.main_window import AllNodesWindow
from all_nodes.logic.logic_scene import LogicScene
from all_nodes import utils
LOGGER = utils.get_logger(__name__)
# LAUNCH MODES ---------------------------------------------------
def launch_gui():
"""
Just launch the tool, with GUI to create/edit scenes.
"""
# App
app = QApplication(sys.argv)
# Launch
AllNodesWindow()
app.exec_()
def launch_batch(scene_file: str, set_parameters: list):
"""
Run a scene in batch mode, no GUI.
Args:
scene_file (str): Filepath or alias of the scene to run
scene_file (list): List eith parameters and values to be set
"""
scene = LogicScene()
scene.load_from_file(scene_file)
if set_parameters:
for i in range(0, len(set_parameters) - 1, 2):
node_name = set_parameters[i].rsplit(".", 1)[0]
attr_name = set_parameters[i].rsplit(".", 1)[1]
attr_str_value = set_parameters[i + 1]
node = scene.to_node(node_name)
if node:
node.set_attribute_from_str(attr_name, attr_str_value)
scene.run_all_nodes(spawn_thread=False)
# MAIN ---------------------------------------------------
def main():
# Arguments
parser = argparse.ArgumentParser()
parser.add_argument(
"-f", "--scene_file", type=str, help="file .yml to run in non-GUI mode"
)
parser.add_argument(
"-s",
"--set_parameters",
help="Arguments to set in batch execution of scene",
type=str,
nargs="+",
)
parser.add_argument(
"-a",
"--analytics",
help="Perform analytics and generate graphs",
action="store_true",
)
args = parser.parse_args()
if not os.getenv("IN_DEV"):
LOGGER.info("For launching in DEBUG mode, set env variable 'IN_DEV'")
# Analytics
if args.analytics:
analytics.process_analytics()
sys.exit(0)
# GUI mode
if not args.scene_file:
launch_gui()
# Non-GUI batch mode
else:
launch_batch(args.scene_file, args.set_parameters)
if __name__ == "__main__":
main()