10000 added enthought traits · matplotlib/matplotlib@456f33b · GitHub
[go: up one dir, main page]

Skip to content

Commit 456f33b

Browse files
committed
added enthought traits
svn path=/trunk/matplotlib/; revision=975
1 parent 9522444 commit 456f33b

18 files changed

+9774
-6
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
New entries should be added at the top
22

3+
2005-02-14 Added enthought traits to matplotlib tree - JDH
4+
5+
===========================================================
6+
37
2005-02-14 0.72 released
48

59
2005-02-14 fix bug in cbook alltrue() and onetrue() - SC

lib/matplotlib/cbook.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,10 @@ def __get_item__(self, i):
273273

274274

275275

276-
277-
# until 2.3
276+
major, minor1, minor2, s, tmp = sys.version_info
278277
def enumerate(seq):
279-
for i in range(len(seq)):
280-
yield i, seq[i]
278+
for i in range(len(seq)):
279+
yield i, seq[i]
281280

282281

283282

lib/matplotlib/enthought/__init__.py

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#-------------------------------------------------------------------------------
2+
#
3+
# Define a 'traits' package that allows other classes to easily define
4+
# 'type-checked' and/or 'delegated' traits for their instances.
5+
#
6+
# Note: A 'trait' is similar to a 'property', but is used instead of the
7+
# word 'property' to differentiate it from the Python language 'property'
8+
# feature.
9+
#
10+
# Written by: David C. Morrill
11+
#
12+
# Date: 06/21/2002
13+
#
14+
# (c) Copyright 2002 by Enthought, Inc.
15+
#
16+
#-------------------------------------------------------------------------------
17+
18+
from info_traits import __doc__
19+
from trait_base import Undefined, Missing, Self
20+
from trait_errors import TraitError, DelegationError
21+
from category import Category
22+
from trait_db import tdb
23+
from traits import Event, TraitEvent, List, Dict, Tuple, Range, \
24+
Constant, CTrait, Trait, TraitPython, Delegate, Property, TraitProperty
25+
from traits import Any, AnyValue, Int, Long, Float, Str, Unicode, Complex, \
26+
Bool, CInt, CLong, CFloat, CStr, CUnicode, CComplex, CBool, false, true, \
27+
Regex, String, Password, File, Directory, Function, Method, Class
28+
from traits import Instance, Module, Type, This, self, Python, Disallow, \
29+
ReadOnly, undefined, missing, ListInt, ListFloat, ListStr, ListUnicode, \
30+
ListComplex, ListBool, ListFunction, ListMethod, ListClass, ListInstance
31+
from traits import ListThis, DictStrAny, DictStrStr, DictStrInt, DictStrLong, \
32+
DictStrFloat, DictStrBool, DictStrList, TraitFactory, Callable, Array, \
33+
CArray, Enum, Code, Default
34+
from traits import Color, RGBColor, RGBAColor, Font, KivaFont
35+
from has_traits import method, HasTraits, HasStrictTraits, HasPrivateTraits
36+
from trait_handlers import TraitHandler, TraitRange, TraitString, TraitType, \
37+
TraitCastType, TraitInstance, ThisClass, TraitClass, TraitFunction
38+
from trait_handlers import TraitEnum, TraitPrefixList, TraitMap, \
39+
TraitPrefixMap, TraitCompound, TraitList, TraitDict
40+
41+
#-------------------------------------------------------------------------------
42+
# Deprecated values:
43+
#-------------------------------------------------------------------------------
44+
45+
from traits import TraitEvent, TraitDelegate, TraitDelegateSynched, \
46+
DefaultPythonTrait
47+
from has_traits import HasDynamicTraits
48+
from trait_handlers import TraitComplex
49+
50+
51+
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#-------------------------------------------------------------------------------
2+
#
3+
# Adds a Cocoa-like 'category' capability to Traits-base classes.
4+
#
5+
# Written by: David C. Morrill
6+
#
7+
# Date: 11/06/2004
8+
#
9+
# (c) Copyright 2002, 2004 by Enthought, Inc.
10+
#
11+
#-------------------------------------------------------------------------------
12+
13+
#-------------------------------------------------------------------------------
14+
# Imports:
15+
#-------------------------------------------------------------------------------
16+
17+
from has_traits import MetaHasTraits, MetaHasTraitsObject, BaseTraits, \
18+
ClassTraits, PrefixTraits, ViewTraits
19+
20+
#-------------------------------------------------------------------------------
21+
# 'MetaCategory' class:
22+
#-------------------------------------------------------------------------------
23+
24+
class MetaCategory ( MetaHasTraits ):
25+
26+
def __new__ ( cls, class_name, bases, class_dict ):
27+
28+
# Make sure the correct usage is being applied:
29+
if len( bases ) > 2:
30+
raise TypeError, \
31+
"Correct usage is: class FooCategory(Category,Foo):"
32+
33+
# Process any traits-related information in the class dictionary:
34+
MetaCategoryObject( cls, class_name, bases, class_dict, True )
35+
36+
# Move all remaining items in our class dictionary to the base class's
37+
# dictionary:
38+
if len( bases ) == 2:
39+
category_class = bases[1]
40+
for name, value in class_dict.items():
41+
if name != '__module__':
42+
setattr( category_class, name, value )
43+
del class_dict[ name ]
44+
45+
# Finish building the class using the updated class dictionary:
46+
return type.__new__( cls, class_name, bases, class_dict )
47+
48+
#-------------------------------------------------------------------------------
49+
# 'MetaCategoryObject' class:
50+
#-------------------------------------------------------------------------------
51+
52+
class MetaCategoryObject ( MetaHasTraitsObject ):
53+
54+
#---------------------------------------------------------------------------
55+
# Adds the traits meta-data to the class:
56+
#---------------------------------------------------------------------------
57+
58+
def add_traits_meta_data ( self, bases, class_dict, base_traits,
59+
class_traits, prefix_traits, view_elements ):
60+
if len( bases ) == 2:
61+
category_class = bases[1]
62+
63+
# Update the base class's traits with the new ones:
64+
if len( base_traits ) > 0:
65+
getattr( category_class, BaseTraits ).update( base_traits )
66+
if len( class_traits ) > 0:
67+
getattr( category_class, ClassTraits ).update( class_traits )
68+
if len( prefix_traits ) > 0:
69+
getattr( category_class, PrefixTraits ).update( prefix_traits )
70+
71+
# Copy all our view elements into the base class's ViewElements:
72+
if view_elements is not None:
73+
content = view_elements.content
74+
if len( content ) > 0:
75+
base_ve = getattr( category_class, ViewTraits, None )
76+
if base_ve is None:
77+
setattr( category_class, ViewTraits, view_elements )
78+
else:
79+
base_ve.content.update( content )
80+
81+
# Update each of the existing subclasses as well:
82+
for subclass in category_class.trait_subclasses( True ):
83+
84+
subclass_traits = getattr( subclass, BaseTraits )
85+
for name, value in base_traits.items():
86+
subclass_traits.setdefault( name, value )
87+
88+
subclass_traits = getattr( subclass, ClassTraits )
89+
for name, value in class_traits.items():
90+
subclass_traits.setdefault( name, value )
91+
92+
subclass_traits = getattr( subclass, PrefixTraits )
93+
subclass_list = subclass_traits['*']
94+
changed = False
95+
for name, value in prefix_traits.items():
96+
if name not in subclass_traits:
97+
subclass_traits[ name ] = value
98+
subclass_list.append( name )
99+
changed = True
100+
# Resort the list from longest to shortest (if necessary):
101+
if changed:
102+
subclass_list.sort( lambda x, y: len( y ) - len( x ) )
103+
else:
104+
MetaHasTraitsObject.add_traits_meta_data( self, bases,
105+
class_dict, base_traits, class_traits, prefix_traits,
106+
view_elements )
107+
108+
#-------------------------------------------------------------------------------
109+
# 'Category' class:
110+
#-------------------------------------------------------------------------------
111+
112+
class Category ( object ):
113+
114+
__metaclass__ = MetaCategory
115+

0 commit comments

Comments
 (0)
0