Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/pymmcore_widgets/_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ def __str__(self) -> str:
return self.value

@classmethod
def for_device_type(cls, device_type: DeviceType | str) -> StandardIcon:
def for_device_type(
cls, device_type: DeviceType | str, mmcore: CMMCorePlus | None = None
) -> StandardIcon:
"""Return an icon for a specific device type.

If a string is provided, it will be resolved to a DeviceType using the
CMMCorePlus.instance.
"""
if isinstance(device_type, str): # device label
core = mmcore or CMMCorePlus.instance()
try:
device_type = CMMCorePlus.instance().getDeviceType(device_type)
device_type = core.getDeviceType(device_type)
except Exception: # pragma: no cover
device_type = DeviceType.Unknown

Expand Down
8 changes: 6 additions & 2 deletions src/pymmcore_widgets/_models/_config_group_pivot_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import TYPE_CHECKING, Any

from pymmcore_plus import CMMCorePlus
from qtpy.QtCore import QAbstractTableModel, QModelIndex, QSize, Qt

from pymmcore_widgets._icons import StandardIcon
Expand All @@ -16,8 +17,11 @@
class ConfigGroupPivotModel(QAbstractTableModel):
"""Pivot a single ConfigGroup into rows=Device/Property, cols=Presets."""

def __init__(self, parent: QWidget | None = None) -> None:
def __init__(
self, parent: QWidget | None = None, mmcore: CMMCorePlus | None = None
) -> None:
super().__init__(parent)
self._mmcore = mmcore or CMMCorePlus.instance()
self._src: QConfigGroupsModel | None = None
self._gidx: QModelIndex | None = None
self._presets: list[ConfigPreset] = []
Expand Down Expand Up @@ -155,7 +159,7 @@ def headerData(
dev, _prop = self._rows[section]
except IndexError: # pragma: no cover
return None
if icon := StandardIcon.for_device_type(dev):
if icon := StandardIcon.for_device_type(dev, self._mmcore):
return icon.icon().pixmap(QSize(16, 16))
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ def create_from_core(
cls, core: CMMCorePlus, parent: QWidget | None = None
) -> ConfigGroupsTree:
"""Create a ConfigGroupsTree from a CMMCorePlus instance."""
obj = cls(parent)
obj = cls(parent, core)
model = QConfigGroupsModel.create_from_core(core)
obj.setModel(model)
return obj

def __init__(self, parent: QWidget | None = None) -> None:
def __init__(
self, parent: QWidget | None = None, core: CMMCorePlus | None = None
) -> None:
super().__init__(parent)
self.setItemDelegateForColumn(2, PropertySettingDelegate(self))
self.setItemDelegateForColumn(2, PropertySettingDelegate(self, mmcore=core))

def setModel(self, model: QAbstractItemModel | None) -> None:
"""Set the model for the tree view."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from contextlib import suppress
from typing import TYPE_CHECKING

from pymmcore_plus import CMMCorePlus
from qtpy.QtCore import (
QAbstractItemModel,
QModelIndex,
Expand All @@ -19,7 +20,6 @@
from ._property_setting_delegate import PropertySettingDelegate

if TYPE_CHECKING:
from pymmcore_plus import CMMCorePlus
from PyQt6.QtGui import QAction

else:
Expand All @@ -36,16 +36,19 @@ class ConfigPresetsTableView(QTableView):
`setGroup` with the name or index of the group you want to view.
"""

def __init__(self, parent: QWidget | None = None) -> None:
def __init__(
self, parent: QWidget | None = None, mmcore: CMMCorePlus | None = None
) -> None:
super().__init__(parent)
self.setItemDelegate(PropertySettingDelegate(self))
self._mmcore = mmcore or CMMCorePlus.instance()
self.setItemDelegate(PropertySettingDelegate(self, mmcore=mmcore))
self._transpose_proxy: QTransposeProxyModel | None = None
self._pivot_model: ConfigGroupPivotModel | None = None

def setModel(self, model: QAbstractItemModel | None) -> None:
"""Set the model for the table view."""
if isinstance(model, QConfigGroupsModel):
matrix = ConfigGroupPivotModel()
matrix = ConfigGroupPivotModel(mmcore=self._mmcore)
matrix.setSourceModel(model)
elif isinstance(model, ConfigGroupPivotModel): # pragma: no cover
matrix = model
Expand Down Expand Up @@ -151,14 +154,16 @@ def create_from_core(
cls, core: CMMCorePlus, parent: QWidget | None = None
) -> ConfigPresetsTable:
"""Create a PresetsTable from a CMMCorePlus instance."""
obj = cls(parent)
obj = cls(parent, core)
model = QConfigGroupsModel.create_from_core(core)
obj.setModel(model)
return obj

def __init__(self, parent: QWidget | None = None) -> None:
def __init__(
self, parent: QWidget | None = None, mmcore: CMMCorePlus | None = None
) -> None:
super().__init__(parent)
self.view = ConfigPresetsTableView(self)
self.view = ConfigPresetsTableView(self, mmcore=mmcore)

self._toolbar = tb = QToolBar(self)
tb.setIconSize(QSize(16, 16))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from pymmcore_plus import CMMCorePlus
from qtpy.QtCore import QAbstractItemModel, QModelIndex, Qt
from qtpy.QtWidgets import QStyledItemDelegate, QStyleOptionViewItem, QWidget

Expand All @@ -10,6 +11,12 @@
class PropertySettingDelegate(QStyledItemDelegate):
"""Item delegate that uses a PropertyWidget for editing PropertySetting values."""

def __init__(
self, parent: QWidget | None = None, mmcore: CMMCorePlus | None = None
) -> None:
super().__init__(parent)
self._mmcore = mmcore or CMMCorePlus.instance()

def createEditor(
self, parent: QWidget | None, option: QStyleOptionViewItem, index: QModelIndex
) -> QWidget | None:
Expand All @@ -21,6 +28,7 @@ def createEditor(
setting.device_label,
setting.property_name,
parent=parent,
mmcore=self._mmcore,
connect_core=False,
)
widget.setValue(setting.value) # avoids commitData warnings
Expand Down