@@ -443,23 +443,24 @@ def create_instance_row(ins:dict) -> InstanceRow or None:
443443def update_instance_list (instance_listbox :Gtk .ListBox , selected_instance_id :str ):
444444 instance_listbox .remove_all ()
445445 instances = SQL .get_instances ()
446+ instance_added = False
446447 if len (instances ) > 0 :
447448 instance_listbox .get_root ().instance_manager_stack .set_visible_child_name ('content' )
448- row_to_select = None
449449 for i , ins in enumerate (instances ):
450450 row = create_instance_row (ins )
451451 if row :
452452 row .instance .set_row (row )
453- instance_listbox .append (row )
453+ GLib .idle_add (instance_listbox .append , row )
454+ instance_added = True
454455 if row .instance .instance_id == selected_instance_id :
455- row_to_select = row
456- if row_to_select :
457- instance_listbox .select_row (row_to_select )
456+ GLib .idle_add (instance_listbox .select_row , row )
458457
459- if len ( list ( instance_listbox )) == 0 :
460- instance_listbox .get_root ().instance_manager_stack .set_visible_child_name ( 'no-instances' )
461- instance_listbox .append ( InstanceRow (Empty ()))
458+ if not instance_added :
459+ GLib . idle_add ( instance_listbox .get_root ().instance_manager_stack .set_visible_child_name , 'no-instances' )
460+ GLib . idle_add ( instance_listbox .append , InstanceRow (Empty ()))
462461
463- if not instance_listbox .get_selected_row ():
464- instance_listbox .select_row (instance_listbox .get_row_at_index (0 ))
462+ def check_row_is_selected ():
463+ if not instance_listbox .get_selected_row ():
464+ instance_listbox .select_row (instance_listbox .get_row_at_index (0 ))
465+ GLib .idle_add (check_row_is_selected )
465466
0 commit comments