-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path__main__.py
More file actions
executable file
·81 lines (61 loc) · 2.3 KB
/
__main__.py
File metadata and controls
executable file
·81 lines (61 loc) · 2.3 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
# Copyright (C) 2022 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# Released under the terms of the BSD 3-Clause License
import argparse
import pathlib
import sys
from typing import Optional, Sequence
# GUI
from qtpy.QtWidgets import QApplication
from robot_log_visualizer.ui.gui import RobotViewerMainWindow
# Meshcat
from robot_log_visualizer.robot_visualizer.meshcat_provider import MeshcatProvider
def _parse_arguments(argv: Sequence[str]) -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Robot Log Visualizer",
)
parser.add_argument(
"dataset",
nargs="?",
help="Path to a MAT dataset to load on startup.",
)
parser.add_argument(
"-s",
"--snapshot",
help="Path to a view snapshot (.json) to restore on startup.",
)
return parser.parse_args(argv)
def main(argv: Optional[Sequence[str]] = None):
parsed_argv = list(argv) if argv is not None else sys.argv[1:]
args = _parse_arguments(parsed_argv)
thread_periods = {
"meshcat_provider": 0.03,
"signal_provider": 0.03,
"plot_animation": 0.03,
}
meshcat_provider = MeshcatProvider(period=thread_periods["meshcat_provider"])
# instantiate a QApplication
app = QApplication(sys.argv)
# instantiate the main window
gui = RobotViewerMainWindow(
signal_provider_period=thread_periods["signal_provider"],
meshcat_provider=meshcat_provider,
animation_period=thread_periods["plot_animation"],
)
# show the main window
gui.show()
if args.dataset:
dataset_path = pathlib.Path(args.dataset).expanduser()
if not gui._load_mat_file(str(dataset_path), quiet=False): # noqa: SLF001
print(f"Failed to load dataset '{dataset_path}'.", file=sys.stderr)
if args.snapshot:
snapshot_path = pathlib.Path(args.snapshot).expanduser()
if not gui.load_view_snapshot_from_path(snapshot_path):
print(f"Failed to load snapshot '{snapshot_path}'.", file=sys.stderr)
exec_method = getattr(app, "exec", None)
if exec_method is None:
exec_method = app.exec_
return exec_method()
if __name__ == "__main__":
sys.exit(main())