Object view#
The datalab.gui.objectview module provides widgets to display object
(signal/image) trees.
Note
This module provides tree widgets to display signals, images and groups. It is important to note that, by design, the user can only select either individual signals/images or groups, but not both at the same time. This is an important design choice, as it allows to simplify the user experience, and to avoid potential confusion between the two types of selection.
Simple object tree#
- class datalab.gui.objectview.SimpleObjectTree(parent: QW.QWidget, objmodel: ObjectModel)[source]#
Base object handling panel list widget, object (sig/ima) lists
- initialize_from(sobjlist: SimpleObjectTree) None[source]#
Init from another SimpleObjectList, without making copies of objects
- iter_items(item: QTreeWidgetItem | None = None) Iterator[QTreeWidgetItem][source]#
Recursively iterate over all items
- get_item_from_id(item_id) QTreeWidgetItem[source]#
Return QTreeWidgetItem from id (stored in item’s data)
- 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.
- get_sel_objects(include_groups: bool = False) list[SignalObj | ImageObj][source]#
Return selected objects.
If include_groups is True, also return objects from selected groups.
- get_sel_groups() list[ObjectGroup][source]#
Return selected groups
- resolve_title_reference(reference: str) tuple[str, SignalObj | ImageObj | ObjectGroup] | None[source]#
Resolve a title reference to
(panel_str, obj).Default implementation only looks up the tree’s own model and returns an empty
panel_str. Subclasses with access to several panels should override this method.
- get_title_reference_display(reference: str) str | None[source]#
Return the configured display text for a resolvable title reference.
- get_source_title(reference: str) str | None[source]#
Return the title of the object or group a reference resolves to.
- build_title_reference_tooltip(text: str) str[source]#
Return an HTML tooltip fragment listing the source objects referenced in
text, or an empty string when no such reference is found.
- handle_title_reference_click(reference: str) None[source]#
Handle a click on a title-reference hyperlink. Default implementation selects the matching object within the tree’s own model.
- title_reference_at(pos: QPoint) str | None[source]#
Return the title reference under viewport position
pos, orNonewhen the cursor is not over an anchor.
- mousePressEvent(event: QMouseEvent) None[source]#
Reimplement Qt method to handle short-ID hyperlink clicks.
- mouseMoveEvent(event: QMouseEvent) None[source]#
Reimplement Qt method to update the cursor over short-ID anchors.
- hovered_index() QModelIndex[source]#
Return the index of the item under the mouse cursor (invalid if none)
- changeEvent(event: QEvent) None[source]#
Reimplement Qt method to keep hover events after a style change (some styles disable them when unpolishing item views)
- update_tree() None[source]#
Update tree
Note: If an item is not found in the tree, the tree is repopulated to ensure consistency between the tree and the model. This can happen in rare cases when objects are added to the model but the tree was not properly updated.
- resize_title_column(items: Sequence[QTreeWidgetItem] | None = None) None[source]#
Fit the title column to the titles.
- Parameters:
items – Items just added to a tree whose column was already fitted to the other items: the column is only widened if one of them needs it, without measuring every title again. All items when None.
- add_group_item(group: ObjectGroup, resize: bool = True) None[source]#
Add group item
- Parameters:
group – Group to add, with its objects
resize – If True, fit the title column to the new items
- add_object_item(obj: SignalObj | ImageObj, group_id: str, set_current: bool = True) None[source]#
Add item
- add_object_items(objects: Sequence[SignalObj | ImageObj], group_id: str, set_current: bool = True) None[source]#
Add multiple object items with a single tree update cycle.
- Parameters:
objects – Objects to add, in insertion order
group_id – UUID of the parent group
set_current – If True, set the last object as current
- remove_items(oids: Sequence[str], refresh: bool = True) None[source]#
Remove items, in this order (looking the items up once for all)
- Parameters:
oids – UUIDs of the objects or groups (unknown UUIDs are ignored)
refresh – False to block the signals of the tree while removing
Get object dialog#
- class datalab.gui.objectview.GetObjectsDialog(parent: QW.QWidget, panel: BaseDataPanel, title: str, comment: str = '', nb_objects: int = 1, minimum_size: tuple[int, int] | None = None)[source]#
Dialog box showing groups and objects (signals or images) to select one, or more.
- Parameters:
parent – parent widget
panel – data panel
title – dialog title
comment – optional dialog comment
nb_objects – number of objects to select (default: 1)
minimum_size – minimum size (width, height)
Object view#
- class datalab.gui.objectview.ObjectView(parent: BaseDataPanel, objmodel: ObjectModel)[source]#
Object handling panel list widget, object (sig/ima) lists
A delete button is shown at the right of the hovered item (signal, image or group), unless disabled (see
set_delete_button_enabled()): clicking it emitsSIG_DELETE_REQUESTEDwith the item UUID.- set_delete_button_enabled(enabled: bool) None[source]#
Show or hide the delete button of the hovered item
- Parameters:
enabled – True to show the button
- is_delete_button_enabled() bool[source]#
Return True if the delete button of the hovered item is shown
- delete_button_rect(index: QModelIndex) QRect | None[source]#
Return the rectangle of the delete button of an item
The button is shown on the hovered item only, at the right edge of the visible part of the viewport (the title column may be wider than the viewport).
- Parameters:
index – model index of the item
- Returns:
Button rectangle in viewport coordinates, or None if the item shows no delete button.
- get_delete_targets(uuid: str) list[str][source]#
Return the UUIDs of the items deleted by the delete button of an item
- Parameters:
uuid – UUID of the item whose delete button is clicked
- Returns:
UUIDs of the selected objects or groups if the item is part of the selection, else the item UUID only.
- delete_button_tooltip(index: QModelIndex) str[source]#
Return the tooltip of the delete button of an item
- Parameters:
index – model index of the item
- Returns:
Tooltip text
- drawRow(painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex) None[source]#
Reimplement Qt method to draw the delete button of the hovered item
- viewportEvent(event: QEvent) bool[source]#
Reimplement Qt method to show the tooltip of the delete button and follow the mouse cursor over it
- mousePressEvent(event: QMouseEvent) None[source]#
Reimplement Qt method to press the delete button, without selecting or dragging the item
- mouseMoveEvent(event: QMouseEvent) None[source]#
Reimplement Qt method to follow the mouse cursor over the delete button
- mouseReleaseEvent(event: QMouseEvent) None[source]#
Reimplement Qt method to click the delete button
- mouseDoubleClickEvent(event: QMouseEvent) None[source]#
Reimplement Qt method to ignore double-clicks on the delete button (which would open the item in a separate view)
- resolve_title_reference(reference: str) tuple[str, SignalObj | ImageObj | ObjectGroup] | None[source]#
Resolve a title reference across the signal and image panels of the main window, so titles can reference objects living in either panel.
- handle_title_reference_click(reference: str) None[source]#
Select the referenced object, switching active panel if needed.
- get_all_group_uuids() list[str][source]#
Return all group uuids, in a list ordered by group position in the tree
- get_all_object_uuids() dict[str, list[str]][source]#
Return all object uuids, in a dictionary that maps group uuids to the list of object uuids in each group, in the correct order
- get_current_object_uuid() str | None[source]#
Return current object uuid, or None if current item is a group or if no item is current
- select_uuids(uuids: Sequence[str], notify: bool = True) None[source]#
Select objects or groups atomically, the last one becoming current
- Parameters:
uuids – UUIDs of the objects or groups to select
notify – if True, publish the complete final state once (see
item_selection_changed())
- item_selection_changed() None[source]#
Refreshing the selection of objects and groups, emitting the SIG_SELECTION_CHANGED signal which triggers the update of the object properties panel, the plot items and the actions of the toolbar and menu bar.
This method is called when the user selects or deselects items in the tree. It is also called when the user clicks on an item that was already selected.
This method emits the SIG_SELECTION_CHANGED signal.
- select_objects(selection: list[SignalObj | ImageObj | int | str]) None[source]#
Select multiple objects
- Parameters:
selection – list of objects, object numbers (1 to N) or object uuids