Skip to content

Commit da74de1

Browse files
committed
make sure backgrounds are properly fetched (requires activating on_draw)
1 parent d26f641 commit da74de1

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

eomaps/helpers.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,6 @@ def _snap(self):
11501150
return snap
11511151

11521152
def _apply_modifications(self):
1153-
11541153
for ax in self.axes:
11551154
from matplotlib.transforms import Bbox
11561155

@@ -1259,38 +1258,39 @@ def add_image_axes(ax):
12591258

12601259
def _make_draggable(self, filepath=None):
12611260
self.modifier_pressed = True
1261+
with self.m.BM._cx_toggle_draw(True):
1262+
# Uncheck avtive pan/zoom actions of the matplotlib toolbar.
1263+
# use a try-except block to avoid issues with ipympl in jupyter notebooks
1264+
# (see https://github.com/matplotlib/ipympl/issues/530#issue-1780919042)
1265+
try:
1266+
toolbar = getattr(self.m.BM.canvas, "toolbar", None)
1267+
if toolbar is not None:
1268+
for key in ["pan", "zoom"]:
1269+
val = toolbar._actions.get(key, None)
1270+
if val is not None and val.isCheckable() and val.isChecked():
1271+
val.trigger()
1272+
except AttributeError:
1273+
pass
12621274

1263-
# Uncheck avtive pan/zoom actions of the matplotlib toolbar.
1264-
# use a try-except block to avoid issues with ipympl in jupyter notebooks
1265-
# (see https://github.com/matplotlib/ipympl/issues/530#issue-1780919042)
1266-
try:
1267-
toolbar = getattr(self.m.BM.canvas, "toolbar", None)
1268-
if toolbar is not None:
1269-
for key in ["pan", "zoom"]:
1270-
val = toolbar._actions.get(key, None)
1271-
if val is not None and val.isCheckable() and val.isChecked():
1272-
val.trigger()
1273-
except AttributeError:
1274-
pass
1275-
1276-
self._filepath = filepath
1277-
_log.info(
1278-
"EOmaps: Layout Editor activated! (press 'esc' to exit " "and 'q' for info)"
1279-
)
1275+
self._filepath = filepath
1276+
_log.info(
1277+
"EOmaps: Layout Editor activated! (press 'esc' to exit "
1278+
"and 'q' for info)"
1279+
)
12801280

1281-
self._history.clear()
1282-
self._history_undone.clear()
1283-
self._add_to_history()
1281+
self._history.clear()
1282+
self._history_undone.clear()
1283+
self._add_to_history()
12841284

1285-
# only re-draw if info-text is None
1286-
if getattr(self, "_info_text", None) is None:
1287-
self._info_text = self.add_info_text()
1285+
# only re-draw if info-text is None
1286+
if getattr(self, "_info_text", None) is None:
1287+
self._info_text = self.add_info_text()
12881288

1289-
self._apply_modifications()
1290-
self._attach_callbacks()
1289+
self._apply_modifications()
1290+
self._attach_callbacks()
12911291

1292-
self.m._emit_signal("layoutEditorActivated")
1293-
self.m.redraw()
1292+
self.m._emit_signal("layoutEditorActivated")
1293+
self.m.redraw()
12941294

12951295
def _add_revert_props(self, child, *args):
12961296
for prop in args:
@@ -1832,6 +1832,15 @@ def _do_on_layer_change(self, layer, new=False):
18321832
if layer in self._pending_webmaps:
18331833
self._pending_webmaps.pop(layer)
18341834

1835+
@contextmanager
1836+
def _cx_toggle_draw(self, val):
1837+
# a contextmanager to temporarily enable/disable calling on_draw
1838+
try:
1839+
self._disable_draw = val
1840+
yield
1841+
finally:
1842+
self._disable_draw = ~val
1843+
18351844
@contextmanager
18361845
def _without_artists(self, artists=None, layer=None):
18371846
try:

0 commit comments

Comments
 (0)