Debian Codegraph @

fltk/test/color_chooser.py

raw symbols SCIP
1 # Color chooser test program for the Python port of
2 # the Fast Light Tool Kit (pyFLTK).
3 #
4 # FLTk is Copyright 1998-2003 by Bill Spitzak and others.
5 # pyFLTK is Copyright 2003 by Andreas Held
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Library General Public
9 # License, version 2.0 as published by the Free Software Foundation.
10 #
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Library General Public License for more details.
15 #
16 # You should have received a copy of the GNU Library General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 # USA.
20 #
21 # Please report all bugs and problems to "[email protected]".
22 #
23
24 from fltk import *
25 import sys
26
27 width = 75
28 height = 75
29 image = []
30
31 def make_image():
32 global image
33 for y in range(0, height, 1):
34 Y = (1.0 *y)/(height-1)
35 for x in range(0, width, 1):
36 X = (1.0 * x)/(width-1)
37 image.append(int((255*((1-X)*(1-Y))))) # red in upper-left
38 image.append(int((255*((1-X)*Y)))) # // green in lower-left
39 image.append(int((255*(X*Y)))) # // blue in lower-right
40
41 class Pens(Fl_Box):
42 def __init__(self, X, Y, W, H, L):
43 Fl_Box.__init__(self, X,Y,W,H,L)
44
45 def draw(self):
46 #// use every color in the gray ramp:
47 i = 0
48 while i < 3*8:
49 fl_color(FL_GRAY_RAMP+i)
50 fl_line(self.x()+i, self.y(), self.x()+i, self.y()+self.h())
51 i += 1
52
53 c = FL_GRAY
54 fullcolor_cell = FL_FREE_COLOR
55
56 def cb1(ptr, box):
57 global c
58 c = fl_show_colormap(c)
59 box.color(c)
60 parent = box.parent()
61 parent.redraw()
62
63 def cb2(ptr, box):
64 global c
65 r = 0
66 g = 0
67 b = 0
68 (r, g, b) = Fl.get_color(c)
69 (status, r, g, b) = fl_color_chooser("New color:", r,g,b)
70 if status == 0:
71 return None
72 c = fullcolor_cell
73 Fl.set_color(fullcolor_cell, r, g, b)
74 box.color(fullcolor_cell)
75 parent = box.parent()
76 parent.redraw()
77
78
79 Fl.set_color(fullcolor_cell,145,159,170)
80 window = Fl_Window(400,400)
81
82 box = Fl_Box(50,50,300,300)
83 box.box(FL_THIN_DOWN_BOX)
84 c = fullcolor_cell
85 box.color(c)
86
87 b1 = Fl_Button(130,120,140,30,"fl_show_colormap")
88 b1.callback(cb1, box) # b1.callback(cb1,&box)
89
90 b2 = Fl_Button(130,160,140,30,"fl_choose_color")
91 b2.callback(cb2,box)
92
93 image_box = Fl_Box(140,200,120,120,"")
94 make_image()
95
96 #i = Fl_Image(image, width, height)
97 i = Fl_RGB_Image(image, width, height)
98 i.label(image_box)
99
100 b = Fl_Box(140,335,120,0,"Example of fl_draw_image()")
101
102 p = Pens(80,200,3*8,120,"lines")
103 p.align(FL_ALIGN_TOP)
104 p.redraw()
105
106 window.end()
107 window.show(len(sys.argv), sys.argv)
108 Fl.run()
109