-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexamples_loader.py
More file actions
31 lines (23 loc) · 902 Bytes
/
Copy pathexamples_loader.py
File metadata and controls
31 lines (23 loc) · 902 Bytes
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
import os
import json
from PySide6.QtGui import QAction
class ExamplesLoader:
def __init__(self, file_name: str, parent_menu, load_function):
try:
with open(file_name, "rt", encoding="utf-8") as file:
loaded_data = json.load(file)
except IOError:
return
keys = sorted(list(loaded_data.keys()))
for key in keys:
group = loaded_data[key]
menu = parent_menu.addMenu(group["name"])
for file in group["files"]:
action = QAction(file, menu)
example_file_path = os.path.join(
os.path.dirname(__file__), "examples", group["directory"], file
)
action.triggered.connect(
lambda checked=False, f=example_file_path: load_function(f)
)
menu.addAction(action)