Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd7d7c3

Browse files
committed
update mpl traitlets
1 parent d402469 commit fd7d7c3

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

lib/matplotlib/artist.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
TransformedPath, Transform)
1616
from .path import Path
1717

18-
import .mpl_traitlets as mpltr
18+
import .traitlets as mpltr
1919

2020
# Note, matplotlib artists use the doc strings for set and get
2121
# methods to enable the introspection methods of setp and getp. Every
@@ -105,6 +105,7 @@ class Artist(mpltr.Configurable):
105105
visible = Bool(True, perishable=True)
106106
animated = Bool(False, perishable=True)
107107
alpha = Float(allow_none=True, perishable=True)
108+
pickable = Bool(False)
108109
# clipbox = Instance(matplotlib.transforms.Bbox)
109110
# clippath = Union([matplotlib.patches.Patch,
110111
# matplotlib.path.Path],
@@ -129,7 +130,8 @@ class Artist(mpltr.Configurable):
129130
def __init__(self, *args, **kwargs):
130131
super(Artist,self).__init__(*args, **kwargs)
131132
pnames = self.trait_names(self._fire_callbacks, perishable=True)
132-
133+
self.on_trait_change(self._fire_callbacks, pnames)
134+
self.on_trait_change(self._update_pickable, ('picker', 'figure'))
133135
self._axes = None
134136

135137
self._visible = True
@@ -166,6 +168,16 @@ def __getstate__(self):
166168
d['_remove_method'] = None
167169
return d
168170

171+
def _update_pickable(self, name, new):
172+
pickable = self.pickable
173+
if name == 'figure':
174+
if new is None or new.canvas is None:
175+
pickable = False
176+
elif name == 'picker':
177+
if new is None:
178+
packable = False
179+
self.pickable = pickable
180+
169181
# can be superseded by on_trait_change or _%_changed methods
170182
def _fire_callbacks(self):
171183
"""Calls all of the registered callbacks."""
@@ -203,9 +215,9 @@ def remove_callback(self, oid):
203215
except KeyError:
204216
pass
205217

206-
# - - - - - - - -
207-
# change handlers
208-
# - - - - - - - -
218+
# - - - - - - - -
219+
# change handlers
220+
# - - - - - - - -
209221

210222
def _transform_changed(self, name, new):
211223
self._transformSet = True
@@ -265,7 +277,7 @@ def get_axes(self):
265277
warnings.warn(_get_axes_msg, mplDeprecation, stacklevel=1)
266278
return self.axes
267279

268-
# only present to maintain current api.
280+
# required until new api : `obj.contains(obj, mouseevent)`
269281
def _contains_changed(self, name, new):
270282
self._trait_values[name] = types.MethodType(new,self)
271283

@@ -276,10 +288,8 @@ def contains_defualt(*args, **kwargs):
276288
return contains_default
277289

278290
def _figure_changed(self, name, old, new):
279-
self.figure = new
280291
if old and old is not self:
281292
self.add_callback(_stale_figure_callback)
282-
self.pchanged()
283293
self.stale = True
284294

285295
def get_figure(self):
@@ -363,10 +373,12 @@ def set_picker(self, picker):
363373
364374
ACCEPTS: [None|float|boolean|callable]
365375
"""
376+
# add warn
366377
self._picker = picker
367378

368379
def get_picker(self):
369380
'Return the picker object used by this artist'
381+
# add warn
370382
return self._picker
371383

372384
# - - - - - - - -
@@ -478,6 +490,7 @@ def get_children(self):
478490

479491
def pickable(self):
480492
'Return *True* if :class:`Artist` is pickable.'
493+
return self.pickable
481494
return (self.figure is not None and
482495
self.figure.canvas is not None and
483496
self._picker is not None)

lib/matplotlib/tests/test_traitlets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ def setUp(self):
1111
self.transparent_values = [None, False, '', 'none']
1212
self.black_values = ['#000000', (0,0,0,0), 0, 0.0, (.0,.0,.0), (.0,.0,.0,.0)]
1313
self.colored_values = ['#BE3537', (190,53,55), (0.7451, 0.20784, 0.21569)]
14-
self.unvalid_values = ['áfaef', '#FFF', '#0SX#$S', (0,0,0), (0.45,0.3), (()), {}, True]
14+
self.invalid_values = ['áfaef', '#FFF', '#0SX#$S', (0,0,0), (0.45,0.3), (()), {}, True]
1515

1616
def _evaluate_unvalids(self, a):
17-
for values in self.unvalid_values:
17+
for values in self.invalid_values:
1818
try:
1919
a.color = values
2020
except:

lib/matplotlib/mpl_traitlets.py renamed to lib/matplotlib/traitlets.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
from __future__ import (absolute_import, division,
22
print_function, unicode_literals)
33

4-
#from traitlets.config import Configurable
5-
#from traitlets import (Int, Float, Bool, Dict, List, Instance,
6-
# Union, TraitError, HasTraits,
7-
# NoDefaultSpecified, TraitType)
8-
9-
from IPython.config import Configurable
10-
from IPython.utils.traitlets import (Int, Float, Bool, Dict, List, Instance,
11-
Union, TraitError, HasTraits,
12-
NoDefaultSpecified, TraitType)
4+
#ipython 4 import
5+
from traitlets.config import Configurable
6+
from traitlets import (Int, Float, Bool, Dict, List, Instance,
7+
Union, TraitError, HasTraits,
8+
NoDefaultSpecified, TraitType)
9+
10+
# ipython 3 imports
11+
# from IPython.config import Configurable
12+
# from IPython.utils.traitlets import (Int, Float, Bool, Dict, List, Instance,
13+
# Union, TraitError, HasTraits,
14+
# NoDefaultSpecified, TraitType)
1315
import numpy as np
1416

17+
# override for backward compatability
1518
class Configurable(Configurable): pass
16-
1719
class TraitType(TraitType): pass
1820

21+
# overload handle may not be temporary
1922
class OverloadMixin(object):
2023

2124
def validate(self, obj, value):
@@ -32,16 +35,7 @@ def info(self):
3235
i = super(OverloadMixin,self).info()
3336
return 'overload resolvable, ' + i
3437

35-
class String(TraitType):
36-
"""A string trait"""
37-
38-
info_text = 'a string'
39-
40-
def validate(self, obj, value):
41-
if isinstance(value, str):
42-
return value
43-
self.error(obj, value)
44-
38+
class oInstance(OverloadMixin,Instance): pass
4539

4640
class Callable(TraitType):
4741
"""A trait which is callable.
@@ -59,8 +53,6 @@ def validate(self, obj, value):
5953
else:
6054
self.error(obj, value)
6155

62-
class oInstance(OverloadMixin,Instance): pass
63-
6456
class Color(TraitType):
6557
"""A trait representing a color, can be either in RGB, or RGBA format.
6658
@@ -88,7 +80,7 @@ class Color(TraitType):
8880
'as_hex' : False,
8981
'default_alpha' : 0.0,
9082
}
91-
allow_none = False
83+
allow_none = True
9284
info_text = 'float, int, tuple of float or int, or a hex string color'
9385
default_value = (0.0,0.0,0.0,0.0)
9486
named_colors = {}

0 commit comments

Comments
 (0)