Skip to content

Commit

Permalink
fix possible inconsistency
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Jul 19, 2024
1 parent 637bb26 commit 091103e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/pymmcore_widgets/_property_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,20 @@ def __init__(
self.layout().addWidget(cast(QWidget, self._value_widget))
self.destroyed.connect(self._disconnect)

def _try_update_from_core(self) -> None:
def _try_update_from_core(self) -> Any:
# set current value from core, ignoring errors
value = ""
with contextlib.suppress(RuntimeError, ValueError):
self._value_widget.setValue(self._mmc.getProperty(*self._dp))
value = self._mmc.getProperty(*self._dp)
self._value_widget.setValue(value)

# disable for any device init state besides 0 (Uninitialized)
if hasattr(self._mmc, "getDeviceInitializationState") and (
self._mmc.isPropertyPreInit(self._device_label, self._prop_name)
and self._mmc.getDeviceInitializationState(self._device_label)
):
self.setDisabled(True)
return value

# connect events and queue for disconnection on widget destroyed
def _on_core_change(self, dev_label: str, prop_name: str, new_val: Any) -> None:
Expand All @@ -360,7 +363,7 @@ def _on_value_widget_change(self, value: Any) -> None:
self._mmc.setProperty(self._device_label, self._prop_name, value)
except (RuntimeError, ValueError):

Check warning on line 364 in src/pymmcore_widgets/_property_widget.py

View check run for this annotation

Codecov / codecov/patch

src/pymmcore_widgets/_property_widget.py#L364

Added line #L364 was not covered by tests
# if there's an error when updating mmcore, reset widget value to mmcore
self._try_update_from_core()
value = self._try_update_from_core()

Check warning on line 366 in src/pymmcore_widgets/_property_widget.py

View check run for this annotation

Codecov / codecov/patch

src/pymmcore_widgets/_property_widget.py#L366

Added line #L366 was not covered by tests
self.valueChanged.emit(value)

def _disconnect(self) -> None:
Expand Down

0 comments on commit 091103e

Please sign in to comment.