|
16 | 16 | from toolbar import Toolbar |
17 | 17 | from component_sketch import ComponentSketcher |
18 | 18 | 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 |
20 | 20 |
|
21 | 21 |
|
22 | 22 | @dataclass |
@@ -91,30 +91,7 @@ def __init__( |
91 | 91 | self.create_chips_area(sidebar_frame) |
92 | 92 | self.create_manage_button(sidebar_frame) |
93 | 93 |
|
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() |
118 | 95 |
|
119 | 96 | def initialize_chip_data(self, current_dict_circuit, chip_images_path) -> None: |
120 | 97 | """ |
@@ -530,12 +507,11 @@ def refresh(self): |
530 | 507 | """ |
531 | 508 | Refreshes the sidebar with updated chip data. |
532 | 509 | """ |
533 | | - current_mtimes = self.get_chips_files_mtimes() |
| 510 | + current_mtimes = get_chip_modification_times() |
534 | 511 | if current_mtimes != self.chip_files_mtimes: |
535 | 512 | 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) |
537 | 514 | self.on_search(None) |
538 | 515 | print("Sidebar refreshed with updated chips.") |
539 | 516 | else: |
540 | 517 | print("No changes detected. Sidebar not refreshed.") |
541 | | - |
0 commit comments