Skip to content

Commit

Permalink
widget: be more permissive in backend names
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Jan 8, 2025
1 parent 8e927e5 commit 6d06752
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* Ensure that operators such as (e.g. `+`, `-`, `/`) work on [`Slice`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.channel.Slice.html) with all types that are convertible to scalars. Previously these failed with zero dimensional numpy arrays and other convertible objects.
* Fixed a bug where bead edge determination could fail with an unhandled exception during background estimation. This raised a `np.linalg.LinAlgError` when determining the background failed rather than the expected `RuntimeError`. In this case, a simple median is used as a fallback option.
* Fix a bug to ensure that [`lk.GaussianMixtureModel`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.GaussianMixtureModel.html) can also be used with a single state.
* Fixed bug that prevented opening the force distance widgets when using them with the `widget` backend on `matplotlib >= 3.9.0`.

## v1.5.3 | 2024-10-29

Expand Down
16 changes: 16 additions & 0 deletions lumicks/pylake/nb_widgets/detail/shared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def check_widget_backend():
import matplotlib.pyplot as plt

if not max(
# Note: Some, but not all versions of matplotlib lower the backend names. Hence, we
# always lower them to be on the safe side.
[backend in plt.get_backend().lower() for backend in ("nbagg", "ipympl", "widget")]
):
raise RuntimeError(
(
"Please enable an interactive matplotlib backend for this widget to work. In "
"jupyter notebook or lab you can do this by invoking either "
"%matplotlib widget or %matplotlib ipympl. Please note that you may have to "
"restart the notebook kernel for this to work."
),
)
17 changes: 3 additions & 14 deletions lumicks/pylake/nb_widgets/kymotracker_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from lumicks.pylake.kymotracker.kymotrack import KymoTrackGroup, load_tracks
from lumicks.pylake.kymotracker.kymotracker import track_greedy, _to_half_kernel_size
from lumicks.pylake.nb_widgets.detail.mouse import MouseDragCallback
from lumicks.pylake.nb_widgets.detail.shared import check_widget_backend
from lumicks.pylake.nb_widgets.detail.undostack import UndoStack


Expand Down Expand Up @@ -435,19 +436,7 @@ def _create_widgets(self):
import matplotlib.pyplot as plt
from IPython.display import display

if not max(
# Note: Some, but not all versions of matplotlib lower the backend names. Hence, we
# always lower them to be on the safe side.
[backend in plt.get_backend().lower() for backend in ("nbagg", "ipympl", "widget")]
):
raise RuntimeError(
(
"Please enable an interactive matplotlib backend for this plot to work. In "
"jupyter notebook or lab you can do this by invoking either "
"%matplotlib widget or %matplotlib ipympl. Please note that you may have to "
"restart the notebook kernel for this to work."
)
)
check_widget_backend()

self._labels["status"] = ipywidgets.Label(value="")
self._labels["warning"] = ipywidgets.HTML(value="")
Expand Down Expand Up @@ -543,7 +532,7 @@ def set_fn(value):

display(ui)

if "ipympl" not in plt.get_backend():
if not any(backend in plt.get_backend().lower() for backend in ("ipympl", "widget")):
# Without this, the figure doesn't show up on non ipympl backends
with output:
display(self._fig)
Expand Down
12 changes: 3 additions & 9 deletions lumicks/pylake/nb_widgets/range_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import numpy as np

from lumicks.pylake.nb_widgets.detail.shared import check_widget_backend


class BaseRangeSelectorWidget:
"""Base class for range selection widgets.
Expand Down Expand Up @@ -270,15 +272,7 @@ def __init__(self, fd_curves):
"F,d selector widget cannot open without a non-empty dictionary containing F,d curves."
)

if not any(backend in plt.get_backend() for backend in ("nbAgg", "ipympl")):
raise RuntimeError(
(
"Please enable an interactive matplotlib backend for this plot to work. In "
"jupyter notebook or lab you can do this by invoking either "
"%matplotlib widget. Please note that you may have to restart the notebook "
"kernel for this to work."
)
)
check_widget_backend()

plt.figure()
self.axes = plt.axes()
Expand Down

0 comments on commit 6d06752

Please sign in to comment.