Debian Codegraph @

fltk/test/image.py

raw symbols SCIP
1 #
2 # "$Id: image.py 495 2013-03-30 09:39:45Z andreasheld $"
3 #
4 # Image 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 from math import *
29 import sys
30
31
32 width = 100
33 height = 100
34 image = []
35
36 def make_image():
37 #image = new uchar[4*width*height];
38 #uchar *p = image;
39 p = image
40 index = 0
41
42 y = 0
43 while y < height:
44 dy = float(y)/(height-1)
45 x = 0
46 while x < width:
47 dx = float(x)/(width-1)
48 p.append(int(255*((1.0-dx)*(1.0-dy))))
49 index = index+1
50 p.append(int(255*((1.0-dx)*dy)))
51 index = index+1
52 p.append(int(255*(dx*dy)))
53 index = index+1
54 dx = dx-0.5
55 dy = dy-0.5
56 alpha = int(255*sqrt(dx*dx+dy*dy))
57 if alpha < 255:
58 p.append(alpha)
59 else:
60 p.append(255)
61 index = index+1
62 dy = dy+0.5
63 x = x+1
64 y = y+1
65 print("make_image done")
66 return None
67
68
69 #globals
70 leftb = None
71 rightb = None
72 topb = None
73 bottomb = None
74 insideb = None
75 overb = None
76 inactb = None
77 b = None
78 w = None
79
80 def button_cb(ptr):
81 global b, w
82
83 i = 0
84 if leftb.value():
85 i = i + FL_ALIGN_LEFT
86 if rightb.value():
87 i = i + FL_ALIGN_RIGHT
88 if topb.value():
89 i = i + FL_ALIGN_TOP
90 if bottomb.value():
91 i = i + FL_ALIGN_BOTTOM
92 if insideb.value():
93 i = i + FL_ALIGN_INSIDE
94 if overb.value():
95 i = i + FL_ALIGN_TEXT_OVER_IMAGE
96 b.align(i)
97 if inactb.value():
98 b.deactivate()
99 else:
100 b.activate()
101 w.redraw()
102
103
104 def make_window():
105
106 global leftb, rightb, topb, bottomb, insideb, overb, inactb, w, b
107
108 window = Fl_Window(400,400)
109 w = window
110 window.color(FL_WHITE)
111 b = Fl_Button(140,160,120,120,"Image w/Alpha")
112
113 rgb = None
114 dergb = None
115
116 make_image()
117 rgb = Fl_RGB_Image(image, width, height,4)
118 print(sys.getrefcount(rgb)-1)
119 dergb = rgb.copy()
120 print(sys.getrefcount(dergb)-1)
121 dergb.inactive()
122
123 b.image(rgb)
124 b.deimage(dergb)
125
126 leftb = Fl_Toggle_Button(25,50,50,25,"left")
127 leftb.callback(button_cb)
128
129 rightb = Fl_Toggle_Button(75,50,50,25,"right")
130 rightb.callback(button_cb)
131
132 topb = Fl_Toggle_Button(125,50,50,25,"top")
133 topb.callback(button_cb)
134
135 bottomb = Fl_Toggle_Button(175,50,50,25,"bottom");
136 bottomb.callback(button_cb)
137
138 insideb = Fl_Toggle_Button(225,50,50,25,"inside")
139 insideb.callback(button_cb)
140
141 overb = Fl_Toggle_Button(25,75,100,25,"text over")
142 overb.callback(button_cb)
143
144 inactb = Fl_Toggle_Button(125,75,100,25,"inactive")
145 inactb.callback(button_cb)
146
147 window.end()
148
149 return window
150
151 window = make_window()
152
153 window.resizable(window)
154
155 window.show(len(sys.argv), sys.argv)
156 #window.show()
157
158 Fl.run()