Package joy :: Module remote :: Class Source
[hide private]
[frames] | no frames]

Class Source

source code


Concrete class remote.Source

This Plan subclass may be used to relay JoyApp events (including all pygame events) to a remote.Sink running in another JoyApp via UDP. This allows a controller in one JoyApp to control a client in a remote JoyApp connected via an IP network, potentially running on another host altogether.

Events are serialized into a JSON string and sent over separate UDP packets. TIMEREVENTS are ignored.

Instance Methods [hide private]
 
__init__(self, app, dst=DEFAULT_SINK)
Attributes:...
source code
 
onStart(self)
(default)
source code
 
onStop(self)
(default)
source code
 
setSink(self, dst)
Set the sink address.
source code
 
sendMsg(self, **msg)
Send a dictionary to the remote sink; will appear in its misc message queue unless it has the key "type", in which case the sink will try to convert it to a JoyApp event.
source code
 
onEvent(self, evt)
(default) Event handler.
source code

Inherited from plans.Plan: behavior, forDuration, isRunning, push, start, step, stop, untilTime

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  DEFAULT_SINK = 'localhost', DEFAULT_PORT
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, app, dst=DEFAULT_SINK)
(Constructor)

source code 

Attributes:
  dst -- 2-tuple -- destination address for packets, in socket library format
  sock -- socket / None -- socket only exists while plan is running 

Overrides: object.__init__

onStart(self)

source code 

(default)

Override this method to perform operations when Plan starts but before the first events are processed.

Overrides: plans.Plan.onStart
(inherited documentation)

onStop(self)

source code 

(default)

Override this method to perform operations when Plan terminates.

Overrides: plans.Plan.onStop
(inherited documentation)

setSink(self, dst)

source code 

Set the sink address. Will take effect immediately

sendMsg(self, **msg)

source code 

Send a dictionary to the remote sink; will appear in its 
misc message queue unless it has the key "type", in which
case the sink will try to convert it to a JoyApp event.

WARNING: if you use "type" inappropriately, the sink
  will error out and stop running

onEvent(self, evt)

source code 
(default)
Event handler. Override this method to handle all events that 
were push()-ed to this Plan.

The sequential behavior() in this plan only runs if onEvent
returned True.

All Plan-s recieve a copy of all TIMEREVENT events. If your
sequential code does not need any other events, and just wants
to execute in parallel with other Plan-s, it is safe to leave
the default onEvent method, which always returns True 

NOTE: 
  onEvent MUST return True or False. Other values raise an 
  exception at runtime. 

Overrides: plans.Plan.onEvent
(inherited documentation)