home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/python
- #
- # Copyright (c) 1996 by Lele Gaifax. All Rights Reserved
- #
- # This file is part of Nothing (yet).
- #
- # $RCSfile: Fred.py,v $
- # $Revision: 1.1.1.1 $
- # $Date: 1996/10/02 21:37:06 $
- #
- # Created Wed Oct 2 01:49:55 1996.
- #
-
- import ObjC
-
- rt = ObjC.runtime
- Application = rt.Application
- NXApp = Application()
- Button = rt.Button
- Window = rt.Window
-
- class Fred:
- def __init__ (self):
- self.stopped = 0
- self.thisWindow = NXApp.appIcon()
-
- #win = Window.alloc()
- #frame = ((200.0, 300.0), (250.0, 100.0))
- #win.initContent__style__backing__buttonMask__defer__(frame, 6, 2, 5, 0)
- #win.setTitle__ ('LittleButtonedWindow')
-
- #but = Button.alloc().initFrame__ (((10.0, 10.0), (200.0, 80.0)))
- #but.setTitle__ ("Stop")
- #win.contentView().addSubview__(but)
- #win.display()
- #win.makeKeyAndOrderFront__(NXApp)
- #but.setTarget__(self)
- #but.setAction__('stop:')
- # end def
-
- def stop__ (sender):
- print "stopped\n"
- self.stopped = 1
- # end def
-
- def iconXPosition (self):
- framep = self.thisWindow.getFrame__.pack_argument (0)
- self.thisWindow.getFrame__ (framep)
- return framep.unpack()[0][0]
- # end def
-
- def iconYPosition (self):
- framep = self.thisWindow.getFrame__.pack_argument (0)
- self.thisWindow.getFrame__ (framep)
- return framep.unpack()[0][1]
- # end def
-
- def mouseXPosition (self):
- pointp = self.thisWindow.getMouseLocation__.pack_argument (0)
- self.thisWindow.getMouseLocation__ (pointp)
- return pointp.unpack()[0]
- # end def
-
- def mouseYPosition (self):
- pointp = self.thisWindow.getMouseLocation__.pack_argument (0)
- self.thisWindow.getMouseLocation__ (pointp)
- return pointp.unpack()[1]
- # end def
-
- def moveIcon (self, x, y):
- self.thisWindow.moveTo____ (x, y)
- # end def
-
- def dispatchEvents (self):
- #event = NXApp.peekAndGetNextEvent__ (0)
- #if event:
- # NXApp.sendEvent__ (event)
- ## end if
- pass
- # end def
- # end class
-
- class don_fred:
- def appDidInit__ (self, sender):
- fred = Fred()
- while not fred.stopped:
- if fred.mouseXPosition() > 32:
- dx = 1
- elif fred.mouseXPosition() == 32:
- dx = 0
- else:
- dx = -1
- # end if
- if fred.mouseYPosition() > 32:
- dy = 1
- elif fred.mouseYPosition() == 32:
- dy = 0
- else:
- dy = -1
- # end if
- fred.moveIcon (fred.iconXPosition() + dx, fred.iconYPosition() + dy)
- fred.dispatchEvents()
- # end while
- # end def
- # end class
-
- class sean_fred:
- def appDidInit__ (self, sender):
- fred = Fred()
- while not fred.stopped:
- if fred.mouseXPosition() > 0:
- dx = 1
- else:
- dx = -1
- # end if
- if fred.mouseYPosition() > 0:
- dy = 1
- else:
- dy = -1
- # end if
- fred.moveIcon (fred.iconXPosition() + dx, fred.iconYPosition() + dy)
- # end while
- # end def
- # end class
-
- class guus_fred:
- def appDidInit__ (self, sender):
- fred = Fred()
- while not fred.stopped:
- fred.moveIcon (fred.iconXPosition() + (fred.mouseXPosition() - 32) / 20,
- fred.iconYPosition() + (fred.mouseYPosition() - 32) / 20)
- # end while
- # end def
- # end class
-
- if __name__ == "__main__":
- import sys
- if len (sys.argv) == 1 or sys.argv[1] == 'guus':
- delegate = guus_fred()
- elif sys.argv[1] == 'don':
- delegate = don_fred()
- elif sys.argv[1] == 'sean':
- delegate = sean_fred()
- else:
- print "Please specify one on 'don', 'sean', 'guus'"
- sys.exit (0)
- # endif
-
- NXApp.setDelegate__ (delegate)
- NXApp.run()
-
-