Version: 8.3.0
gui.CONNECTOR.CONNECTOR Class Reference

Public Member Functions

def __init__
 
def Connect
 
def Disconnect
 
def Emit
 

Public Attributes

 connections
 

Detailed Description

Definition at line 46 of file CONNECTOR.py.

Constructor & Destructor Documentation

def gui.CONNECTOR.CONNECTOR.__init__ (   self)

Definition at line 48 of file CONNECTOR.py.

48 
49  def __init__(self):
50  self.connections={}

Member Function Documentation

def gui.CONNECTOR.CONNECTOR.Connect (   self,
  object,
  channel,
  function,
  args 
)

Definition at line 51 of file CONNECTOR.py.

References gui.CONNECTOR.CONNECTOR.connections, and gui.CONNECTOR.ref().

51 
52  def Connect(self, object, channel, function, args):
53  ###print "Connect",object, channel, function, args
54  idx = id(object)
55  if self.connections.has_key(idx):
56  channels = self.connections[idx]
57  else:
58  channels = self.connections[idx] = {}
59 
60  if channels.has_key(channel):
61  receivers = channels[channel]
62  else:
63  receivers = channels[channel] = []
64 
65  for funct,fargs in receivers[:]:
66  if funct() is None:
67  receivers.remove((funct,fargs))
68  elif (function,args) == (funct(),fargs):
69  receivers.remove((funct,fargs))
70 
71  receivers.append((ref(function),args))
72  ###print "Connect",receivers
73 
def gui.CONNECTOR.CONNECTOR.Disconnect (   self,
  object,
  channel,
  function,
  args 
)

Definition at line 74 of file CONNECTOR.py.

References gui.CONNECTOR.CONNECTOR.connections.

74 
75  def Disconnect(self, object, channel, function, args):
76  try:
77  receivers = self.connections[id(object)][channel]
78  except KeyError:
79  raise ConnectorError, \
80  'no receivers for channel %s of %s' % (channel, object)
81 
82  for funct,fargs in receivers[:]:
83  if funct() is None:
84  receivers.remove((funct,fargs))
85 
86  for funct,fargs in receivers:
87  if (function,args) == (funct(),fargs):
88  receivers.remove((funct,fargs))
89  if not receivers:
90  # the list of receivers is empty now, remove the channel
91  channels = self.connections[id(object)]
92  del channels[channel]
93  if not channels:
94  # the object has no more channels
95  del self.connections[id(object)]
96  return
97 
98  raise ConnectorError,\
99  'receiver %s%s is not connected to channel %s of %s' \
100  % (function, args, channel, object)
101 
def gui.CONNECTOR.CONNECTOR.Emit (   self,
  object,
  channel,
  args 
)

Definition at line 102 of file CONNECTOR.py.

References gui.CONNECTOR.CONNECTOR.connections.

103  def Emit(self, object, channel, *args):
104  ###print "Emit",object, channel, args
105  try:
106  receivers = self.connections[id(object)][channel]
107  except KeyError:
108  return
109  ###print "Emit",object, channel, receivers
110  # Attention : copie pour eviter les pbs lies aux deconnexion reconnexion
111  # pendant l'execution des emit
112  for rfunc, fargs in copy(receivers):
113  try:
114  func=rfunc()
115  if func:
116  apply(func, args + fargs)
117  else:
118  # Le receveur a disparu
119  if (rfunc,fargs) in receivers:receivers.remove((rfunc,fargs))
120  except:
121  traceback.print_exc()

Member Data Documentation

gui.CONNECTOR.CONNECTOR.connections

Definition at line 49 of file CONNECTOR.py.

Referenced by gui.CONNECTOR.CONNECTOR.Connect(), gui.CONNECTOR.CONNECTOR.Disconnect(), and gui.CONNECTOR.CONNECTOR.Emit().


The documentation for this class was generated from the following file: