8000 Mpl traitlets by tacaswell · Pull Request #4694 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Mpl traitlets #4694

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update mpl traitlets
  • Loading branch information
rmorshea committed Jul 12, 2015
commit 19a9ca218ebb0e534d27bfdc603424e2a65e494f
29 changes: 21 additions & 8 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
TransformedPath, Transform)
from .path import Path

import .mpl_traitlets as mpltr
import .traitlets as mpltr

# Note, matplotlib artists use the doc strings for set and get
# methods to enable the introspection methods of setp and getp. Every
Expand Down Expand Up @@ -105,6 +105,7 @@ class Artist(mpltr.Configurable):
visible = Bool(True, perishable=True)
animated = Bool(False, perishable=True)
alpha = Float(allow_none=True, perishable=True)
pickable = Bool(False)
# clipbox = Instance(matplotlib.transforms.Bbox)
# clippath = Union([matplotlib.patches.Patch,
# matplotlib.path.Path],
Expand All @@ -129,7 +130,8 @@ class Artist(mpltr.Configurable):
def __init__(self, *args, **kwargs):
super(Artist,self).__init__(*args, **kwargs)
pnames = self.trait_names(self._fire_callbacks, perishable=True)

self.on_trait_change(self._fire_callbacks, pnames)
self.on_trait_change(self._update_pickable, ('picker', 'figure'))
self._axes = None

self._visible = True
Expand Down Expand Up @@ -166,6 +168,16 @@ def __getstate__(self):
d['_remove_method'] = None
return d

def _update_pickable(self, name, new):
pickable = self.pickable
if name == 'figure':
if new is None or new.canvas is None:
pickable = False
elif name == 'picker':
if new is None:
packable = False
self.pickable = pickable

# can be superseded by on_trait_change or _%_changed methods
def _fire_callbacks(self):
"""Calls all of the registered callbacks."""
Expand Down Expand Up @@ -203,9 +215,9 @@ def remove_callback(self, oid):
except KeyError:
pass

# - - - - - - - -
# change handlers
# - - - - - - - -
# - - - - - - - -
# change handlers
# - - - - - - - -

def _transform_changed(self, name, new):
self._transformSet = True
Expand Down Expand Up @@ -265,7 +277,7 @@ def get_axes(self):
warnings.warn(_get_axes_msg, mplDeprecation, stacklevel=1)
return self.axes

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

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

def _figure_changed(self, name, old, new):
self.figure = new
if old and old is not self:
self.add_callback(_stale_figure_callback)
self.pchanged()
self.stale = True

def get_figure(self):
Expand Down Expand Up @@ -363,10 +373,12 @@ def set_picker(self, picker):

ACCEPTS: [None|float|boolean|callable]
"""
# add warn
self._picker = picker

def get_picker(self):
'Return the picker object used by this artist'
# add warn
return self._picker

# - - - - - - - -
Expand Down Expand Up @@ -478,6 +490,7 @@ def get_children(self):

def pickable(self):
'Return *True* if :class:`Artist` is pickable.'
return self.pickable
return (self.figure is not None and
self.figure.canvas is not None and
self._picker is not None)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_traitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def setUp(self):
self.transparent_values = [None, False, '', 'none']
self.black_values = ['#000000', (0,0,0,0), 0, 0.0, (.0,.0,.0), (.0,.0,.0,.0)]
self.colored_values = ['#BE3537', (190,53,55), (0.7451, 0.20784, 0.21569)]
self.unvalid_values = ['áfaef', '#FFF', '#0SX#$S', (0,0,0), (0.45,0.3), (()), {}, True]
self.invalid_values = ['áfaef', '#FFF', '#0SX#$S', (0,0,0), (0.45,0.3), (()), {}, True]

def _evaluate_unvalids(self, a):
for values in self.unvalid_values:
for values in self.invalid_values:
try:
a.color = values
except:
Expand Down
38 changes: 15 additions & 23 deletions lib/matplotlib/mpl_traitlets.py → lib/matplotlib/traitlets.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
from __future__ import (absolute_import, division,
print_function, unicode_literals)

#from traitlets.config import Configurable
#from traitlets import (Int, Float, Bool, Dict, List, Instance,
# Union, TraitError, HasTraits,
# NoDefaultSpecified, TraitType)

from IPython.config import Configurable
from IPython.utils.traitlets import (Int, Float, Bool, Dict, List, Instance,
Union, TraitError, HasTraits,
NoDefaultSpecified, TraitType)
#ipython 4 import
from traitlets.config import Configurable
from traitlets import (Int, Float, Bool, Dict, List, Instance,
Union, TraitError, HasTraits,
NoDefaultSpecified, TraitType)

# ipython 3 imports
# from IPython.config import Configurable
# from IPython.utils.traitlets import (Int, Float, Bool, Dict, List, Instance,
# Union, TraitError, HasTraits,
# NoDefaultSpecified, TraitType)
import numpy as np

# override for backward compatability
class Configurable(Configurable): pass

class TraitType(TraitType): pass

# overload handle may not be temporary
class OverloadMixin(object):

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

class String(TraitType):
"""A string trait"""

info_text = 'a string'

def validate(self, obj, value):
if isinstance(value, str):
return value
self.error(obj, value)

class oInstance(OverloadMixin,Instance): pass

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

class oInstance(OverloadMixin,Instance): pass

class Color(TraitType):
"""A trait representing a color, can be either in RGB, or RGBA format.

Expand Down Expand Up @@ -88,7 +80,7 @@ class Color(TraitType):
'as_hex' : False,
'default_alpha' : 0.0,
}
allow_none = False
allow_none = True
info_text = 'float, int, tuple of float or int, or a hex string color'
default_value = (0.0,0.0,0.0,0.0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is transparent; perhaps you mean to set alpha to 1, not 0.

named_colors = {}
Expand Down
0