Debian Codegraph @

fltk/test/subwindow.py

raw symbols SCIP
1 # "$Id: subwindow.py 535 2020-10-30 10:43:46Z andreasheld $"
2 #
3 # Subwindows test program for pyFLTK the Python bindings
4 # for the Fast Light Tool Kit (FLTK).
5 # Test to make sure nested windows work.
6 # Events should be reported for enter/exit and all mouse operations
7 # Buttons and pop-up menu should work, indicating that mouse positions
8 # are being correctly translated.
9 #
10 # FLTK copyright 1998-1999 by Bill Spitzak and others.
11 # pyFLTK copyright 2003 by Andreas Held and others.
12 #
13 # This library is free software you can redistribute it and/or
14 # modify it under the terms of the GNU Library General Public
15 # License, version 2.0 as published by the Free Software Foundation.
16 #
17 # This library is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # Library General Public License for more details.
21 #
22 # You should have received a copy of the GNU Library General Public
23 # License along with this library if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 # USA.
26 #
27 # Please report all bugs and problems to "[email protected]".
28 #
29
30
31 from fltk import *
32 import sys, math
33
34
35 class EnterExit(Fl_Box):
36 def __init__(self, x, y, w, h, l):
37 Fl_Box.__init__(self,FL_BORDER_BOX,x,y,w,h,l)
38 print(self)
39
40 # def draw(self):
41 # #Fl_Box.draw(self)
42 # pass
43
44 def handle(self, e):
45 print("event = ", e)
46 if e == FL_ENTER:
47 try:
48 print("FL_ENTER")
49 self.color(FL_RED)
50 self.redraw()
51 except:
52 print('uncaught!', sys.exc_info()[0], sys.exc_info()[1])
53 return 1
54 elif e == FL_LEAVE:
55 try:
56 print("FL_LEAVE")
57 self.color(FL_GRAY)
58 self.redraw()
59 except:
60 print('uncaught!', sys.exc_info()[0], sys.exc_info()[1])
61 return 1
62 else:
63 return 0
64
65
66
67 class testwindow(Fl_Window):
68 cx = 0
69 cy = 0
70 key = '0'
71 def __init__(self, b, x, y, w, h, l):
72 Fl_Window.__init__(self,x,y,w, h,l)
73 self.box(b)
74 key = 0
75
76 def draw(self):
77 print(self.label(), " :draw")
78 Fl_Window.draw(self)
79 if self.key:
80 fl_draw(self.key, 1, self.cx, self.cy)
81
82 def handle(self, e):
83 if e != FL_MOVE:
84 print(self.label())
85 if Fl_Window.handle(self, e):
86 return 1;
87 if e == FL_FOCUS:
88 return 1
89 if e == FL_PUSH:
90 Fl.focus(self.this)
91 return 1
92 if e == FL_KEYDOWN and Fl.event_text()[0]:
93 self.key = Fl.event_text()[0]
94 self.cx = Fl.event_x()
95 self.y = Fl.event_y()
96 self.redraw()
97 return 1
98 return 0
99
100
101
102 popup = None
103
104 bigmess = "this|is|only|a test"
105
106 window = testwindow(FL_UP_BOX,0,0,400,400,"outer")
107
108 tn1 = Fl_Toggle_Button(310,310,80,80,"&outer")
109
110 ee1 = EnterExit(10,310,80,80,"enterexit")
111
112 fi1 = Fl_Input(150,310,150,25,"input:")
113
114 mb1 = Fl_Menu_Button(5,150,80,25,"menu&1")
115 #setMenu(mb1, ( ("this",), ("is",), ("only",), ("a test",), (None,)))
116 mb1.menu(( ("this",), ("is",), ("only",), ("a test",), (None,)))
117 #mb1.add(bigmess)
118 subwindow = testwindow(FL_DOWN_BOX,100,100,200,200,"inner")
119 #subwindow = Fl_Window(FL_DOWN_BOX,100,100,200,200,"inner")
120 tn2 = Fl_Toggle_Button(310,310,80,80,"&outer")
121 subwindow.add(tn2)
122
123 ee2 = EnterExit(10,310,80,80,"enterexit")
124 subwindow.add(ee2)
125
126 fi2 = Fl_Input(150,310,150,25,"input:")
127 subwindow.add(fi2)
128
129 mb2 = Fl_Menu_Button(5,150,80,25,"menu&2")
130 #mb2.add(bigmess)
131 #setMenu(mb2, ( ("this",), ("is",), ("only",), ("a test",), (None,)))
132 mb2.menu(( ("this",), ("is",), ("only",), ("a test",), (None,)))
133 subwindow.end()
134 subwindow.resizable(subwindow)
135 window.resizable(subwindow)
136 window.add(subwindow)
137
138 fb = Fl_Box(FL_NO_BOX,0,0,400,100,
139 "A child Fl_Window with children of it's own may "
140 "be useful for imbedding controls into a GL or display "
141 "that needs a different visual. There are bugs with the "
142 "origins being different between drawing and events, "
143 "which I hope I have solved."
144 )
145 fb.align(FL_ALIGN_WRAP)
146
147 popup = Fl_Menu_Button(0,0,400,400)
148 popup.type(Fl_Menu_Button.POPUP3)
149 #setMenu(popup, ( ("This",), ("is",), ("a popup",), ("menu",), ("this",), ("is",), ("only",), ("a test",), (None,)))
150 popup.menu(( ("This",), ("is",), ("a popup",), ("menu",), ("this",), ("is",), ("only",), ("a test",), (None,)))
151 #popup.add("This|is|a popup|menu")
152 #popup.add(bigmess)
153 window.add(fb)
154 window.add(popup)
155 window.end()
156
157 #window.show(len(sys.argv), sys.argv)
158 window.show()
159
160 print("rec = ", sys.getrecursionlimit())
161 #sys.setrecursionlimit(2000)
162
163 Fl.run()