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 as published by the Free Software Foundation either 13# version 2 of the License, or (at your option) any later version. 14# 15# This library is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18# Library General Public License for more details. 19# 20# You should have received a copy of the GNU Library General Public 21# License along with this library if not, write to the Free Software 22# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 23# USA. 24# 25# Please report all bugs and problems to "pyfltk-user@lists.sourceforge.net". 26# 27 28from fltk import * 29from math import * 30import sys 31 32 33width = 100 34height = 100 35image = [] 36 37def make_image(): 38 #image = new uchar[4*width*height]; 39 #uchar *p = image; 40 p = image 41 index = 0 42 43 y = 0 44 while y < height: 45 dy = float(y)/(height-1) 46 x = 0 47 while x < width: 48 dx = float(x)/(width-1) 49 p.append(int(255*((1.0-dx)*(1.0-dy)))) 50 index = index+1 51 p.append(int(255*((1.0-dx)*dy))) 52 index = index+1 53 p.append(int(255*(dx*dy))) 54 index = index+1 55 dx = dx-0.5 56 dy = dy-0.5 57 alpha = int(255*sqrt(dx*dx+dy*dy)) 58 if alpha < 255: 59 p.append(alpha) 60 else: 61 p.append(255) 62 index = index+1 63 dy = dy+0.5 64 x = x+1 65 y = y+1 66 print("make_image done") 67 return None 68 69 70#globals 71leftb = None 72rightb = None 73topb = None 74bottomb = None 75insideb = None 76overb = None 77inactb = None 78b = None 79w = None 80 81def button_cb(ptr): 82 global b, w 83 84 i = 0 85 if leftb.value(): 86 i = i + FL_ALIGN_LEFT 87 if rightb.value(): 88 i = i + FL_ALIGN_RIGHT 89 if topb.value(): 90 i = i + FL_ALIGN_TOP 91 if bottomb.value(): 92 i = i + FL_ALIGN_BOTTOM 93 if insideb.value(): 94 i = i + FL_ALIGN_INSIDE 95 if overb.value(): 96 i = i + FL_ALIGN_TEXT_OVER_IMAGE 97 b.align(i) 98 if inactb.value(): 99 b.deactivate() 100 else: 101 b.activate() 102 w.redraw() 103 104 105def make_window(): 106 107 global leftb, rightb, topb, bottomb, insideb, overb, inactb, w, b 108 109 window = Fl_Window(400,400) 110 w = window 111 window.color(FL_WHITE) 112 b = Fl_Button(140,160,120,120,"Image w/Alpha") 113 114 rgb = None 115 dergb = None 116 117 make_image() 118 rgb = Fl_RGB_Image(image, width, height,4) 119 print(sys.getrefcount(rgb)-1) 120 dergb = rgb.copy() 121 print(sys.getrefcount(dergb)-1) 122 dergb.inactive() 123 124 b.image(rgb) 125 b.deimage(dergb) 126 127 leftb = Fl_Toggle_Button(25,50,50,25,"left") 128 leftb.callback(button_cb) 129 130 rightb = Fl_Toggle_Button(75,50,50,25,"right") 131 rightb.callback(button_cb) 132 133 topb = Fl_Toggle_Button(125,50,50,25,"top") 134 topb.callback(button_cb) 135 136 bottomb = Fl_Toggle_Button(175,50,50,25,"bottom"); 137 bottomb.callback(button_cb) 138 139 insideb = Fl_Toggle_Button(225,50,50,25,"inside") 140 insideb.callback(button_cb) 141 142 overb = Fl_Toggle_Button(25,75,100,25,"text over") 143 overb.callback(button_cb) 144 145 inactb = Fl_Toggle_Button(125,75,100,25,"inactive") 146 inactb.callback(button_cb) 147 148 window.end() 149 150 return window 151 152window = make_window() 153 154window.resizable(window) 155 156window.show(len(sys.argv), sys.argv) 157#window.show() 158 159Fl.run() 160