home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / sgi / flp / test_cb.py < prev    next >
Text File  |  1993-12-17  |  2KB  |  62 lines

  1. #
  2. # Example 2 - Using fl in python with callbacks.
  3. #
  4. # The form is named 'main_form' and resides on file 'test_cb.fd'.
  5. # It has three objects named button1, button2 and exitbutton.
  6. # All buttons have callbacks with the same names as their corresponding
  7. # buttons but with CB appended.
  8. #
  9. import fl        # The forms library
  10. import FL        # Symbolic constants for the above
  11. import flp        # The module to parse .fd files
  12. import sys
  13.  
  14. # The following struct is created to hold the instance variables
  15. # main_form, button1, button2 and exitbutton.
  16.  
  17. class myform:
  18.     #
  19.     # The constructor parses and creates the form, but doesn't
  20.     # display it (yet).
  21.     def __init__(self, number):
  22.         #
  23.         # First we parse the form
  24.         parsetree = flp.parse_form('test_cb', 'main_form')
  25.         #
  26.         # Next we create it
  27.         
  28.         flp.create_full_form(self, parsetree)
  29.  
  30.         # And keep our number
  31.         self.number = number
  32.  
  33.     #
  34.     # The show function displays the form. It doesn't do any interaction,
  35.     # though.
  36.     def show(self):
  37.         self.main_form.show_form(FL.PLACE_SIZE, 1, '')
  38.  
  39.     # The callback functions
  40.     def button1CB(self, obj, arg):
  41.         print 'Button 1 pressed on form', self.number
  42.  
  43.     def button2CB(self, obj, arg):
  44.         print 'Button 2 pressed on form', self.number
  45.  
  46.     def exitbuttonCB(self, obj, arg):
  47.         print 'Ok, bye bye'
  48.         sys.exit(0)
  49.  
  50. #
  51. # The main program. Instantiate two variables of the forms class
  52. # and interact with them.
  53.  
  54. form1 = myform(1)
  55. form2 = myform(2)
  56.  
  57. form1.show()
  58. form2.show()
  59.  
  60. obj = fl.do_forms()
  61. print 'do_forms() returned. This should not happen. obj=', obj
  62.