Skip to content

Commit 99701ec

Browse files
committed
improvement to the logic
1 parent 6042da8 commit 99701ec

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

sidebar.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,31 @@ 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
118+
94119
def initialize_chip_data(self, current_dict_circuit, chip_images_path) -> None:
95120
"""
96121
Initializes the chip data for the sidebar.
@@ -503,8 +528,14 @@ def on_search(self, _):
503528

504529
def refresh(self):
505530
"""
506-
Refreshes the sidebar by reloading the chip data and redisplaying the chips.
531+
Refreshes the sidebar with updated chip data.
507532
"""
508-
self.initialize_chip_data(self.current_dict_circuit, self.chip_images_path)
509-
self.on_search(None)
510-
print("Sidebar refreshed.")
533+
current_mtimes = self.get_chips_files_mtimes()
534+
if current_mtimes != self.chip_files_mtimes:
535+
self.chip_files_mtimes = current_mtimes
536+
self.initialize_chip_data(self.current_dict_circuit, self.chips_images_path)
537+
self.on_search(None)
538+
print("Sidebar refreshed with updated chips.")
539+
else:
540+
print("No changes detected. Sidebar not refreshed.")
541+

0 commit comments

Comments
 (0)