Debian Codegraph @

examples/simple_sample.py

raw symbols SCIP
1 """Simple sample showing basic usage pattern"""
2 from __future__ import print_function
3 from pydispatch import dispatcher
4
5 def doSomethingUseful( table, signal, sender ):
6 """Sample method to receive signals"""
7 print(' doSomethingUseful', repr(table), signal, sender)
8 def doSomethingElse( signal, **named ):
9 """Sample method to receive signals
10
11 This method demonstrates the use of the **named
12 parameter, which allows a method to receive all
13 remaining parameters from the send call.
14 """
15 print(' doSomethingElse', named)
16 def doDefault( ):
17 """Sample method to receive All signals
18
19 Note that this function will be registered for all
20 signals from a given object. It does not have the
21 same interface as any of the other functions
22 registered for those signals. The system will
23 automatically determine the appropriate calling
24 signature for the function.
25 """
26 print(' doDefault (no arguments)')
27
28 class Node(object):
29 """Sample object to send signals, note lack of dispatcher-aware code"""
30 def __init__( self, name="an object" ):
31 self.name = name
32 def __repr__( self ):
33 return "%s( %r )"%( self.__class__.__name__, self.name )
34
35 DO_LOTS = 0
36 DO_SOMETHING = ('THIS','IS','A','MORE','COMPLEX','SIGNAL')
37 DO_SOMETHING_ELSE = Node()
38
39 ourObjects = [
40 Node(),
41 Node(),
42 Node(),
43 ]
44 if __name__ == "__main__":
45 # Establish some "routing" connections
46 dispatcher.connect (
47 doSomethingUseful,
48 signal = DO_LOTS,
49 sender = ourObjects[0],
50 )
51 dispatcher.connect (
52 doSomethingElse,
53 signal = DO_SOMETHING,
54 sender = ourObjects[0],
55 )
56 dispatcher.connect(
57 doDefault,
58 signal = dispatcher.Any, # this is actually the default,
59 sender = ourObjects[0],
60 )
61 print("Sending DO_LOTS from first object")
62 dispatcher.send(
63 signal = DO_LOTS,
64 sender = ourObjects[0],
65 table = "Table Argument",
66 )
67 print("Sending DO_SOMETHING from first object")
68 dispatcher.send(
69 signal = DO_SOMETHING,
70 sender = ourObjects[0],
71 table = "Table Argument",
72 )
73 print("Sending DO_SOMETHING_ELSE from first object")
74 dispatcher.send(
75 signal = DO_SOMETHING_ELSE,
76 sender = ourObjects[0],
77 table = "Table Argument",
78 )