Skip to content

Commit

Permalink
IMPROVEMENT: NFC changes in preparation for the template overview win…
Browse files Browse the repository at this point in the history
…dow feature
  • Loading branch information
amilcarlucas committed Jun 9, 2024
1 parent 35e14c0 commit 3f4f052
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
16 changes: 10 additions & 6 deletions MethodicConfigurator/backend_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,7 @@ def store_recently_used_vehicle_dir(vehicle_dir: str):


@staticmethod
def get_recently_used_dirs():
settings_directory = LocalFilesystem.__user_config_dir()
settings = LocalFilesystem.__get_settings_as_dict()

def get_templates_base_dir():
current_dir = os_path.dirname(os_path.abspath(__file__))
if platform_system() == 'Windows':
current_dir = current_dir.replace("\\_internal", "")
Expand All @@ -565,12 +562,19 @@ def get_recently_used_dirs():
site_directory = LocalFilesystem.__site_config_dir()
else:
site_directory = program_dir
template_default_dir = os_path.join(site_directory, "vehicle_templates", "ArduCopter",
"diatone_taycan_mxc", "4.5.3-params")
return os_path.join(site_directory, "vehicle_templates")

@staticmethod
def get_recently_used_dirs():
template_default_dir = os_path.join(LocalFilesystem.get_templates_base_dir(),
"ArduCopter", "diatone_taycan_mxc", "4.5.3-params")

settings_directory = LocalFilesystem.__user_config_dir()
vehicles_default_dir = os_path.join(settings_directory, "vehicles")
if not os_path.exists(vehicles_default_dir):
os_makedirs(vehicles_default_dir, exist_ok=True)

settings = LocalFilesystem.__get_settings_as_dict()
template_dir = settings["directory_selection"].get("template_dir", template_default_dir)
new_base_dir = settings["directory_selection"].get("new_base_dir", vehicles_default_dir)
vehicle_dir = settings["directory_selection"].get("vehicle_dir", vehicles_default_dir)
Expand Down
8 changes: 4 additions & 4 deletions MethodicConfigurator/backend_filesystem_vehicle_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ class VehicleComponents:
vehicle components configurations from a JSON file.
"""
def __init__(self):
self.__vehicle_components_json_filename = "vehicle_components.json"
self.vehicle_components_json_filename = "vehicle_components.json"
self.vehicle_components = None

def load_vehicle_components_json_data(self, vehicle_dir: str):
data = {}
try:
filepath = os_path.join(vehicle_dir, self.__vehicle_components_json_filename)
filepath = os_path.join(vehicle_dir, self.vehicle_components_json_filename)
with open(filepath, 'r', encoding='utf-8') as file:
data = json_load(file)
except FileNotFoundError:
logging_warning("File '%s' not found in %s.", self.__vehicle_components_json_filename, vehicle_dir)
logging_warning("File '%s' not found in %s.", self.vehicle_components_json_filename, vehicle_dir)
except JSONDecodeError:
logging_error("Error decoding JSON data from file '%s'.", filepath)
self.vehicle_components = data
return data

def save_vehicle_components_json_data(self, data, vehicle_dir: str) -> bool:
filepath = os_path.join(vehicle_dir, self.__vehicle_components_json_filename)
filepath = os_path.join(vehicle_dir, self.vehicle_components_json_filename)
try:
with open(filepath, 'w', encoding='utf-8') as file:
json_dump(data, file, indent=4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from version import VERSION


class FlightControllerInfoWindow(BaseWindow):
class FlightControllerInfoWindow(BaseWindow): # pylint: disable=too-few-public-methods
"""
Display flight controller hardware, firmware and parameter information
"""
Expand Down

0 comments on commit 3f4f052

Please sign in to comment.