Widgets

class squirrel.widgets.flow_layout.FlowLayout(*args: Any, **kwargs: Any)[source]

A custom layout that arranges child widgets in a flowing manner.

Widgets are placed horizontally until there is no more space, then the layout wraps them to the next line. This layout is useful for creating a tag cloud, button groups, or any interface where items should wrap automatically.

Methods

__call__(*args, **kwargs)

Call self as a function.

addItem(item)

Add an item to the layout.

count()

Return the number of items in the layout.

doLayout(rect, testOnly)

Layout the items within the given rectangle.

expandingDirections()

Specify the directions in which the layout can expand.

hasHeightForWidth()

Indicate that this layout has a height-for-width dependency.

heightForWidth(width)

Calculate the height of the layout given a specific width.

itemAt(index)

Return the layout item at the given index.

minimumSize()

Calculate the minimum size required by the layout.

setGeometry(rect)

Set the geometry of the layout and position the child items.

sizeHint()

Provide a recommended size for the layout.

takeAt(index)

Remove and return the layout item at the given index.

addItem(item: qtpy.QtWidgets.QLayoutItem) None[source]

Add an item to the layout.

Parameters:
itemQLayoutItem

The layout item to add.

count() int[source]

Return the number of items in the layout.

Returns:
int

The count of items currently in the layout.

doLayout(rect: qtpy.QtCore.QRect, testOnly: bool) int[source]

Layout the items within the given rectangle.

Items are arranged horizontally until there is no more space, then they wrap to the next line. This method is used both for setting the geometry and for calculating the required height.

Parameters:
rectQRect

The rectangle within which to layout the items.

testOnlybool

If True, the layout is calculated but item geometries are not set.

Returns:
int

The total height required by the layout.

expandingDirections() qtpy.QtCore.Qt.Orientations[source]

Specify the directions in which the layout can expand.

Returns:
Qt.Orientations

A combination of Qt.Horizontal and Qt.Vertical indicating that the layout can expand in both directions.

hasHeightForWidth() bool[source]

Indicate that this layout has a height-for-width dependency.

Returns:
bool

True, since the layout’s height depends on its width.

heightForWidth(width: int) int[source]

Calculate the height of the layout given a specific width.

Parameters:
widthint

The width to calculate the height for.

Returns:
int

The computed height based on the layout of items.

itemAt(index: int) qtpy.QtWidgets.QLayoutItem[source]

Return the layout item at the given index.

Parameters:
indexint

The index of the item.

Returns:
QLayoutItem or None

The layout item if index is valid; otherwise, None.

minimumSize() qtpy.QtCore.QSize[source]

Calculate the minimum size required by the layout.

Returns:
QSize

The minimum size that can contain all layout items with margins.

setGeometry(rect: qtpy.QtCore.QRect) None[source]

Set the geometry of the layout and position the child items.

Parameters:
rectQRect

The rectangle that defines the area available for the layout.

sizeHint() qtpy.QtCore.QSize[source]

Provide a recommended size for the layout.

Returns:
QSize

The recommended size, based on the minimum size of the items.

takeAt(index: int) qtpy.QtWidgets.QLayoutItem[source]

Remove and return the layout item at the given index.

Parameters:
indexint

The index of the item to remove.

Returns:
QLayoutItem or None

The removed layout item if index is valid; otherwise, None.

class squirrel.widgets.pv_details_components.PVDetails(setpoint_name: str, readback_name: str, description: str, tolerance_abs: float, tolerance_rel: float, tags: dict[int, set[int]], device: str = '', lolo: float | None = None, low: float | None = None, high: float | None = None, hihi: float | None = None)[source]

Class to represent the details of a PV (Process Variable). Used to populate the PV details popups.

Attributes:
high
hihi
lolo
low
class squirrel.widgets.pv_details_components.PVDetailsPopup(*args: Any, **kwargs: Any)[source]

Read-only popup displaying PV details.

Methods

__call__(*args, **kwargs)

Call self as a function.

class squirrel.widgets.pv_details_components.PVDetailsPopupEditable(*args: Any, **kwargs: Any)[source]

Editable popup for creating or editing PVs.

Methods

__call__(*args, **kwargs)

Call self as a function.

handle_submit()

Handle save button press.

keyPressEvent(event)

Submit the PV edit on Enter key press, or close the popup on Escape key press.

handle_submit() None[source]

Handle save button press.

keyPressEvent(event: qtpy.QtGui.QKeyEvent)[source]

Submit the PV edit on Enter key press, or close the popup on Escape key press.

class squirrel.widgets.pv_details_components.PVDetailsRow(*args: Any, **kwargs: Any)[source]

A row in the PV details popup.

Methods

__call__(*args, **kwargs)

Call self as a function.

class squirrel.widgets.pv_details_components.PVDetailsTitleBar(*args: Any, **kwargs: Any)[source]

Title bar for the PV details popup. Allows dragging and closing the popup.

Methods

__call__(*args, **kwargs)

Call self as a function.

mouseMoveEvent

mousePressEvent

class squirrel.widgets.tag.TagChip(*args: Any, **kwargs: Any)[source]

A UI element representing active tags for one tag group. TagsWidget uses multiple to represent a full TagSet.

This widget display the tag group name and the name of all its active tags. If enabled, clicking this widget opens a popup to activate or deactivate tags, and it exposes a button to clear all active tags.

Parameters:
tag_groupint

The index of this widget’s tag group.

choicesdict[int, str]

A map relating tag indices and names.

tag_namestr

The name of this widget’s tag group.

descstr

The description of this widget’s tag group. Only shown via tooltip.

enabledbool

Whether this widget is editable or its set of active tags is frozen.

**kwargsAny

Additional keyword arguments to pass to the base QWidget.

Methods

__call__(*args, **kwargs)

Call self as a function.

clear()

Clear this widget's active tags.

set_tags(tags)

Set this widget's active tags and redraw.

minimumSize

mouseReleaseEvent

paint

paintEvent

sizeHint

tagsChanged

clear() None[source]

Clear this widget’s active tags.

set_tags(tags: set[int]) None[source]

Set this widget’s active tags and redraw.

tagsChanged

alias of set

class squirrel.widgets.tag.TagDelegate(*args: Any, **kwargs: Any)[source]

Methods

__call__(*args, **kwargs)

Call self as a function.

paint

sizeHint

class squirrel.widgets.tag.TagEditor(*args: Any, **kwargs: Any)[source]

Popup for selecting a TagChip’s active tags.

Parameters:
choicesdict[int, str]

Map of tag indices to names; received from TagChip. Used to display the correct tag names while sending the correct tag indices back to the TagChip.

selectedset[int]

Set of tag indices representing active tags from the TagChip. These will be selected when this widget is initially shown.

parentQWidget

This widget’s parent; typically a TagChip. Only used for positioning, data is transferred via signals.

Attributes:
tagsChangedQtCore.Signal(set)

Signal emitted when the set of selected tags is changed.

Methods

__call__(*args, **kwargs)

Call self as a function.

emitTagsChanged()

Emits self.tagsChanged with the new set of selected tag indices.

set_choices(choices)

Set this widget's tag choices.

show

tagsChanged

emitTagsChanged()[source]

Emits self.tagsChanged with the new set of selected tag indices. Needed so that self.tagsChanged can emit the required data despite being connected to the data-less QListWidget.itemSelectionChanged signal.

set_choices(choices: dict[int, str]) None[source]

Set this widget’s tag choices. Clears and then re-populates choice_list, with each list item containing both the tag index and name.

tagsChanged

alias of set

class squirrel.widgets.tag.TagsWidget(*args: Any, **kwargs: Any)[source]

A container for TagChips arranged in a flow layout.

This widget manages a collection of tag elements, each of which manages the addition, removal, and display of tags in its tag group. To freeze the set of tags in the TagChips, set enabled to False on this widget. The tags are arranged using a custom FlowLayout that automatically wraps the tags when they reach the edge of the widget.

Attributes:
tag_list_layoutFlowLayout

The layout containing the widget’s tag elements.

Methods

__call__(*args, **kwargs)

Call self as a function.

clear_tags()

Clears all tags in all TagChips

emitTagSetChanged()

Emits the tagSetChanged signal with the widget's current TagSet

get_group_chip(tag_group)

Returns TagChip corresponding to the desired tag group, or None if chip was not found

get_tag_set()

Constructs the TagSet representation of the child TagChips

set_tags(tag_set)

Sets the child TagChips according to the provided TagSet

paint

set_tag_groups

tagSetChanged

clear_tags() None[source]

Clears all tags in all TagChips

emitTagSetChanged() None[source]

Emits the tagSetChanged signal with the widget’s current TagSet

get_group_chip(tag_group: int) TagChip | None[source]

Returns TagChip corresponding to the desired tag group, or None if chip was not found

get_tag_set() dict[int, set[int]][source]

Constructs the TagSet representation of the child TagChips

set_tags(tag_set: dict[int, set[int]]) None[source]

Sets the child TagChips according to the provided TagSet

tagSetChanged

alias of object

class squirrel.widgets.namedesctags.NameDescTagsWidget(*args: Any, **kwargs: Any)[source]

Widget for displaying and editing the name, description, and tags fields.

Any of these will be automatically disabled if the data source is missing the corresponding field.

Methods

__call__(*args, **kwargs)

Call self as a function.

apply_new_desc(desc)

When some other widget updates the description, update it here.

apply_new_name(text)

If the text changed in the data, update the widget.

init_desc()

Set up the desc_edit widget appropriately.

init_name()

Set up the name_edit widget appropriately.

init_tags(tag_groups)

Set up the tags widgets appropriately.

retranslateUi(*args, **kwargs)

Required function for setupUi to work in __init__

show_type_hints()

Show type hints of widgets included in the display for development help.

update_saved_desc()

When the user edits the desc, write to the config.

update_saved_name(name)

When the user edits the name, write to the config.

apply_new_desc(desc: str) None[source]

When some other widget updates the description, update it here.

init_desc() None[source]

Set up the desc_edit widget appropriately.

init_tags(tag_groups: dict[int, list[str | dict[int, str]]]) None[source]

Set up the tags widgets appropriately.

update_saved_desc() None[source]

When the user edits the desc, write to the config.

class squirrel.widgets.namedesctags.NameMixin[source]

Mixin class for distributing init_name

Methods

apply_new_name(text)

If the text changed in the data, update the widget.

init_name()

Set up the name_edit widget appropriately.

update_saved_name(name)

When the user edits the name, write to the config.

apply_new_name(text: str) None[source]

If the text changed in the data, update the widget.

Only run if needed to avoid annoyance with cursor repositioning.

init_name() None[source]

Set up the name_edit widget appropriately.

update_saved_name(name: str) None[source]

When the user edits the name, write to the config.

class squirrel.widgets.qsingleton.QtSingleton(*args: Any, **kwargs: Any)[source]

Qt specific singleton implementation, needed to ensure signals are shared between instances. Adapted from https://stackoverflow.com/questions/59459770/receiving-pyqtsignal-from-singleton

The more common __new__ - based singleton pattern does result in the QObject being a singleton, but the bound signals lose their connections whenever the instance is re-acquired. I do not understand but this works

To use this, specify QtSingleton as a metaclass:

class SingletonClass(QtCore.QObject, metaclass=QtSingleton):
    shared_signal: ClassVar[QtCore.Signal] = QtCore.Signal()

Methods

__call__(*args, **kwargs)

Call self as a function.

mro(/)

Return a type's method resolution order.

class squirrel.widgets.data_widget.DataWidget(*args: Any, **kwargs: Any)[source]

Base class for widgets that manipulate dataclasses.

Defines the init args for all data widgets and handles synchronization of the QDataclassBridge instances. This is done so that only data widgets need to consider how to handle bridges and the page classes simply need to pass in data structures, rather than needing to keep track of how two widgets editing the same data structure must share the same bridge object.

Parameters:
dataany dataclass

The dataclass that the widget needs to manipulate. Most widgets are expecting either specific dataclasses or dataclasses that have specific matching fields.

kwargsQWidget kwargs

Passed directly to QWidget’s __init__. Likely unused in most cases. Even parent is unlikely to see use because parent is set automatically when a widget is inserted into a layout.

Methods

__call__(*args, **kwargs)

Call self as a function.

class squirrel.widgets.display.Display(*args, **kwargs)[source]

Helper class for loading designer .ui files and adding logic

Methods

retranslateUi(*args, **kwargs)

Required function for setupUi to work in __init__

show_type_hints()

Show type hints of widgets included in the display for development help.