1 title = 'Color spectrum demonstration'
3 # Import Pmw from this directory tree.
5 sys.path[:0] = ['../../..']
12 def __init__(self, parent):
13 parent = Tkinter.Frame(parent)
14 parent.pack(padx=10, pady=10, fill='both', expand=1)
17 self.canvas = Tkinter.Canvas(parent,
18 width = self.width, height = self.height)
19 self.canvas.grid(row = 0, column = 0, columnspan = 2, sticky = 'news')
21 self.numColors = Pmw.EntryField(parent,
23 label_text = 'Number of colors:',
26 command = Pmw.busycallback(self.execute))
27 self.numColors.grid(row = 1, column = 0, sticky = 'ew')
29 self.correction = Pmw.EntryField(parent,
31 label_text = 'Correction:',
34 command = Pmw.busycallback(self.execute))
35 self.correction.grid(row = 1, column = 1, sticky = 'ew')
37 self.saturation = Pmw.EntryField(parent,
39 label_text = 'Saturation:',
42 command = Pmw.busycallback(self.execute))
43 self.saturation.grid(row = 2, column = 0, sticky = 'ew')
45 self.intensity = Pmw.EntryField(parent,
47 label_text = 'Intensity:',
50 command = Pmw.busycallback(self.execute))
51 self.intensity.grid(row = 2, column = 1, sticky = 'ew')
53 self.extraOrange = Pmw.EntryField(parent,
55 label_text = 'Emphasize orange (0 or 1):',
56 validate = {'validator' : 'numeric', 'min' : 0, 'max' : 1},
58 command = Pmw.busycallback(self.execute))
59 self.extraOrange.grid(row = 3, column = 0, sticky = 'ew')
61 self.text = Pmw.EntryField(parent,
65 command = Pmw.busycallback(self.execute))
66 self.text.grid(row = 4, column = 0, sticky = 'ew')
68 self.brightness = Pmw.EntryField(parent,
70 label_text = 'Brightness:',
73 command = Pmw.busycallback(self.execute))
74 self.brightness.grid(row = 3, column = 1, sticky = 'ew')
76 self.radiobuttons = Pmw.RadioSelect(parent,
77 command = Pmw.busycallback(self.radio_cb),
79 self.radiobuttons.grid(row = 4, column = 1)
80 self.radiobuttons.add('Use saturation\nand intensity')
81 self.radiobuttons.add('Use\nbrightness')
83 parent.grid_columnconfigure(0, weight = 1)
84 parent.grid_columnconfigure(1, weight = 1)
85 parent.grid_rowconfigure(0, weight = 1)
87 Pmw.alignlabels((self.numColors, self.saturation, self.extraOrange))
88 Pmw.alignlabels((self.correction, self.intensity, self.brightness))
90 # Set initial values for all entries.
91 self.numColors.setentry('64')
92 self.correction.setentry('1.0')
93 self.saturation.setentry('1.0')
94 self.intensity.setentry('1.0')
95 self.extraOrange.setentry('1')
96 self.brightness.setentry('0.7')
97 self.text.setentry('This is a test')
98 self.radiobuttons.invoke('Use saturation\nand intensity')
102 def radio_cb(self, value):
107 numColors = string.atoi(self.numColors.get())
108 correction = string.atof(self.correction.get())
109 saturation = string.atof(self.saturation.get())
110 intensity = string.atof(self.intensity.get())
111 extraOrange = string.atof(self.extraOrange.get())
112 brightness = string.atof(self.brightness.get())
114 self.numColors.bell()
118 self.numColors.bell()
121 self.canvas.delete('all')
123 colorList = Pmw.Color.spectrum(
124 numColors, correction, saturation, intensity, extraOrange)
125 extent = 360.0 / numColors
128 (self.radiobuttons.getcurselection() == 'Use\nbrightness')
131 # Special case circle, since create_arc does not work when
133 background = colorList[0]
135 background = Pmw.Color.changebrightness(
136 self.canvas, background, brightness)
137 self.canvas.create_oval(10, 10, self.width - 10, self.height - 10,
138 fill = background, outline = background)
140 for index in range(numColors):
141 start = index * extent - extent / 2
142 background = colorList[index]
144 background = Pmw.Color.changebrightness(
145 self.canvas, background, brightness)
146 self.canvas.create_arc(10, 10, self.width - 10, self.height - 10,
147 start = start, extent = extent,
148 fill = background, outline = background)
150 text = self.text.get()
151 self.canvas.create_text(self.width / 2, self.height / 3, text = text)
152 self.canvas.create_text(self.width / 2, self.height / 2, text = text)
153 self.canvas.create_text(self.width / 2, 2 * self.height / 3, text = text)
155 ######################################################################
157 # Create demo in root window for testing.
158 if __name__ == '__main__':
163 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
164 exitButton.pack(side = 'bottom')