-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
fixes issue #2556 #2558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes issue #2556 #2558
Changes from 1 commit
1b81e9f
fcaf629
5e69629
c312cca
4cc466e
e0972f0
c07f674
f92ee59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
closes #2556
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,9 +220,9 @@ | |
|
||
class QuiverKey(martist.Artist): | ||
""" Labelled arrow for use as a quiver plot scale key.""" | ||
halign = {'N': 'center', 'S': 'center', 'E': 'left', 'W': 'right'} | ||
valign = {'N': 'bottom', 'S': 'top', 'E': 'center', 'W': 'center'} | ||
pivot = {'N': 'mid', 'S': 'mid', 'E': 'tip', 'W': 'tail'} | ||
halign = {'N': 'center', 'S': 'center', 'E': 'left', 'W': 'right'} | ||
valign = {'N': 'bottom', 'S': 'top', 'E': 'center', 'W': 'center'} | ||
pivot = {'N': 'mid', 'S': 'mid', 'E': 'tip', 'W': 'tail'} | ||
|
||
def __init__(self, Q, X, Y, U, label, **kw): | ||
martist.Artist.__init__(self) | ||
|
@@ -236,13 +236,21 @@ def __init__(self, Q, X, Y, U, label, **kw): | |
self._labelsep_inches = kw.pop('labelsep', 0.1) | ||
self.labelsep = (self._labelsep_inches * Q.ax.figure.dpi) | ||
|
||
# try to prevent closure over the real self | ||
weak_self = weakref.ref(self) | ||
|
||
def on_dpi_change(fig): | ||
self.labelsep = (self._labelsep_inches * fig.dpi) | ||
self._initialized = False # simple brute force update | ||
# works because _init is called | ||
# at the start of draw. | ||
_s = weak_self() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a fan of the variable name - how about |
||
if _s is not None: | ||
_s.labelsep = (_s._labelsep_inches * fig.dpi) | ||
_s._initialized = False # simple brute force update | ||
# works because _init is called | ||
# at the start of draw. | ||
|
||
self._cid = Q.ax.figure.callbacks.connect('dpi_changed', | ||
on_dpi_change) | ||
|
||
Q.ax.figure.callbacks.connect('dpi_changed', on_dpi_change) | ||
self._cb_ref = weakref.ref(Q.ax.figure.callbacks) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we already have a non-weak ref to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. had blinders on and missed that we had that ref to |
||
|
||
self.labelpos = kw.pop('labelpos', 'N') | ||
self.labelcolor = kw.pop('labelcolor', None) | ||
|
@@ -255,11 +263,24 @@ def on_dpi_change(fig): | |
horizontalalignment=self.halign[self.labelpos], | ||
verticalalignment=self.valign[self.labelpos], | ||
fontproperties=font_manager.FontProperties(**_fp)) | ||
|
||
if self.labelcolor is not None: | ||
self.text.set_color(self.labelcolor) | ||
self._initialized = False | ||
self.zorder = Q.zorder + 0.1 | ||
|
||
def remove(self): | ||
""" | ||
Overload the remove method | ||
""" | ||
_cbs = self._cb_ref() | ||
if _cbs is not None: | ||
# disconnect the call back | ||
_cbs.disconnect(self._cid) | ||
self._cid = None | ||
# pass the remove call up the stack | ||
martist.Artist.remove(self) | ||
|
||
__init__.__doc__ = _quiverkey_doc | ||
|
||
def _init(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This use of weak ref looks fine (and I can't think of an alternative way)