At the release of 1.0.1.
[python/dscho.git] / Demo / sgi / flp / test_cb.py
blob41635036d34a233617ff6660883ebfbda5de59b8
2 # Example 2 - Using fl in python with callbacks.
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.
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
14 # The following struct is created to hold the instance variables
15 # main_form, button1, button2 and exitbutton.
17 class myform:
19 # The constructor parses and creates the form, but doesn't
20 # display it (yet).
21 def __init__(self, number):
23 # First we parse the form
24 parsetree = flp.parse_form('test_cb', 'main_form')
26 # Next we create it
28 flp.create_full_form(self, parsetree)
30 # And keep our number
31 self.number = number
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, '')
39 # The callback functions
40 def button1CB(self, obj, arg):
41 print 'Button 1 pressed on form', self.number
43 def button2CB(self, obj, arg):
44 print 'Button 2 pressed on form', self.number
46 def exitbuttonCB(self, obj, arg):
47 print 'Ok, bye bye'
48 sys.exit(0)
51 # The main program. Instantiate two variables of the forms class
52 # and interact with them.
54 form1 = myform(1)
55 form2 = myform(2)
57 form1.show()
58 form2.show()
60 obj = fl.do_forms()
61 print 'do_forms() returned. This should not happen. obj=', obj