Gnumed.timelinelib.db.observer

Package Gnumed :: Package timelinelib :: Package db :: Module observer |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.db.observer

     1  # Copyright (C) 2009, 2010, 2011  Rickard Lindberg, Roger Lindberg
     2  #
     3  # This file is part of Timeline.
     4  #
     5  # Timeline is free software: you can redistribute it and/or modify
     6  # it under the terms of the GNU General Public License as published by
     7  # the Free Software Foundation, either version 3 of the License, or
     8  # (at your option) any later version.
     9  #
    10  # Timeline is distributed in the hope that it will be useful,
    11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  # GNU General Public License for more details.
    14  #
    15  # You should have received a copy of the GNU General Public License
    16  # along with Timeline.  If not, see <http://www.gnu.org/licenses/>.
    17
    18
    19  # A category was added, edited, or deleted
    20  STATE_CHANGE_CATEGORY = 1
    21  # Something happened that changed the state of the timeline
    22  STATE_CHANGE_ANY = 2
    23
    24
    25 -class Observable(object):
    26
    27 -    def __init__(self):
    28          self.observers = []
    29
    30 -    def register(self, fn):
    31          self.observers.append(fn)
    32
    33 -    def unregister(self, fn):
    34          if fn in self.observers:
    35              self.observers.remove(fn)
    36
    37 -    def _notify(self, state_change):
    38          for fn in self.observers:
    39              fn(state_change)
    40