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

Source Code for Script script-demo_helloJoy_py

 1  from joy import * 
 2   
3 -class HelloJoyApp( JoyApp ):
4 """HelloJoyApp 5 6 The "hello world" of JoyApp programming. 7 This JoyApp pipes the y coordinate of mouse positions (while left 8 button is pressed) to a specified setter. By default this setter is 9 given by "#output " -- i.e. it is a debug message. 10 11 See JoyApp.setterOf() for a specification of possible outputs 12 """
13 - def __init__(self,spec,*arg,**kw):
14 # This is a "constructor". It initializes the JoyApp object. 15 # Because we added an additional parameter, we extend the 16 # JoyApp constructor. The first step is to call the superclass 17 # constructor so that we'll have a valid JoyApp instance. 18 JoyApp.__init__(self, *arg,**kw) 19 # Store output specifier for later use 20 self.spec = spec
21
22 - def onStart(self):
23 # This function is called when the JoyApp is ready to start up, 24 # i.e. after all PyGame devices have been activated, robot Cluster 25 # is populated, scratch interface is live, etc. 26 self.output = self.setterOf(self.spec)
27
28 - def onEvent(self,evt):
29 # All unknown events --> punt to superclass 30 if evt.type != MOUSEMOTION or evt.buttons[0] == 0: 31 return JoyApp.onEvent(self,evt) 32 # If we reach this line, it was a MOUSEMOTION with button pressed 33 # so we send the value out to the output 34 self.output( evt.pos[1] )
35 if __name__=="__main__": 36 app = HelloJoyApp("#output ") 37 app.run() 38