Version: 9.15.0
gui.CONNECTOR.CONNECTOR Class Reference

Public Member Functions

def __init__ (self)
 
def Connect (self, object, channel, function, args)
 
def Disconnect (self, object, channel, function, args)
 
def Emit (self, object, channel, *args)
 

Public Attributes

 connections
 

Detailed Description

Definition at line 46 of file CONNECTOR.py.

Constructor & Destructor Documentation

◆ __init__()

def gui.CONNECTOR.CONNECTOR.__init__ (   self)

Definition at line 48 of file CONNECTOR.py.

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

Member Function Documentation

◆ Connect()

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

Definition at line 51 of file CONNECTOR.py.

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

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

◆ Disconnect()

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

Definition at line 74 of file CONNECTOR.py.

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

References gui.CONNECTOR.CONNECTOR.connections.

◆ Emit()

def gui.CONNECTOR.CONNECTOR.Emit (   self,
  object,
  channel,
args 
)

Definition at line 100 of file CONNECTOR.py.

100  def Emit(self, object, channel, *args):
101 
102  try:
103  receivers = self.connections[id(object)][channel]
104  except KeyError:
105  return
106 
109  for rfunc, fargs in copy(receivers):
110  try:
111  func=rfunc()
112  if func:
113  func(*args + fargs)
114  else:
115  # Le receveur a disparu
116  if (rfunc,fargs) in receivers:receivers.remove((rfunc,fargs))
117  except:
118  traceback.print_exc()
119 

References gui.CONNECTOR.CONNECTOR.connections.

Member Data Documentation

◆ connections

gui.CONNECTOR.CONNECTOR.connections

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