home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / util / lego / lattice / frame / __init__.pyo (.txt)
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  2.9 KB  |  66 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import protocols
  5. from peak.events import trellis
  6. from blocks import IBindableValue
  7. from blocks import IValueListener
  8.  
  9. class BindingValueListener(protocols.Adapter, trellis.Component):
  10.     protocols.advise(asAdapterForProtocols = [
  11.         IBindableValue], instancesProvide = [
  12.         IValueListener])
  13.     
  14.     def __init__(self, subject):
  15.         protocols.Adapter.__init__(self, subject)
  16.         trellis.Component.__init__(self)
  17.         self.subject.bind(self.value_changed)
  18.  
  19.     
  20.     def value_changed(self):
  21.         self.value = self.get_value()
  22.  
  23.     
  24.     def get_value(self):
  25.         return self.subject.value
  26.  
  27.     value = trellis.make(rule = get_value, writable = True, optional = True, name = 'value')
  28.  
  29.  
  30. class ObservableChangeBindable(trellis.Component):
  31.     
  32.     def __init__(self, model, *attrs):
  33.         self.model = model
  34.         self.attrs = attrs
  35.  
  36.     
  37.     def bind(self, func):
  38.         self.func = func
  39.         self.model.add_gui_observer(self.on_change, *self.attrs)
  40.  
  41.     
  42.     def unbind(self):
  43.         self.model.remove_gui_observer(self.on_change, *self.attrs)
  44.         del self.func
  45.  
  46.     
  47.     def on_change(self, *a, **k):
  48.         self.func()
  49.  
  50.  
  51.  
  52. class ObservableAttrBindable(ObservableChangeBindable):
  53.     protocols.advise(instancesProvide = [
  54.         IBindableValue])
  55.     
  56.     def __init__(self, model, attr):
  57.         super(ObservableAttrBindable, self).__init__(model, attr)
  58.         self.attr = attr
  59.  
  60.     
  61.     def value(self):
  62.         return getattr(self.model, self.attr, False)
  63.  
  64.     value = property(value)
  65.  
  66.