Script demo_remoteSink_py
[hide private]
[frames] | no frames]

Source Code for Script script-demo_remoteSink_py

 1  from joy import JoyApp 
 2  from joy.decl import * 
 3  from joy.remote import Sink as RemoteSink 
 4   
5 -class RemoteSinkApp( JoyApp ):
6 - def __init__(self,*arg,**kw):
7 JoyApp.__init__(self,*arg,**kw)
8
9 - def onStart( self ):
10 self.rs = RemoteSink(self) 11 self.rs.setAllowMisc(True) 12 self.rs.start() # in case of running with no pygame 13 self.showMisc = self.onceEvery(1)
14
15 - def onEvent( self, evt ):
16 if self.showMisc(): 17 if self.rs.queue: 18 progress("Queue has %d messages:" % len(self.rs.queue)) 19 for n,msg in enumerate(self.rs.queue): 20 progress('[%0d] %s' % (n,msg)) 21 if evt.type == ACTIVEEVENT: 22 if evt.gain==1 and self.rs.isRunning(): 23 progress("(say) ignoring remote events") 24 self.rs.stop() 25 return 26 elif evt.gain==0 and not self.rs.isRunning(): 27 progress("(say) allowing remote events") 28 self.rs.start() 29 return 30 elif evt.type==MOUSEMOTION: 31 # suppressed for output readability 32 return 33 JoyApp.onEvent(self,evt)
34 35 if __name__=="__main__": 36 print """ 37 Demonstration of RemoteSink plan 38 ------------------------------------ 39 40 Receives keyboard events from remote JoyApp(s) using RemoteSource 41 42 Use in combination with the RemoteSource demo 43 44 Remote events are suppressed while the mouse is over the window 45 """ 46 app = RemoteSinkApp() 47 app.run() 48