home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnd101.zip / Add-Ons / Fnorb / examples / tkinter / server.py < prev    next >
Text File  |  1999-06-28  |  5KB  |  194 lines

  1. #!/usr/bin/env python
  2. #############################################################################
  3. # Copyright (C) DSTC Pty Ltd (ACN 052 372 577) 1997, 1998, 1999
  4. # All Rights Reserved.
  5. #
  6. # The software contained on this media is the property of the DSTC Pty
  7. # Ltd.  Use of this software is strictly in accordance with the
  8. # license agreement in the accompanying LICENSE.HTML file.  If your
  9. # distribution of this software does not contain a LICENSE.HTML file
  10. # then you have no rights to use this software in any manner and
  11. # should contact DSTC at the address below to determine an appropriate
  12. # licensing arrangement.
  13. #      DSTC Pty Ltd
  14. #      Level 7, GP South
  15. #      Staff House Road
  16. #      University of Queensland
  17. #      St Lucia, 4072
  18. #      Australia
  19. #      Tel: +61 7 3365 4310
  20. #      Fax: +61 7 3365 4311
  21. #      Email: enquiries@dstc.edu.au
  22. # This software is being provided "AS IS" without warranty of any
  23. # kind.  In no event shall DSTC Pty Ltd be liable for damage of any
  24. # kind arising out of or in connection with the use or performance of
  25. # this software.
  26. #
  27. # Project:      Fnorb
  28. # File:         $Source: /units/arch/src/Fnorb/examples/tkinter/RCS/server.py,v $
  29. # Version:      @(#)$RCSfile: server.py,v $ $Revision: 1.8 $
  30. #
  31. #############################################################################
  32. """ A server with a 'tkinter' GUI. """
  33.  
  34.  
  35. # Standard/built-in modules.
  36. import sys
  37.  
  38. # Tkinter modules.
  39. from Tkinter import *
  40.  
  41. # Fnorb modules.
  42. from Fnorb.orb import BOA, CORBA, TkReactor
  43.  
  44. # Stubs and skeletons generated by 'fnidl'.
  45. import TicToc, TicToc_skel
  46.  
  47.  
  48. class Server(TicToc_skel.TicTocIF_skel):
  49.     """ GUI Server! """
  50.  
  51.     def __init__(self):
  52.  
  53.     # Root window.
  54.     self.root = Tk()
  55.  
  56.     # Main frame.
  57.     self.mainFrame = MainFrame(self.root)
  58.  
  59.     # Pack it!
  60.     self.mainFrame.pack(fill='x')
  61.  
  62.     return
  63.  
  64.     #########################################################################
  65.     # CORBA TicTocIF operations.
  66.     #########################################################################
  67.     
  68.     def tictoc(self):
  69.  
  70.     print 'Server.tictoc: operation tictoc invoked by client.'
  71.     self.mainFrame.ticTocButton.ticToc()
  72.     print 'Server.tictoc: operation tictoc complete.'
  73.  
  74.     return
  75.  
  76.     def quit(self):
  77.  
  78.     print 'Server.quit: operation quit invoked by client.'
  79.     boa = BOA.BOA_init()
  80.     boa._fnorb_quit()
  81.     print 'Server.quit: operation tictoc complete.'
  82.  
  83.     return
  84.  
  85.  
  86. class MainFrame(Frame):
  87.  
  88.     def __init__(self, parent, **kw):
  89.  
  90.     apply(Frame.__init__, (self, parent), kw)
  91.  
  92.     # Buttons.
  93.     self.ticTocButton = TicTocButton(self)
  94.  
  95.     # Pack it!
  96.     self.ticTocButton.pack(side='left', expand=1)
  97.  
  98.     return
  99.  
  100.  
  101. class TicTocButton(Button):
  102.  
  103.     def __init__(self, parent, **kw):
  104.  
  105.     self._d_options = {'command': self.ticToc,
  106.                'state'  : 'normal',
  107.                'text'   : 'Tic!'}
  108.  
  109.     apply(Button.__init__, (self, parent), self._d_options)
  110.  
  111.     # Toggle state (0 = 'Tic!', 1 = 'Toc!').
  112.     self._state = 0
  113.  
  114.     return
  115.  
  116.     def ticToc(self):
  117.     """ Callback invoked when the button is pressed. """
  118.  
  119.     print 'TicTocButton.ticToc: button pressed.'
  120.  
  121.     if self._state == 0:
  122.         self.configure(text='Toc!')
  123.         self._state = 1
  124.  
  125.     else:
  126.         self.configure(text='Tic!')
  127.         self._state = 0
  128.  
  129.     print 'TicTocButton.ticToc: complete.'
  130.     return
  131.  
  132.  
  133. def main(argv):
  134.     """ Do it! """
  135.  
  136.     print 'Initialising the ORB...'
  137.  
  138.     # Initialise the ORB.
  139.     orb = CORBA.ORB_init(argv, CORBA.ORB_ID)
  140.  
  141.     print 'Initialising the Tk Reactor...'
  142.  
  143.     # Because we are using Tk, we must use the 'TkReactor' which allows Tk
  144.     # and Fnorb events to be handled from within a single event loop.
  145.     #
  146.     # The 'TkReactor' MUST be be initialised BEFORE the BOA.
  147.     TkReactor.TkReactor_init()
  148.  
  149.     print 'Initialising the BOA...'
  150.  
  151.     # Initialise the BOA.
  152.     boa = BOA.BOA_init(sys.argv, BOA.BOA_ID)
  153.  
  154.     print 'Creating object reference...'
  155.  
  156.     # Create an object reference ('fred' is the object key).
  157.     obj = boa.create('fred', Server._FNORB_ID)
  158.  
  159.     print 'Creating implementation...'
  160.  
  161.     # Create an instance of the implementation class.
  162.     impl = Server()
  163.  
  164.     print 'Activating the implementation...'
  165.  
  166.     # Activate the implementation (ie. connect the generated object reference
  167.     # to the implementation).  Note that the implementation will not receive
  168.     # any operation requests until we start the event loop (see below).
  169.     boa.obj_is_ready(obj, impl)
  170.  
  171.     # Write the stringified object reference to a file (this is just a 'cheap
  172.     # and cheerful' way of making the object reference available to the
  173.     # client!).
  174.     open('server.ref', 'w').write(orb.object_to_string(obj))
  175.  
  176.     print 'Server created and accepting requests...'
  177.  
  178.     # Start the event loop.
  179.     boa._fnorb_mainloop()
  180.  
  181.     print 'Server finished!'
  182.  
  183.     return 0
  184.  
  185. #############################################################################
  186.  
  187. if __name__ == '__main__':
  188.     # Do it!
  189.     sys.exit(main(sys.argv))
  190.  
  191. #############################################################################
  192.