@@ -217,58 +217,37 @@ def __init__(self, panel: BaseDataPanel, objclass: SignalObj | ImageObj) -> None
217217 self .processing_history .setReadOnly (True )
218218 self .processing_history .setFont (font )
219219
220- self .analysis_parameter = QW .QTextEdit ()
221- self .analysis_parameter .setReadOnly (True )
222- self .analysis_parameter .setFont (font )
220+ self .analysis_parameters = QW .QTextEdit ()
221+ self .analysis_parameters .setReadOnly (True )
222+ self .analysis_parameters .setFont (font )
223223
224224 self .addTab (self .processing_history , _ ("History" ))
225- self .addTab (self .analysis_parameter , _ ("Analysis parameters" ))
225+ self .addTab (self .analysis_parameters , _ ("Analysis parameters" ))
226226 self .addTab (self .properties , _ ("Properties" ))
227227
228228 self .processing_history .textChanged .connect (self ._update_tab_visibility )
229- self .analysis_parameter .textChanged .connect (self ._update_tab_visibility )
229+ self .analysis_parameters .textChanged .connect (self ._update_tab_visibility )
230230
231231 def _update_tab_visibility (self ) -> None :
232- """Update visibility of a tab based on its content."""
233- # Save current tab to restore it after visibility changes
234- current_index = self .currentIndex ()
235- current_widget = self .widget (current_index )
236-
237- for textedit in (self .processing_history , self .analysis_parameter ):
232+ """Update visibility of tabs based on their content."""
233+ for textedit in (self .processing_history , self .analysis_parameters ):
238234 tab_index = self .indexOf (textedit )
239235 if tab_index >= 0 :
240236 has_content = bool (textedit .toPlainText ().strip ())
241237 self .setTabVisible (tab_index , has_content )
242238
243- # Restore the previously selected tab if it's still visible
244- # But only if we're not making History or Analysis parameters visible
245- # (they shouldn't steal focus)
246- if current_widget is not None :
247- # Don't restore if current widget was History or Analysis parameters
248- # that just became visible
249- if current_widget not in (
250- self .processing_history ,
251- self .analysis_parameter ,
252- ):
253- restored_index = self .indexOf (current_widget )
254- if restored_index >= 0 and self .isTabVisible (restored_index ):
255- self .setCurrentIndex (restored_index )
256- else :
257- # Current widget was History or Analysis parameters
258- # Select Properties instead
259- properties_index = self .indexOf (self .properties )
260- if properties_index >= 0 :
261- self .setCurrentIndex (properties_index )
262-
263239 def add_button (self , button : QW .QPushButton ) -> None :
264240 """Add additional button on bottom of properties panel"""
265241 self .add_prop_layout .addWidget (button )
266242
267- def display_analysis_parameter (self , obj : SignalObj | ImageObj ) -> None :
243+ def display_analysis_parameters (self , obj : SignalObj | ImageObj ) -> bool :
268244 """Set analysis parameter label.
269245
270246 Args:
271247 obj: Signal or Image object
248+
249+ Returns:
250+ True if analysis parameters were found and displayed, False otherwise.
272251 """
273252 text = ""
274253 # Iterate through all result adapters and extract parameter info
@@ -286,7 +265,8 @@ def display_analysis_parameter(self, obj: SignalObj | ImageObj) -> None:
286265 "(" + _ ("Parameters for function `%s`" ) % func_name + ")"
287266 )
288267 text += param .to_html ()
289- self .analysis_parameter .setText (text )
268+ self .analysis_parameters .setText (text )
269+ return bool (text )
290270
291271 def _build_processing_history (self , obj : SignalObj | ImageObj ) -> str :
292272 """Build processing history as a simple text list.
@@ -346,14 +326,18 @@ def _build_processing_history(self, obj: SignalObj | ImageObj) -> str:
346326
347327 return "\n " .join (history_lines )
348328
349- def display_processing_history (self , obj : SignalObj | ImageObj ) -> None :
329+ def display_processing_history (self , obj : SignalObj | ImageObj ) -> bool :
350330 """Display processing history.
351331
352332 Args:
353333 obj: Signal or Image object
334+
335+ Returns:
336+ True if processing history was found and displayed, False otherwise.
354337 """
355338 history_text = self ._build_processing_history (obj )
356339 self .processing_history .setText (history_text )
340+ return bool (history_text )
357341
358342 def update_properties_from (self , obj : SignalObj | ImageObj | None = None ) -> None :
359343 """Update properties from signal/image dataset
@@ -368,7 +352,7 @@ def update_properties_from(self, obj: SignalObj | ImageObj | None = None) -> Non
368352 dataset .set_defaults ()
369353 update_dataset (dataset , obj )
370354 self .properties .get ()
371- self .display_analysis_parameter (obj )
355+ has_analysis_parameters = self .display_analysis_parameters (obj )
372356 self .display_processing_history (obj )
373357 self .properties .apply_button .setEnabled (False )
374358
@@ -397,15 +381,30 @@ def update_properties_from(self, obj: SignalObj | ImageObj | None = None) -> Non
397381 self .processing_scroll = None
398382
399383 # Setup Creation and Processing tabs (if applicable)
384+ has_creation_tab = has_processing_tab = False
400385 if obj is not None :
401- self .setup_creation_tab (obj )
402- self .setup_processing_tab (obj )
386+ has_creation_tab = self .setup_creation_tab (obj )
387+ has_processing_tab = self .setup_processing_tab (obj )
403388
404389 # Trigger visibility update for History and Analysis parameters tabs
405390 # (will be called via textChanged signals, but we call explicitly
406391 # here to ensure initial state is correct)
407392 self ._update_tab_visibility ()
408393
394+ # Handle priority regarding the tab to set as current:
395+ # 1. Analysis parameters if content exists
396+ # 2. Creation tab if it exists
397+ # 3. Processing tab if it exists
398+ # 4. Properties tab
399+ if has_analysis_parameters :
400+ self .setCurrentWidget (self .analysis_parameters )
401+ elif has_creation_tab :
402+ self .setCurrentWidget (self .creation_scroll )
403+ elif has_processing_tab :
404+ self .setCurrentWidget (self .processing_scroll )
405+ else :
406+ self .setCurrentWidget (self .properties )
407+
409408 def get_changed_properties (self ) -> dict [str , Any ]:
410409 """Get dictionary of properties that have changed from original values.
411410
@@ -490,7 +489,6 @@ def setup_creation_tab(self, obj: SignalObj | ImageObj) -> bool:
490489 self .creation_scroll .setWidgetResizable (True )
491490 self .creation_scroll .setWidget (editor )
492491 self .insertTab (0 , self .creation_scroll , _ ("Creation" ))
493- self .setCurrentIndex (0 )
494492 return True
495493
496494 def apply_creation_parameters (self ) -> None :
@@ -639,7 +637,6 @@ def setup_processing_tab(
639637
640638 self .processing_scroll .setWidget (editor )
641639 self .insertTab (insert_index , self .processing_scroll , _ ("Processing" ))
642- self .setCurrentIndex (insert_index )
643640 return True
644641
645642 def apply_processing_parameters (
0 commit comments