Example #1
0
 def changed(context):
     logger.debug("Context %s changed" % context)
     # TODO: wrap in try/except
     if context.evaluateRules():
         if context not in current_contexts:
             current_contexts.add(context)
             notify.enter(context)
             context.runEnteringActions()
     else:
         if context in current_contexts:
             current_contexts.remove(context)
             notify.leave(context)
             context.runLeavingActions()
Example #2
0
def reevaluate():
    old_contexts = current_contexts.copy()
    current_contexts.clear()
    for c in contexts.itervalues():
        if c.evaluateRules():
            current_contexts.add(c)
    
    # Run leave before enter
    for c in old_contexts.difference(current_contexts):
        notify.leave(c)
        c.runLeavingActions()
    for c in current_contexts.difference(old_contexts):
        notify.enter(c)
        c.runEnteringActions()