@@ -1474,6 +1474,10 @@ def set_modified(self, state: bool = True) -> None:
14741474 title += f" [{ datalab .__version__ } ]"
14751475 self .setWindowTitle (title )
14761476
1477+ def is_modified (self ) -> bool :
1478+ """Return True if mainwindow is modified"""
1479+ return self .__is_modified
1480+
14771481 def __add_dockwidget (self , child , title : str ) -> QW .QDockWidget :
14781482 """Add QDockWidget and toggleViewAction"""
14791483 dockwidget , location = child .create_dockwidget (title )
@@ -1683,9 +1687,7 @@ def save_to_h5_file(self, filename=None) -> None:
16831687 if not filename :
16841688 return
16851689 with qth .qt_try_loadsave_file (self , filename , "save" ):
1686- filename = self .__check_h5file (filename , "save" )
1687- self .h5inputoutput .save_file (filename )
1688- self .set_modified (False )
1690+ self .save_h5_workspace (filename )
16891691
16901692 @remote_controlled
16911693 def open_h5_files (
@@ -1791,6 +1793,59 @@ def browse_h5_files(self, filenames: list[str], reset_all: bool) -> None:
17911793 self .__check_h5file (filename , "load" )
17921794 self .h5inputoutput .import_files (filenames , False , reset_all )
17931795
1796+ @remote_controlled
1797+ def load_h5_workspace (self , h5files : list [str ], reset_all : bool = False ) -> None :
1798+ """Load native DataLab HDF5 workspace files without any GUI elements.
1799+
1800+ This method can be safely called from the internal console as it does not
1801+ create any Qt widgets, dialogs, or progress bars. It is designed for
1802+ programmatic use when loading DataLab workspace files.
1803+
1804+ .. warning::
1805+
1806+ This method only supports native DataLab HDF5 files. For importing
1807+ arbitrary HDF5 files (non-native), use the GUI menu or macros with
1808+ :class:`datalab.control.proxy.RemoteProxy`.
1809+
1810+ Args:
1811+ h5files: List of native DataLab HDF5 filenames
1812+ reset_all: Reset all application data before importing. Defaults to False.
1813+
1814+ Raises:
1815+ ValueError: If a file is not a valid native DataLab HDF5 file
1816+ """
1817+ for idx , filename in enumerate (h5files ):
1818+ filename = self .__check_h5file (filename , "load" )
1819+ success = self .h5inputoutput .open_file_headless (
1820+ filename , reset_all = (reset_all and idx == 0 )
1821+ )
1822+ if not success :
1823+ raise ValueError (
1824+ f"File '{ filename } ' is not a native DataLab HDF5 file. "
1825+ f"Use the GUI menu or a macro with RemoteProxy to import "
1826+ f"arbitrary HDF5 files."
1827+ )
1828+ # Refresh panel trees after loading
1829+ self .repopulate_panel_trees ()
1830+
1831+ @remote_controlled
1832+ def save_h5_workspace (self , filename : str ) -> None :
1833+ """Save current workspace to a native DataLab HDF5 file without GUI elements.
1834+
1835+ This method can be safely called from the internal console as it does not
1836+ create any Qt widgets, dialogs, or progress bars. It is designed for
1837+ programmatic use when saving DataLab workspace files.
1838+
1839+ Args:
1840+ filename: HDF5 filename to save to
1841+
1842+ Raises:
1843+ IOError: If file cannot be saved
1844+ """
1845+ filename = self .__check_h5file (filename , "save" )
1846+ self .h5inputoutput .save_file (filename )
1847+ self .set_modified (False )
1848+
17941849 @remote_controlled
17951850 def import_h5_file (self , filename : str , reset_all : bool | None = None ) -> None :
17961851 """Import HDF5 file into DataLab
@@ -2151,7 +2206,7 @@ def close_properly(self) -> bool:
21512206 Returns:
21522207 True if closed properly, False otherwise
21532208 """
2154- if not env .execenv .unattended and self .__is_modified :
2209+ if not env .execenv .unattended and self .is_modified () :
21552210 answer = QW .QMessageBox .warning (
21562211 self ,
21572212 _ ("Quit" ),
@@ -2163,7 +2218,7 @@ def close_properly(self) -> bool:
21632218 )
21642219 if answer == QW .QMessageBox .Yes :
21652220 self .save_to_h5_file ()
2166- if self .__is_modified :
2221+ if self .is_modified () :
21672222 return False
21682223 elif answer == QW .QMessageBox .Cancel :
21692224 return False
0 commit comments