#!/usr/bin/env python

""" server.py
 Copyright (C) 1998 Aloril
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""

# import the ilu_tk module first, so that
# initialization happens in the right order:
import ilu_tk

import sys,ilu, Tkinter
from engine import engine
from event import event


class interface:
    def __init__(self, eng):
        self.eng=eng
        # Now we put up a Tk button so that the user can kill the
        #  server by pressing the button
        
        f = Tkinter.Frame() ; Tkinter.Pack.config(f)
        f.master.title(self.eng.IluObjectID())
        b = Tkinter.Button (f, {'text' : "Quit",\
                                'command': self.quit})
        b.pack ({'side': 'left', 'fill': 'both'})
        
        b = Tkinter.Button (f, {'text' : "One step",\
                                 'command': self.run_step})
        b.pack ({'side': 'left', 'fill': 'both'})
        self.loopb = Tkinter.Button (f, {'text' : "Run",\
                                         'command': self.set_loop})
        self.loopb.pack ({'side': 'left', 'fill': 'both'})
        self.active_loop=0
    def quit(self):
        sys.exit(0)
    def run_step(self):
        self.eng.metaEvent("event('step')")
    def set_timer(self):
        ilu_tk.ilutkinter.createtimerhandler(200, self.loop)
    def set_loop(self):
        if self.active_loop:
            self.loopb.config(text="Run")
            self.active_loop=0
        else:
            self.loopb.config(text="Stop")
            self.set_timer()
            self.active_loop=1
    def loop(self):
        self.run_step()
        if self.active_loop:
            self.set_timer()

def main(argv):
    if (len(argv) < 2):
        serverName="cyphesis"
        #print "Usage:  python server.py SERVER-ID"
        #sys.exit(1)
    else:
        serverName=argv[1]

    # Create a kernel server with appropriate server ID, which
    #  is passed in as the first argument

    theServer = ilu.CreateServer(serverName)

    # Now create an instance of a Factory object on that server,
    #  with the instance handle "theFactory"

    theFactory = engine ("engine", theServer)

    # Now make the Factory object "well-known" by publishing it.

    theFactory.IluPublish()

    # Now we print the string binding handle (the object's name plus
    # its location) of the new instance.

    print "Factory instance published."
    print "Its SBH is '" + theFactory.IluSBH() + "'."

    #handle = ilu.CreateLoopHandle()
    #ilu.RunMainLoop (handle)

    i=interface(theFactory)

    # Then we wait in the ilu_tk mainloop, instead of either
    #  the ILU mainloop or the Tkinter mainloop
    
    ilu_tk.RunMainLoop()

main(sys.argv)

    Source: geocities.com/siliconvalley/station/4279/src

               ( geocities.com/siliconvalley/station/4279)                   ( geocities.com/siliconvalley/station)                   ( geocities.com/siliconvalley)