Skip to content

Commit

Permalink
fix: catch errors in property widget when building device property ta…
Browse files Browse the repository at this point in the history
…ble (#224)

fix: catch error in property widget
  • Loading branch information
tlambert03 authored Oct 12, 2023
1 parent 54a7c33 commit 3974f92
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/pymmcore_widgets/_device_property_table.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from logging import getLogger
from typing import Iterable, cast

from fonticon_mdi6 import MDI6
Expand Down Expand Up @@ -31,6 +32,8 @@
DeviceType.Serial: MDI6.serial_port,
}

logger = getLogger(__name__)


class DevicePropertyTable(QTableWidget):
"""Table of all currently loaded device properties.
Expand Down Expand Up @@ -140,18 +143,24 @@ def _rebuild_table(self) -> None:
for i, prop in enumerate(props):
item = QTableWidgetItem(f"{prop.device}-{prop.name}")
item.setData(self.PROP_ROLE, prop)
# TODO: make sure to add icons for all possible device types
icon_string = ICONS.get(prop.deviceType(), None)
icon_string = ICONS.get(prop.deviceType())
if icon_string:
item.setIcon(icon(icon_string, color="Gray"))
self.setItem(i, 0, item)

wdg = PropertyWidget(
prop.device,
prop.name,
mmcore=self._mmc,
connect_core=self._connect_core,
)
try:
wdg = PropertyWidget(
prop.device,
prop.name,
mmcore=self._mmc,
connect_core=self._connect_core,
)
except Exception as e:
logger.error(
f"Error creating widget for {prop.device}-{prop.name}: {e}"
)
continue

self.setCellWidget(i, 1, wdg)
if not self._prop_widgets_enabled:
wdg.setEnabled(False)
Expand Down

0 comments on commit 3974f92

Please sign in to comment.