@@ -62,19 +62,8 @@ def __init__(
6262 - canvas: The canvas where the chips are placed.
6363 - sketcher: The component sketcher object.
6464 """
65- self .current_dict_circuit = current_dict_circuit
66- images = self .load_chip_images (chip_images_path )
67- self .available_chips_and_imgs : list [Tuple [Chip , tk .PhotoImage | None ]] = [
68- (chip , images .get (chip .package_name )) for chip in get_all_available_chips ().values ()
69- ]
70- # Sort the chips based on the number after 'HC' in their chip_type
71- self .available_chips_and_imgs .sort (key = lambda chip_img : int (chip_img [0 ].chip_type .split ("HC" )[- 1 ]))
72-
73- # Create a reverse lookup dictionary for chip names to their index in the list
74- self .chip_name_to_index = {
75- chip .chip_type : index for index , (chip , _ ) in enumerate (self .available_chips_and_imgs )
76- }
77-
65+ self .initialize_chip_data (current_dict_circuit , chip_images_path )
66+ self .chip_images_path = chip_images_path
7867 self .canvas : tk .Canvas = canvas
7968 self .sketcher : ComponentSketcher = sketcher
8069 self .toolbar = toolbar
@@ -102,6 +91,23 @@ def __init__(
10291 self .create_chips_area (sidebar_frame )
10392 self .create_manage_button (sidebar_frame )
10493
94+ def initialize_chip_data (self , current_dict_circuit , chip_images_path ) -> None :
95+ """
96+ Initializes the chip data for the sidebar.
97+ """
98+ self .current_dict_circuit = current_dict_circuit
99+ images = self .load_chip_images (chip_images_path )
100+ self .available_chips_and_imgs : list [Tuple [Chip , tk .PhotoImage | None ]] = [
101+ (chip , images .get (chip .package_name )) for chip in get_all_available_chips ().values ()
102+ ]
103+ # Sort the chips based on the number after 'HC' in their chip_type
104+ self .available_chips_and_imgs .sort (key = lambda chip_img : int (chip_img [0 ].chip_type .split ("HC" )[- 1 ]))
105+
106+ # Create a reverse lookup dictionary for chip names to their index in the list
107+ self .chip_name_to_index = {
108+ chip .chip_type : index for index , (chip , _ ) in enumerate (self .available_chips_and_imgs )
109+ }
110+
105111 def load_chip_images (self , img_path ) -> dict [str , tk .PhotoImage ]:
106112 """
107113 Loads chip images from the specified directory and scales them down.
@@ -494,3 +500,11 @@ def on_search(self, _):
494500 or any (query in func .__class__ .__name__ .lower () for func in chip_data [0 ].functions )
495501 ]
496502 self .display_chips (filtered_chips )
503+
504+ def refresh (self ):
505+ """
506+ Refreshes the sidebar by reloading the chip data and redisplaying the chips.
507+ """
508+ self .initialize_chip_data (self .current_dict_circuit , self .chip_images_path )
509+ self .on_search (None )
510+ print ("Sidebar refreshed." )
0 commit comments