@@ -80,6 +80,10 @@ def __init__(self, **kwargs):
8080 super ().__init__ (** kwargs )
8181 self .can_focus = True # Make the overlay focusable
8282
83+ def call_after_refresh (self , callback , * args , ** kwargs ):
84+ """Helper method to call a function after the next refresh using set_timer."""
85+ self .set_timer (0.01 , lambda : callback (* args , ** kwargs ))
86+
8387 def compose (self ) -> ComposeResult :
8488 """Compose the welcome overlay."""
8589 with Vertical (id = "welcome-overlay" , classes = "welcome-overlay" ):
@@ -324,9 +328,10 @@ def _handle_database_connection(self, connection_result: dict | None) -> None:
324328 connection_string = connection_result ["connection_string" ]
325329 self .log (f"Calling connect_to_database with: { connection_string } " )
326330 data_grid .connect_to_database (connection_string )
327- # Hide the welcome overlay after successful connection
328- self .log ("Hiding welcome overlay" )
329- self .add_class ("hidden" )
331+ # Hide the welcome overlay after successful connection with a small delay
332+ # to allow the focus logic to complete
333+ self .log ("Scheduling welcome overlay hide after database connection" )
334+ self .set_timer (0.5 , lambda : self ._hide_welcome_overlay ())
330335 else :
331336 self .log ("No connection string provided in result" )
332337 else :
@@ -341,6 +346,14 @@ def _handle_database_connection(self, connection_result: dict | None) -> None:
341346 else :
342347 self .log ("Database connection cancelled or no result" )
343348
349+ def _hide_welcome_overlay (self ) -> None :
350+ """Hide the welcome overlay after database connection."""
351+ try :
352+ self .log ("Hiding welcome overlay after database connection" )
353+ self .add_class ("hidden" )
354+ except Exception as e :
355+ self .log (f"Error hiding welcome overlay: { e } " )
356+
344357
345358class DataDirectoryTree (DirectoryTree ):
346359 """A DirectoryTree that filters to show only data files and directories."""
@@ -1070,6 +1083,10 @@ def __init__(self, **kwargs):
10701083 self .original_data = None # Store original data for change tracking
10711084 self .has_changes = False # Track if data has been modified
10721085 self ._current_address = "A1"
1086+
1087+ def call_after_refresh (self , callback , * args , ** kwargs ):
1088+ """Helper method to call a function after the next refresh using set_timer."""
1089+ self .set_timer (0.01 , lambda : callback (* args , ** kwargs ))
10731090 self .editing_cell = False
10741091 self ._edit_input = None
10751092 self .original_data = None # Store original data for change tracking
@@ -6879,6 +6896,10 @@ def __init__(self, data_grid: ExcelDataGrid, **kwargs):
68796896 self .search_type = None
68806897 self .search_values = None
68816898
6899+ def call_after_refresh (self , callback , * args , ** kwargs ):
6900+ """Helper method to call a function after the next refresh using set_timer."""
6901+ self .set_timer (0.01 , lambda : callback (* args , ** kwargs ))
6902+
68826903 def compose (self ) -> ComposeResult :
68836904 """Compose the search overlay."""
68846905 # Search info bar - make it clickable to exit search
@@ -7118,6 +7139,10 @@ def __init__(self, **kwargs):
71187139 self .is_database_mode = False
71197140 self .available_tables = []
71207141
7142+ def call_after_refresh (self , callback , * args , ** kwargs ):
7143+ """Helper method to call a function after the next refresh using set_timer."""
7144+ self .set_timer (0.01 , lambda : callback (* args , ** kwargs ))
7145+
71217146 def compose (self ) -> ComposeResult :
71227147 """Compose the tools panel."""
71237148 # Navigation radio buttons for sections - will be updated based on mode
@@ -7490,13 +7515,13 @@ def set_database_mode(
74907515 if enabled and tables :
74917516 if is_remote :
74927517 # For remote databases, focus on Table Selection tab
7493- self .call_after_refresh (
7494- lambda : self ._update_table_selector_and_focus_for_remote (tables )
7518+ self .set_timer (
7519+ 0.1 , lambda : self ._update_table_selector_and_focus_for_remote (tables )
74957520 )
74967521 else :
74977522 # For local databases, use normal flow (Sweet AI Assistant focus)
7498- self .call_after_refresh (
7499- lambda : self ._update_table_selector_after_refresh (tables )
7523+ self .set_timer (
7524+ 0.1 , lambda : self ._update_table_selector_after_refresh (tables )
75007525 )
75017526
75027527 except Exception as e :
0 commit comments