@@ -61,17 +61,48 @@ def __init__(self, parent, db_name: str):
6161 self .search .setMaximumHeight (30 )
6262 self .search .setPlaceholderText ("Quick Search" )
6363
64+ # Create loading indicator with spinner
65+ self .loading_spinner = QtWidgets .QProgressBar ()
66+ self .loading_spinner .setRange (0 , 0 ) # Indeterminate/busy indicator
67+ self .loading_spinner .setTextVisible (False )
68+ self .loading_spinner .setMaximumWidth (200 )
69+ self .loading_spinner .setMaximumHeight (20 )
70+
71+ self .loading_label = widgets .ABLabel ("Loading database..." )
72+ self .loading_label .setAlignment (Qt .AlignmentFlag .AlignCenter )
73+ font = self .loading_label .font ()
74+ font .setPointSize (14 )
75+ self .loading_label .setFont (font )
76+ self .loading_label .setStyleSheet ("color: gray; padding: 10px;" )
77+
6478 self .build_layout ()
6579 self .connect_signals ()
80+ self .update_loading_state ()
6681
6782 def build_layout (self ):
68- table_layout = QtWidgets .QHBoxLayout ()
83+ # Create a stacked layout to switch between loading and table view
84+ self .stacked_layout = QtWidgets .QStackedLayout ()
85+
86+ # Page 0: Loading indicator with spinner
87+ loading_widget = QtWidgets .QWidget ()
88+ loading_layout = QtWidgets .QVBoxLayout (loading_widget )
89+ loading_layout .addStretch ()
90+ loading_layout .addWidget (self .loading_spinner , alignment = Qt .AlignmentFlag .AlignCenter )
91+ loading_layout .addWidget (self .loading_label )
92+ loading_layout .addStretch ()
93+ self .stacked_layout .addWidget (loading_widget )
94+
95+ # Page 1: Table view
96+ table_widget = QtWidgets .QWidget ()
97+ table_layout = QtWidgets .QVBoxLayout (table_widget )
6998 table_layout .setSpacing (0 )
99+ table_layout .setContentsMargins (0 , 0 , 0 , 0 )
70100 table_layout .addWidget (self .table_view )
101+ self .stacked_layout .addWidget (table_widget )
71102
72103 layout = QtWidgets .QVBoxLayout (self )
73104 layout .addWidget (self .search )
74- layout .addLayout (table_layout )
105+ layout .addLayout (self . stacked_layout )
75106
76107 # Set the table view as the central widget of the window
77108 self .setLayout (layout )
@@ -84,9 +115,24 @@ def connect_signals(self):
84115 self .search .textChangedDebounce .connect (self .table_view .setAllFilter )
85116
86117 def on_metadata_changed (self , added , updated , deleted ):
118+ # Check if primary data has finished loading
119+ self .update_loading_state ()
120+
87121 if any (db == self .database .name for db , code in added | updated | deleted ):
88122 self .sync ()
89123
124+ def update_loading_state (self ):
125+ """
126+ Updates the loading state based on whether primary metadata has loaded.
127+ Shows the loading indicator if primary data is still loading, otherwise shows the table.
128+ """
129+ if AB_metadata .loader .secondary_status == "done" :
130+ # Show table view
131+ self .stacked_layout .setCurrentIndex (1 )
132+ else :
133+ # Show loading indicator
134+ self .stacked_layout .setCurrentIndex (0 )
135+
90136 def sync (self ):
91137 """
92138 Synchronizes the widget with the current state of the database.
0 commit comments