Debian Codegraph @

fltk/test/handle_events.py

raw symbols SCIP
1 #
2 # "$Id: handle_events.py 536 2020-10-30 15:20:32Z andreasheld $"
3 #
4 # Event test program for pyFLTK the Python bindings
5 # for the Fast Light Tool Kit (FLTK).
6 #
7 # FLTK copyright 1998-1999 by Bill Spitzak and others.
8 # pyFLTK copyright 2003 by Andreas Held and others.
9 #
10 # This library is free software you can redistribute it and/or
11 # modify it under the terms of the GNU Library General Public
12 # License, version 2.0 as published by the Free Software Foundation.
13 #
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Library General Public License for more details.
18 #
19 # You should have received a copy of the GNU Library General Public
20 # License along with this library if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 # USA.
23 #
24 # Please report all bugs and problems to "[email protected]".
25 #
26
27 from fltk import *
28 import sys
29
30
31 highlight = 0
32
33 class EventHandler(Fl_Widget):
34 def __init__(self, X, Y, W, H, L):
35 Fl_Widget.__init__(self, X, Y, W, H, L)
36
37 def handle(self, event):
38 global highlight
39 #print "Alt event: ", Fl.event_alt()
40 if event == FL_PUSH:
41 print("FL_PUSH")
42 if Fl.event_clicks():
43 print("Double click")
44 else:
45 if Fl.event_button1():
46 print("Button1")
47 elif Fl.event_button2():
48 print("Button2")
49 elif Fl.event_button3():
50 print("Button3")
51 highlight = 1
52 self.redraw()
53 return 1
54 elif event == FL_DRAG:
55 print("FL_DRAG")
56 t = Fl.event_inside(self);
57 if t != highlight:
58 highlight = t
59 self.redraw()
60 return 1
61 elif event == FL_RELEASE:
62 print("FL_RELEASE")
63 print(f"Button = {Fl.event_button()}")
64 if highlight != 0:
65 highlight = 0
66 self.redraw()
67 self.do_callback()
68 # never do anything after a callback, as the callback
69 # may delete the widget!
70 return 1
71
72 elif event == FL_SHORTCUT:
73 print("FL_SHORTCUT")
74 if Fl.event_key() == 'x':
75 self.do_callback()
76 return 1
77 return 0
78 elif event == FL_FOCUS:
79 Fl.focus(self)
80 self.redraw()
81 return 1
82 elif event == FL_UNFOCUS:
83 self.redraw()
84 return 1
85 elif event == FL_KEYDOWN:
86 print("Last key pressed = ", Fl.event_key())
87 return 1
88 elif event == FL_MOVE:
89 print("FL_MOVE")
90 return 1
91 else:
92 return 0
93
94 def draw(self):
95 fl_color(FL_RED)
96 fl_rectf(10,10,self.w(),self.h())
97 return None
98
99 def resize(self, X, Y, W, H):
100 print(f"Resizing: {X}, {Y}, {W}, {H}\n")
101 #Fl_Widget.resize(self, X, Y, W, H)
102
103
104
105 window = Fl_Window(300, 300)
106 d = EventHandler(10,10,280,280,"test")
107 window.resizable(d)
108
109 window.end()
110 window.show(len(sys.argv),sys.argv)
111 Fl.run()