This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
laydi/fluents/main.py
einarr a45743c31e Added main.py that now contains the One & Only Singleton instance of these classes:
- Navigator
 - Aplication
 - Workflow
 - Project
 - Options
Corresponding changes have been added in lots of other files to account for this, but
the access to these objects should now be a lot easier.
2007-07-26 12:35:59 +00:00

91 lines
2.0 KiB
Python

import sys
#: Dictionary of observers
_observers = {}
#: The current Navigator object.
navigator = None
#: The current application
application = None
#: The current project
project = None
#: The current workflow
workflow = None
#: A cfgparse/optparse options object.
options = None
def notify_observers(name):
call = "%s_changed" % name
for s in _observers.get(name, []):
getattr(s, call)(getattr(sys.modules[__name__], name))
def _add_observer(name, observer):
"""Adds observer as an observer of the named object."""
if not _observers.has_key(name):
_observers[name] = []
_observers[name].append(observer)
def _remove_observer(name, observer):
"""Removes observer as an observer of the named object."""
if not _observers.has_key(name):
return
_observers.remove(observer)
def add_navigator_observer(observer):
_add_observer('navigator', observer)
def add_project_observer(observer):
_add_observer('project', observer)
def add_workflow_observer(observer):
_add_observer('workflow', observer)
def add_application_observer(observer):
_add_observer('application', observer)
def remove_navigator_observer(observer):
_remove_observer('navigator', observer)
def remove_project_observer(observer):
_remove_observer('project', observer)
def remove_workflow_observer(observer):
_remove_observer('workflow', observer)
def remove_application_observer(observer):
_remove_observer('application', observer)
def remove_options_observer(observer):
_remove_observer('options', observer)
def set_navigator(nav):
global navigator
navigator = nav
notify_observers('navigator')
def set_application(app):
global application
application = app
notify_observers('application')
def set_project(p):
global project
project = p
notify_observers('project')
def set_workflow(wf):
global workflow
workflow = wf
notify_observers('workflow')
def set_options(opt):
global options
options = opt
notify_observers('options')