Main window#
The datalab.gui.main module provides the main window of the
DataLab project.
- class datalab.gui.main.DLMainWindow(console=None, hide_on_close=False)[source]#
DataLab main window
- Parameters:
console β enable internal console
hide_on_close β True to hide window on close
- static xmlrpc_server_started(port)[source]#
XML-RPC server has started, writing comm port in configuration file
- get_group_titles_with_object_info() tuple[list[str], list[list[str]], list[list[str]]][source]#
Return groups titles and lists of inner objects uuids and titles.
- Returns:
Groups titles, lists of inner objects uuids and titles
- get_object_titles(panel: Literal['signal', 'image', 'macro'] | None = None) list[str][source]#
Get object (signal/image) list for current panel. Objects are sorted by group number and object index in group.
- Parameters:
panel β panel name. If None, current data panel is used (i.e. signal or image panel).
- Returns:
List of object titles
- Raises:
ValueError β if panel is unknown
- get_object(nb_id_title: int | str | None = None, panel: Literal['signal', 'image'] | None = None) SignalObj | ImageObj[source]#
Get object (signal/image) from index.
- find_object_by_uuid(uuid: str) SignalObj | ImageObj | ObjectGroup | None[source]#
Find an object by UUID, searching across all panels.
This method searches for an object in both signal and image panels, making it suitable for cross-panel operations (e.g., radial profile that takes an ImageObj and produces a SignalObj).
Difference from get_object(): - get_object() requires specifying a panel and accepts number/id/title - find_object_by_uuid() searches all panels automatically using only UUID
- Parameters:
uuid β UUID of the object to find
- Returns:
The object if found in any panel, None otherwise
- get_object_uuids(panel: Literal['signal', 'image'] | None = None, group: int | str | None = None) list[str][source]#
Get object (signal/image) uuid list for current panel. Objects are sorted by group number and object index in group.
- Parameters:
panel β panel name. If None, current panel is used.
group β Group number, or group id, or group title. Defaults to None (all groups).
- Returns:
List of object uuids
- Raises:
ValueError β if panel is unknown
- get_sel_object_uuids(include_groups: bool = False) list[str][source]#
Return selected objects uuids.
- Parameters:
include_groups β If True, also return objects from selected groups.
- Returns:
List of selected objects uuids.
- add_group(title: str, panel: Literal['signal', 'image'] | None = None, select: bool = False) None[source]#
Add group to DataLab.
- Parameters:
title β Group title
panel β Panel name. Defaults to None.
select β Select the group after creation. Defaults to False.
- select_objects(selection: list[int | str], panel: Literal['signal', 'image'] | None = None) None[source]#
Select objects in current panel.
- Parameters:
selection β List of object numbers (1 to N) or uuids to select
panel β panel name. If None, current panel is used. Defaults to None.
- select_groups(selection: list[int | str] | None = None, panel: Literal['signal', 'image'] | None = None) None[source]#
Select groups in current panel.
- Parameters:
selection β List of group numbers (1 to N), or list of group uuids, or None to select all groups. Defaults to None.
panel β panel name. If None, current panel is used. Defaults to None.
- delete_metadata(refresh_plot: bool = True, keep_roi: bool = False) None[source]#
Delete metadata of selected objects
- Parameters:
refresh_plot β Refresh plot. Defaults to True.
keep_roi β Keep ROI. Defaults to False.
- call_method(method_name: str, *args, panel: Literal['signal', 'image'] | None = None, **kwargs)[source]#
Call a public method on a panel or main window.
This generic method allows calling any public method that is not explicitly exposed in the proxy API. The method resolution follows this order:
If panel is specified: call method on that specific panel
If panel is None: a. Try to call method on main window (DLMainWindow) b. If not found, try to call method on current panel (BaseDataPanel)
This makes it convenient to call panel methods without specifying the panel parameter when working on the current panel.
- Parameters:
method_name β Name of the method to call
*args β Positional arguments to pass to the method
panel β Panel name (βsignalβ, βimageβ, or None for auto-detection). Defaults to None.
**kwargs β Keyword arguments to pass to the method
- Returns:
The return value of the called method
- Raises:
AttributeError β If the method does not exist or is not public
ValueError β If the panel name is invalid
Examples
>>> # Call remove_object on current panel (auto-detected) >>> win.call_method("remove_object", force=True) >>> # Call a signal panel method specifically >>> win.call_method("delete_all_objects", panel="signal") >>> # Call main window method >>> win.call_method("get_current_panel")
- call_method_slot(method_name: str, args: list, panel: Literal['signal', 'image'] | None, kwargs: dict) None[source]#
Slot to call a method from RemoteServer thread in GUI thread.
This slot receives signals from RemoteServer and executes the method in the GUI thread, avoiding thread-safety issues with Qt widgets and dialogs.
- Parameters:
method_name β Name of the method to call
args β Positional arguments as a list
panel β Panel name or None for auto-detection
kwargs β Keyword arguments as a dict
- get_object_shapes(nb_id_title: int | str | None = None, panel: Literal['signal', 'image'] | None = None) list[source]#
Get plot item shapes associated to object (signal/image).
- Parameters:
nb_id_title β Object number, or object id, or object title. Defaults to None (current object).
panel β Panel name. Defaults to None (current panel).
- Returns:
List of plot item shapes
- add_annotations_from_items(items: list, refresh_plot: bool = True, panel: Literal['signal', 'image'] | None = None) None[source]#
Add object annotations (annotation plot items).
- Parameters:
items β annotation plot items
refresh_plot β refresh plot. Defaults to True.
panel β panel name. If None, current panel is used.
- add_label_with_title(title: str | None = None, panel: Literal['signal', 'image'] | None = None) None[source]#
Add a label with object title on the associated plot
- Parameters:
title β Label title. Defaults to None. If None, the title is the object title.
panel β panel name. If None, current panel is used.
- run_macro(number_or_title: int | str | None = None) None[source]#
Run macro.
- Parameters:
number β Number of the macro (starting at 1). Defaults to None (run current macro, or does nothing if there is no macro).
- stop_macro(number_or_title: int | str | None = None) None[source]#
Stop macro.
- Parameters:
number β Number of the macro (starting at 1). Defaults to None (stop current macro, or does nothing if there is no macro).
- import_macro_from_file(filename: str) None[source]#
Import macro from file
- Parameters:
filename β Filename.
- start_webapi_server(host: str | None = None, port: int | None = None) dict[source]#
Start the Web API server.
- Parameters:
host β Host address to bind to. Defaults to β127.0.0.1β.
port β Port number. Defaults to auto-detect available port.
- Returns:
Dictionary with βurlβ and βtokenβ keys.
- Raises:
RuntimeError β If Web API deps not installed or server already running.
- get_webapi_status() dict[source]#
Get Web API server status.
- Returns:
Dictionary with βrunningβ, βurlβ, and βtokenβ keys.
- property panels: tuple[AbstractPanel, ...]#
Return the tuple of implemented panels (signal, image)
- Returns:
Tuple of panels
- confirm_memory_state() bool[source]#
Check memory warning state and eventually show a warning dialog
- Returns:
True if memory state is ok
Take menu screenshots
- setup(console: bool = False) None[source]#
Setup main window
- Parameters:
console β True to setup console
- set_process_isolation_enabled(state: bool) None[source]#
Enable/disable process isolation
- Parameters:
state β True to enable process isolation
- get_current_panel() str[source]#
Return current panel name
- Returns:
βsignalβ, βimageβ, βmacroβ)
- Return type:
Panel name (valid values
- set_current_panel(panel: Literal['signal', 'image', 'macro'] | BaseDataPanel) None[source]#
Switch to panel.
- Parameters:
panel β panel name or panel instance
- Raises:
ValueError β unknown panel
- calc(name: str, param: DataSet | None = None, edit: bool = True) None[source]#
Call computation feature
nameNote
This calls either the processorβs
compute_<name>method (if it exists), or the processorβs<name>computation feature (if it is registered, using therun_featuremethod). It looks for the function in all panels, starting with the current one.- Parameters:
name β Compute function name
param β Compute function parameter. Defaults to None.
edit β Whether to show parameter edit dialog. Defaults to True. Set to False when calling from remote/API to avoid blocking dialogs.
- Raises:
ValueError β unknown function
- toggle_show_titles(state: bool) None[source]#
Toggle show annotations option
- Parameters:
state β state
- handle_autorefresh_action(state: bool) None[source]#
Handle auto-refresh action from UI (with confirmation dialog)
- Parameters:
state β desired state
- toggle_auto_refresh(state: bool) None[source]#
Toggle auto refresh option
- Parameters:
state β state
- toggle_show_first_only(state: bool) None[source]#
Toggle show first only option
- Parameters:
state β state
- remove_object(force: bool = False) None[source]#
Remove current object from current panel.
- Parameters:
force β if True, remove object without confirmation. Defaults to False.
- save_to_h5_file(filename=None) None[source]#
Save to a DataLab HDF5 file
- Parameters:
filename β HDF5 filename. If None, a file dialog is opened.
- Raises:
IOError β if filename is invalid or file cannot be saved.
- open_h5_files(h5files: list[str] | None = None, import_all: bool | None = None, reset_all: bool | None = None) None[source]#
Open a DataLab HDF5 file or import from any other HDF5 file.
- Parameters:
h5files β HDF5 filenames (optionally with dataset name, separated by β:β)
import_all β Import all datasets from HDF5 files
reset_all β Reset all application data before importing
- browse_h5_files(filenames: list[str], reset_all: bool) None[source]#
Browse HDF5 files
- Parameters:
filenames β HDF5 filenames
reset_all β Reset all application data before importing
- load_h5_workspace(h5files: list[str], reset_all: bool = False) None[source]#
Load native DataLab HDF5 workspace files without any GUI elements.
This method can be safely called from the internal console as it does not create any Qt widgets, dialogs, or progress bars. It is designed for programmatic use when loading DataLab workspace files.
Warning
This method only supports native DataLab HDF5 files. For importing arbitrary HDF5 files (non-native), use the GUI menu or macros with
datalab.control.proxy.RemoteProxy.- Parameters:
h5files β List of native DataLab HDF5 filenames
reset_all β Reset all application data before importing. Defaults to False.
- Raises:
ValueError β If a file is not a valid native DataLab HDF5 file
- save_h5_workspace(filename: str) None[source]#
Save current workspace to a native DataLab HDF5 file without GUI elements.
This method can be safely called from the internal console as it does not create any Qt widgets, dialogs, or progress bars. It is designed for programmatic use when saving DataLab workspace files.
- Parameters:
filename β HDF5 filename to save to
- Raises:
IOError β If file cannot be saved
- import_h5_file(filename: str, reset_all: bool | None = None) None[source]#
Import HDF5 file into DataLab
- Parameters:
filename β HDF5 filename (optionally with dataset name,
" (separated by) β β)
reset_all β Delete all DataLab signals/images before importing data
- add_object(obj: SignalObj | ImageObj, group_id: str = '', set_current=True) None[source]#
Add object - signal or image
- Parameters:
obj β object to add (signal or image)
group_id β group ID (optional)
set_current β True to set the object as current object
- load_from_files(filenames: list[str]) None[source]#
Open objects from files in current panel (signals/images)
- Parameters:
filenames β list of filenames
- load_from_directory(path: str) None[source]#
Open objects from directory in current panel (signals/images).
- Parameters:
path β directory path
- add_signal(title: str, xdata: ndarray, ydata: ndarray, xunit: str = '', yunit: str = '', xlabel: str = '', ylabel: str = '', group_id: str = '', set_current: bool = True) bool[source]#
Add signal data to DataLab.
- Parameters:
title β Signal title
xdata β X data
ydata β Y data
xunit β X unit. Defaults to ββ
yunit β Y unit. Defaults to ββ
xlabel β X label. Defaults to ββ
ylabel β Y label. Defaults to ββ
group_id β group id in which to add the signal. Defaults to ββ
set_current β if True, set the added signal as current
- Returns:
True if signal was added successfully, False otherwise
- Raises:
ValueError β Invalid xdata dtype
ValueError β Invalid ydata dtype
- add_image(title: str, data: ndarray, xunit: str = '', yunit: str = '', zunit: str = '', xlabel: str = '', ylabel: str = '', zlabel: str = '', group_id: str = '', set_current: bool = True) bool[source]#
Add image data to DataLab.
- Parameters:
title β Image title
data β Image data
xunit β X unit. Defaults to ββ
yunit β Y unit. Defaults to ββ
zunit β Z unit. Defaults to ββ
xlabel β X label. Defaults to ββ
ylabel β Y label. Defaults to ββ
zlabel β Z label. Defaults to ββ
group_id β group id in which to add the image. Defaults to ββ
set_current β if True, set the added image as current
- Returns:
True if image was added successfully, False otherwise
- Raises:
ValueError β Invalid data dtype