@@ -173,7 +173,7 @@ def __init__(self, library: Library, driver: "QtDriver"):
173173 info_layout .addWidget (self .dimensions_label )
174174 info_layout .addWidget (scroll_area )
175175
176- # keep list of rendered libraries to avoid needles re-rendering
176+ # keep list of rendered libraries to avoid needless re-rendering
177177 self .render_libs = set ()
178178 self .libs_layout = QVBoxLayout ()
179179 self .fill_libs_widget (self .libs_layout )
@@ -247,44 +247,80 @@ def fill_libs_widget(self, layout: QVBoxLayout):
247247 libs_sorted = sorted (lib_items .items (), key = lambda item : item [0 ], reverse = True )
248248
249249 self .render_libs = new_keys
250- return self ._fill_libs_widget (libs_sorted , layout )
250+ self ._fill_libs_widget (libs_sorted , layout )
251251
252252 def _fill_libs_widget (
253253 self , libraries : list [tuple [str , tuple [str , str ]]], layout : QVBoxLayout
254254 ):
255+ def clear_layout (layout_item : QVBoxLayout ):
256+ for i in reversed (range (layout_item .count ())):
257+ child = layout_item .itemAt (i )
258+ if child .widget () is not None :
259+ child .widget ().deleteLater ()
260+ elif child .layout () is not None :
261+ clear_layout (child .layout ())
262+
255263 # remove any potential previous items
256264 for idx in reversed (range (layout .count ())):
257- widget = layout .itemAt (idx ).widget ()
258- layout .removeWidget (widget )
259- # remove from GUI
260- widget .setParent (None )
265+ row_layout = layout .itemAt (idx )
266+ clear_layout (row_layout )
261267
262268 label = QLabel ("Recent Libraries" )
263269 label .setAlignment (Qt .AlignCenter )
264- layout .addWidget (label )
265270
266- for tstamp , ( full_val , cut_val ) in libraries :
267- button = QPushButton ( text = cut_val )
268- button . setObjectName ( f"path { tstamp } " )
271+ row_layout = QHBoxLayout ()
272+ row_layout . addWidget ( label )
273+ layout . addLayout ( row_layout )
269274
270- def open_library_button_clicked (path ):
271- return lambda : self .driver .open_library (path )
275+ def get_button_style (extras : list [str ] | None = None ):
276+ base_style = [
277+ f"background-color:{ Theme .COLOR_BG .value } ;" ,
278+ "border-radius:6px;" ,
279+ "text-align: left;" ,
280+ "padding-top: 3px;" ,
281+ "padding-left: 6px;" ,
282+ "padding-bottom: 4px;" ,
283+ ]
272284
273- button .clicked .connect (open_library_button_clicked (full_val ))
274- button .setStyleSheet (
285+ full_style = base_style + (extras or [])
286+
287+ return (
275288 "QPushButton{"
276- f"background-color:{ Theme .COLOR_BG .value } ;"
277- "border-radius:6px;"
278- "text-align: left;"
279- "padding-top: 3px;"
280- "padding-left: 6px;"
281- "padding-bottom: 4px;"
289+ f"{ '' .join (full_style )} "
282290 "}"
283291 f"QPushButton::hover{{background-color:{ Theme .COLOR_HOVER .value } ;}}"
284292 f"QPushButton::pressed{{background-color:{ Theme .COLOR_PRESSED .value } ;}}"
285293 )
294+
295+ for item_key , (full_val , cut_val ) in libraries :
296+ button = QPushButton (text = cut_val )
297+ button .setObjectName (f"path{ item_key } " )
298+
299+ def open_library_button_clicked (path ):
300+ return lambda : self .driver .open_library (path )
301+
302+ button .clicked .connect (open_library_button_clicked (full_val ))
303+ button .setStyleSheet (get_button_style ())
286304 button .setCursor (Qt .CursorShape .PointingHandCursor )
287- layout .addWidget (button )
305+
306+ button_remove = QPushButton ("➖" )
307+ button_remove .setStyleSheet (get_button_style ())
308+ button_remove .setCursor (Qt .CursorShape .PointingHandCursor )
309+ button_remove .setFixedWidth (30 )
310+
311+ def remove_recent_library_clicked (key : str ):
312+ return lambda : (
313+ self .driver .remove_recent_library (key ),
314+ self .fill_libs_widget (self .libs_layout ),
315+ )
316+
317+ button_remove .clicked .connect (remove_recent_library_clicked (item_key ))
318+
319+ row_layout = QHBoxLayout ()
320+ row_layout .addWidget (button )
321+ row_layout .addWidget (button_remove )
322+
323+ layout .addLayout (row_layout )
288324
289325 def resizeEvent (self , event : QResizeEvent ) -> None :
290326 self .update_image_size (
0 commit comments