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

Source Code for Script script-demo_remoteSource_py

 1  from joy import * 
 2  from joy.remote import Source as RemoteSource 
 3   
4 -class RemoteSourceApp( JoyApp ):
5 - def __init__(self,*arg,**kw):
6 self.dst = kw.get('sink',RemoteSource.DEFAULT_SINK) 7 if kw.has_key('sink'): 8 del kw['sink'] 9 JoyApp.__init__(self,*arg,**kw)
10
11 - def onStart( self ):
12 self.rs = RemoteSource(self, self.dst) 13 self.rs.start()
14
15 - def onEvent( self, evt ):
16 if evt.type in set([KEYDOWN,KEYUP,JOYAXISMOTION]): 17 # Process keydown events so that 'q' key will work 18 if evt.type == KEYDOWN: 19 JoyApp.onEvent(self,evt) 20 self.rs.push( evt ) 21 return 22 elif evt.type == MOUSEMOTION: 23 return 24 JoyApp.onEvent(self,evt)
25 26 if __name__=="__main__": 27 print """ 28 Demonstration of RemoteSource plan 29 ------------------------------------ 30 31 Sends keyboard events to a remote JoyApp, specified on the commandline as two parameters: host port 32 33 """ 34 import sys 35 from joy.remote import DEFAULT_PORT 36 if len(sys.argv)>1: 37 if len(sys.argv)>2: 38 port = int(sys.argv[2]) 39 else: 40 port = DEFAULT_PORT 41 progress("**** Using default port "+str(DEFAULT_PORT)) 42 app = RemoteSourceApp(sink=(sys.argv[1],port)) 43 else: 44 app = RemoteSourceApp() 45 app.run() 46