-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
51 lines (41 loc) · 1.57 KB
/
utils.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
# -----------------------------------------------------------
# Author: Daniel Jiang (danieldj@umich.edu)
# This file is part of the Seat Adjustment System (SAS) project.
# -----------------------------------------------------------
# %% standard lib imports
import os, json
# %% project-specific imports
## Qt
from PyQt5.QtWidgets import (
QFileDialog,
QWidget,
)
def getDirPath():
"""
getDirPath opens a file dialog and only allows the user to select folders
"""
w = QWidget()
return QFileDialog.getExistingDirectory(w, "Open Directory",
os.getcwd(),
QFileDialog.ShowDirsOnly
| QFileDialog.DontResolveSymlinks)
def getfilePath():
"""
getScanFilePath opens a file dialog and only allows the user to select ply files
"""
w = QWidget()
return QFileDialog.getOpenFileName(w, 'Open File', os.getcwd(), "json file (*.json)")[0]
def readConfigFile(configFilepath):
# Read the configuration file
# If it doesn't exist or invalid, return empty dict
try:
if (not configFilepath or not os.path.isfile(configFilepath)):
raise Exception('Invalid config file')
with open(configFilepath) as f:
config = json.load(f)
if 'predictors' not in config:
raise Exception('Invalid config file')
except:
print(f'Error reading configuration file: {configFilepath}')
return {}
return config