Skip to content

Commit

Permalink
Support 'priority' in on_trait_change decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
johntyree committed Oct 8, 2014
1 parent a6e0818 commit 6aedf92
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions traits/has_traits.py
Expand Up @@ -831,7 +831,8 @@ def _trait_monitor_index ( cls, handler ):
# 'HasTraits' decorators:
#-------------------------------------------------------------------------------

def on_trait_change ( name, post_init = False, dispatch='same' ):
def on_trait_change ( name, post_init = False, dispatch = 'same',
priority = False ):
""" Marks the following method definition as being a handler for the
extended trait change specified by *name(s)*.
Expand All @@ -850,7 +851,8 @@ def decorator ( function ):

function.on_trait_change = {'pattern': name,
'post_init': post_init,
'dispatch': dispatch}
'dispatch': dispatch,
'priority': priority}

return function

Expand Down Expand Up @@ -3275,7 +3277,8 @@ def _post_init_trait_listeners ( self ):
self.on_trait_change( getattr( self, name ),
config['pattern'],
deferred = True,
dispatch=config['dispatch'] )
dispatch=config['dispatch'],
priority=config['priority'])

def _init_trait_listeners ( self ):
""" Initializes the object's statically parsed, but dynamically
Expand All @@ -3293,7 +3296,8 @@ def _init_trait_method_listener ( self, name, kind, config ):
if not config['post_init']:
self.on_trait_change( getattr( self, name ), config['pattern'],
deferred = True,
dispatch=config['dispatch'] )
dispatch=config['dispatch'],
priority=config['priority'])

def _init_trait_event_listener ( self, name, kind, pattern ):
""" Sets up the listener for an event with on_trait_change metadata.
Expand Down

0 comments on commit 6aedf92

Please sign in to comment.