Skip to content

Commit 9f08633

Browse files
committed
Moved get_modification_times to more logical file
1 parent 99701ec commit 9f08633

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

object_model/circuit_object_model.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,19 @@ def get_all_available_chips() -> dict[str, Chip]:
453453
return all_chips
454454

455455

456+
def get_chip_modification_times() -> dict[str, float]:
457+
"""
458+
Returns a dictionary of chip modification times.
459+
"""
460+
chip_mod_times = {}
461+
chips_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "Components", "Chips")
462+
for root, _, files in os.walk(chips_dir):
463+
for filename in files:
464+
if filename.endswith(".json"):
465+
chip_mod_times[filename] = os.path.getmtime(os.path.join(root, filename))
466+
return chip_mod_times
467+
468+
456469
if __name__ == "__main__":
457470
available_chips = get_all_available_chips()
458471
print("--------------------LOADED CHIPS:--------------------")

sidebar.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from toolbar import Toolbar
1717
from component_sketch import ComponentSketcher
1818
from dataCDLT import FREE, USED
19-
from object_model.circuit_object_model import Chip, get_all_available_chips
19+
from object_model.circuit_object_model import Chip, get_all_available_chips, get_chip_modification_times
2020

2121

2222
@dataclass
@@ -91,30 +91,7 @@ def __init__(
9191
self.create_chips_area(sidebar_frame)
9292
self.create_manage_button(sidebar_frame)
9393

94-
self.chips_images_path = chip_images_path
95-
self.chip_files_mtimes = self.get_chips_files_mtimes()
96-
97-
def get_chips_files_mtimes(self):
98-
"""
99-
Gets the modification times of the chip JSON files.
100-
"""
101-
chip_files_mtimes = {}
102-
# Construct the correct base path relative to the sidebar.py location
103-
chips_dir = os.path.join(os.path.dirname(__file__), "Components", "Chips")
104-
105-
# Subdirectories containing JSON files
106-
subdirs = ["Sequential", "Logical"]
107-
108-
for subdir in subdirs:
109-
folder_path = os.path.join(chips_dir, subdir)
110-
if not os.path.isdir(folder_path):
111-
print(f"Warning: Subdirectory '{folder_path}' does not exist.")
112-
continue
113-
for filename in os.listdir(folder_path):
114-
filepath = os.path.join(folder_path, filename)
115-
if os.path.isfile(filepath) and filename.lower().endswith(".json"):
116-
chip_files_mtimes[filepath] = os.path.getmtime(filepath)
117-
return chip_files_mtimes
94+
self.chip_files_mtimes = get_chip_modification_times()
11895

11996
def initialize_chip_data(self, current_dict_circuit, chip_images_path) -> None:
12097
"""
@@ -530,12 +507,11 @@ def refresh(self):
530507
"""
531508
Refreshes the sidebar with updated chip data.
532509
"""
533-
current_mtimes = self.get_chips_files_mtimes()
510+
current_mtimes = get_chip_modification_times()
534511
if current_mtimes != self.chip_files_mtimes:
535512
self.chip_files_mtimes = current_mtimes
536-
self.initialize_chip_data(self.current_dict_circuit, self.chips_images_path)
513+
self.initialize_chip_data(self.current_dict_circuit, self.chip_images_path)
537514
self.on_search(None)
538515
print("Sidebar refreshed with updated chips.")
539516
else:
540517
print("No changes detected. Sidebar not refreshed.")
541-

0 commit comments

Comments
 (0)