Skip to content

Commit 1a9628e

Browse files
committed
Make the same callback connected to multiple event types work.
1 parent 6e87da3 commit 1a9628e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/matplotlib/cbook.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,17 @@ def connect(self, s, func):
251251
func will be called
252252
"""
253253
if func in self._func_cid_map:
254-
return self._func_cid_map[func]
255-
proxy = self.BoundMethodProxy(func)
256-
self._cid += 1
254+
cid = self._func_cid_map[func]
255+
else:
256+
self._cid += 1
257+
cid = self._cid
258+
self._func_cid_map[func] = cid
257259
self.callbacks.setdefault(s, dict())
258-
self.callbacks[s][self._cid] = proxy
259-
self._func_cid_map[func] = self._cid
260-
return self._cid
260+
if cid in self.callbacks[s]:
261+
return cid
262+
proxy = self.BoundMethodProxy(func)
263+
self.callbacks[s][cid] = proxy
264+
return cid
261265

262266
def disconnect(self, cid):
263267
"""
@@ -268,8 +272,6 @@ def disconnect(self, cid):
268272
del callbackd[cid]
269273
except KeyError:
270274
continue
271-
else:
272-
return
273275

274276
def process(self, s, *args, **kwargs):
275277
"""

0 commit comments

Comments
 (0)