Debian Codegraph @

fltk/test/DragAndDrop.py

raw symbols SCIP
1 #
2 # "$Id: DragAndDrop.py 536 2020-10-30 15:20:32Z andreasheld $"
3 #
4 # Drag and drop 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
28 from fltk import *
29
30
31 class DNDWidget(Fl_Widget):
32 text_string = ""
33
34 def __init__(self, x, y, w, h, label):
35 Fl_Widget.__init__(self, x, y, w, h, label)
36
37 def draw(self):
38 fl_rect(self.x(), self.y(), self.w(), self.h(), FL_RED)
39
40 def handle(self, event):
41 if event == FL_DND_ENTER:
42 print("FL_DND_ENTER ", self.text_string)
43 return 1
44 elif event == FL_DND_LEAVE:
45 print("FL_DND_LEAVE ", self.text_string)
46 return 1
47 elif event == FL_DND_DRAG:
48 print(f"FL_DND_DRAG {self.text_string} ({Fl.event_x()}, {Fl.event_y()})")
49 return 1
50 elif event == FL_DND_RELEASE:
51 print(f"FL_DND_RELEASE {self.text_string} ({Fl.event_x()}, {Fl.event_y()})")
52 return 1
53 elif event == FL_PUSH:
54 print("PREPUSH ", self.text_string)
55 Fl.copy("text", 5, 0)
56 Fl.dnd()
57 print("POSTPUSH ", self.text_string)
58 return 1
59 elif event == FL_PASTE:
60 cl = Fl.event_text()
61 ln = Fl.event_length()
62 print("PASTE ", self.text_string)
63 print(f" text = {cl}, length = {ln}")
64 return 1
65 else:
66 return 0
67
68 def text(self, t):
69 self.text_string = t
70 return
71
72
73
74
75 if __name__=='__main__':
76 window = Fl_Window(50, 50, 200, 200)
77 w1 = DNDWidget(5, 5, 90, 90, "DND")
78 w1.text("A")
79 w2 = DNDWidget(105, 105, 90, 90, "DND")
80 w2.text("B")
81 window.end()
82
83 window.show()
84
85 Fl.run()