home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Languages / python / PyObjC-0.47-MIHS / pyobjc-0.47-src / Demo / ObjC / Fred / Fred.py next >
Encoding:
Python Source  |  1996-10-02  |  3.3 KB  |  152 lines

  1. #!/usr/local/bin/python
  2. #
  3. # Copyright (c) 1996 by Lele Gaifax.  All Rights Reserved
  4. #
  5. # This file is part of Nothing (yet).
  6. #
  7. # $RCSfile: Fred.py,v $
  8. # $Revision: 1.1.1.1 $
  9. # $Date: 1996/10/02 21:37:06 $
  10. #
  11. # Created Wed Oct  2 01:49:55 1996.
  12. #
  13.  
  14. import ObjC
  15.  
  16. rt = ObjC.runtime
  17. Application = rt.Application
  18. NXApp = Application()
  19. Button = rt.Button
  20. Window = rt.Window
  21.  
  22. class Fred:
  23.     def __init__ (self):
  24.     self.stopped = 0
  25.     self.thisWindow = NXApp.appIcon()
  26.  
  27.     #win = Window.alloc()
  28.     #frame = ((200.0, 300.0), (250.0, 100.0))
  29.     #win.initContent__style__backing__buttonMask__defer__(frame, 6, 2, 5, 0)
  30.     #win.setTitle__ ('LittleButtonedWindow')
  31.  
  32.     #but = Button.alloc().initFrame__ (((10.0, 10.0), (200.0, 80.0)))
  33.     #but.setTitle__ ("Stop")
  34.     #win.contentView().addSubview__(but)
  35.     #win.display()
  36.     #win.makeKeyAndOrderFront__(NXApp)
  37.     #but.setTarget__(self)
  38.     #but.setAction__('stop:')
  39.     # end def
  40.  
  41.     def stop__ (sender):
  42.     print "stopped\n"
  43.     self.stopped = 1
  44.     # end def
  45.     
  46.     def iconXPosition (self):
  47.     framep = self.thisWindow.getFrame__.pack_argument (0)
  48.     self.thisWindow.getFrame__ (framep)
  49.     return framep.unpack()[0][0]
  50.     # end def
  51.  
  52.     def iconYPosition (self):
  53.         framep = self.thisWindow.getFrame__.pack_argument (0)
  54.     self.thisWindow.getFrame__ (framep)
  55.     return framep.unpack()[0][1]
  56.     # end def
  57.  
  58.     def mouseXPosition (self):
  59.     pointp = self.thisWindow.getMouseLocation__.pack_argument (0)
  60.     self.thisWindow.getMouseLocation__ (pointp)
  61.     return pointp.unpack()[0]
  62.     # end def
  63.  
  64.     def mouseYPosition (self):
  65.     pointp = self.thisWindow.getMouseLocation__.pack_argument (0)
  66.     self.thisWindow.getMouseLocation__ (pointp)
  67.     return pointp.unpack()[1]
  68.     # end def
  69.  
  70.     def moveIcon (self, x, y):
  71.     self.thisWindow.moveTo____ (x, y)
  72.     # end def
  73.  
  74.     def dispatchEvents (self):
  75.     #event = NXApp.peekAndGetNextEvent__ (0)
  76.     #if event:
  77.     #    NXApp.sendEvent__ (event)
  78.     ## end if
  79.     pass
  80.     # end def
  81. # end class
  82.  
  83. class don_fred:
  84.     def appDidInit__ (self, sender):
  85.     fred = Fred()
  86.     while not fred.stopped:
  87.         if fred.mouseXPosition() > 32:
  88.         dx = 1
  89.         elif fred.mouseXPosition() == 32:
  90.         dx = 0
  91.         else:
  92.         dx = -1
  93.         # end if
  94.         if fred.mouseYPosition() > 32:
  95.         dy = 1
  96.         elif fred.mouseYPosition() == 32:
  97.         dy = 0
  98.         else:
  99.         dy = -1
  100.         # end if
  101.         fred.moveIcon (fred.iconXPosition() + dx, fred.iconYPosition() + dy)
  102.         fred.dispatchEvents()
  103.     # end while
  104.     # end def
  105. # end class
  106.  
  107. class sean_fred:
  108.     def appDidInit__ (self, sender):
  109.     fred = Fred()
  110.     while not fred.stopped:
  111.         if fred.mouseXPosition() > 0:
  112.         dx = 1
  113.         else:
  114.         dx = -1
  115.         # end if
  116.         if fred.mouseYPosition() > 0:
  117.         dy = 1
  118.         else:
  119.         dy = -1
  120.         # end if
  121.         fred.moveIcon (fred.iconXPosition() + dx, fred.iconYPosition() + dy)
  122.     # end while
  123.     # end def
  124. # end class
  125.  
  126. class guus_fred:
  127.     def appDidInit__ (self, sender):
  128.     fred = Fred()
  129.     while not fred.stopped:
  130.         fred.moveIcon (fred.iconXPosition() + (fred.mouseXPosition() - 32) / 20,
  131.                fred.iconYPosition() + (fred.mouseYPosition() - 32) / 20)
  132.     # end while
  133.     # end def
  134. # end class
  135.  
  136. if __name__ == "__main__":
  137.     import sys
  138.     if len (sys.argv) == 1 or sys.argv[1] == 'guus':
  139.     delegate = guus_fred()
  140.     elif sys.argv[1] == 'don':
  141.     delegate = don_fred()
  142.     elif sys.argv[1] == 'sean':
  143.     delegate = sean_fred()
  144.     else:
  145.     print "Please specify one on 'don', 'sean', 'guus'"
  146.     sys.exit (0)
  147.     # endif
  148.     
  149.     NXApp.setDelegate__ (delegate)
  150.     NXApp.run()
  151.  
  152.