Debian Codegraph @

fltk/test/DraggableBox.py

raw symbols SCIP
1 #
2 # "$Id: DraggableBox.py 493 2012-02-14 21:40:41Z andreasheld $"
3 #
4 # Draggable boxes in a scrollable window. After the demo program
5 # by G. Ercolano, http://seriss.com/people/erco/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 # Demonstrate user-movable boxes in a scroll region
31 # [email protected] 08/06/02
32
33 # XPM
34 cat_xpm = [
35 "50 50 4 1",
36 " c black",
37 "o c #ff9900",
38 "@ c #ffffff",
39 "# c None",
40 "##################################################",
41 "##################################################",
42 "##################################################",
43 "##################################################",
44 "##################################################",
45 "##################################################",
46 "##################################################",
47 "##################################################",
48 "##################################################",
49 "### ############################## ####",
50 "### ooooo ########################### ooooo ####",
51 "### oo oo ######################### oo oo ####",
52 "### oo oo ####################### oo oo ####",
53 "### oo oo ##################### oo oo ####",
54 "### oo oo ################### oo oo ####",
55 "### oo oo oo oo ####",
56 "### oo oo ooooooooooooooo oo oo ####",
57 "### oo ooooooooooooooooooooo oo ####",
58 "### oo ooooooooooooooooooooooooooo ooo ####",
59 "#### oo ooooooo ooooooooooooo ooooooo oo #####",
60 "#### oo oooooooo ooooooooooooo oooooooo oo #####",
61 "##### oo oooooooo ooooooooooooo oooooooo oo ######",
62 "##### o ooooooooooooooooooooooooooooooo o ######",
63 "###### ooooooooooooooooooooooooooooooooooo #######",
64 "##### ooooooooo ooooooooo ooooooooo ######",
65 "##### oooooooo @@@ ooooooo @@@ oooooooo ######",
66 "##### oooooooo @@@@@ ooooooo @@@@@ oooooooo ######",
67 "##### oooooooo @@@@@ ooooooo @@@@@ oooooooo ######",
68 "##### oooooooo @@@ ooooooo @@@ oooooooo ######",
69 "##### ooooooooo ooooooooo ooooooooo ######",
70 "###### oooooooooooooo oooooooooooooo #######",
71 "###### oooooooo@@@@@@@ @@@@@@@oooooooo #######",
72 "###### ooooooo@@@@@@@@@ @@@@@@@@@ooooooo #######",
73 "####### ooooo@@@@@@@@@@@ @@@@@@@@@@@ooooo ########",
74 "######### oo@@@@@@@@@@@@ @@@@@@@@@@@@oo ##########",
75 "########## o@@@@@@ @@@@@ @@@@@ @@@@@@o ###########",
76 "########### @@@@@@@ @ @@@@@@@ ############",
77 "############ @@@@@@@@@@@@@@@@@@@@@ #############",
78 "############## @@@@@@@@@@@@@@@@@ ###############",
79 "################ @@@@@@@@@ #################",
80 "#################### #####################",
81 "##################################################",
82 "##################################################",
83 "##################################################",
84 "##################################################",
85 "##################################################",
86 "##################################################",
87 "##################################################",
88 "##################################################",
89 "##################################################"
90 ]
91
92 G_win = None
93 G_scroll = None
94 G_cat = Fl_Pixmap(cat_xpm)
95 offset = [0,0]
96
97 # A 'MOVABLE' BOX
98 class Box(Fl_Box):
99 def __init__(self, X, Y, W, H, L):
100 Fl_Box.__init__(self, X, Y, W, H, L)
101 self.image(G_cat)
102 self.box(FL_UP_BOX)
103 self.color(FL_GRAY)
104 def __init__(self, X, Y):
105 Fl_Box.__init__(self, X, Y, 80, 50)
106 self.image(G_cat)
107 self.box(FL_UP_BOX)
108 self.color(FL_GRAY)
109
110 def handle(self, e):
111 global offset
112 if e == FL_PUSH:
113 # save where user clicked for dragging
114 offset[0] = self.x() - Fl.event_x()
115 offset[1] = self.y() - Fl.event_y()
116 return 1
117 elif e == FL_RELEASE:
118 return 1
119 elif e == FL_DRAG:
120 # handle dragging
121 self.position(offset[0]+Fl.event_x(), offset[1]+Fl.event_y())
122 G_win.redraw()
123 return 1
124 elif e == FL_ENTER:
125 return 1
126 elif e == FL_MOVE:
127 print("FL_MOVE")
128 return 0
129 return 0
130
131
132 # MAIN
133 if __name__=='__main__':
134 G_win = Fl_Double_Window(720,486)
135 G_scroll = Fl_Scroll(10,10,720-20,486-20)
136 G_scroll.box(FL_FLAT_BOX)
137 G_scroll.color(fl_rgb_color(46))
138 G_scroll.begin()
139 # CREATE NEW BOXES ON THE SCROLLABLE 'DESK'
140 l = []
141 x = 200
142 while x <= 500:
143 y = 100
144 while y < 370:
145 l.append(Box(x,y))
146 y += 70
147 x += 100
148
149 G_scroll.end()
150 G_win.resizable(G_win)
151 G_win.show(len(sys.argv), sys.argv)
152 Fl.run()