1
2
3
4
5
6
7
8
9
10
11
12
13
14 import Tkinter, Numeric
15 import Slider, ColorWheel, ColorChooser, colorTool
16 from EventHandler import CallbackFunctions
17
18
20 """Class for a material editor"""
21
22 property = [ 'ambient', 'diffuse', 'specular', 'emission' ]
23
25 """Implement callback functions"""
26
27 if type(event) == type(0.0):
28 for f in self.callbacks:
29 f('shininess', event)
30 else:
31 tkrgb = self.colorChooser.hsWheel.Get(mode='TkRGB')
32 c = self.currentComponent.get()
33 self.mat[c] = self.colorChooser.hsWheel.Get(mode='RGB')[:3]
34 self.colw[c].config( background = tkrgb )
35 for f in self.callbacks:
36 f(self.property[c], self.mat[c])
37
38
40 """Set the wheel cursor to the color of the current component"""
41 c = self.currentComponent.get()
42 self.colorChooser.Set(self.mat[c], 'RGB')
43
44
45 - def Set(self, ambi=None, diff=None, spec=None, emis=None, shini=None,
46 mode = 'RGB'):
77
78
79 - def __init__(self, root=None, colorChooser=None):
80
81 CallbackFunctions.__init__(self)
82
83 self.frame = Tkinter.Frame(root, relief=Tkinter.RIDGE, borderwidth=3)
84 self.mat = Numeric.ones( (4,3), 'f')
85 self.currentComponent = Tkinter.IntVar()
86 self.currentComponent.set(0)
87 self.colw = [0,]*4
88 width = 9
89 self.colw[0] = Tkinter.Radiobutton(self.frame, text='Ambient',
90 variable = self.currentComponent, value=0,
91 command=self.RestoreColor, relief = Tkinter.SUNKEN,
92 width=width, borderwidth=3,
93 background = '#FFFFFF', foreground = '#000000', )
94 self.colw[0].grid(row=0,column=0)
95 self.colw[1] = Tkinter.Radiobutton(self.frame, text='Diffuse',
96 value=1, variable = self.currentComponent,
97 command=self.RestoreColor, borderwidth=3,
98 width=width, relief = Tkinter.SUNKEN,
99 background = '#FFFFFF', foreground = '#000000' )
100 self.colw[1].grid(row=1,column=0)
101 self.colw[2] = Tkinter.Radiobutton(self.frame, text='Specular',
102 value=2, variable = self.currentComponent,
103 command=self.RestoreColor, relief = Tkinter.SUNKEN,
104 width=width, borderwidth=3,
105 background = '#FFFFFF', foreground = '#000000' )
106 self.colw[2].grid(row=0,column=1)
107 self.colw[3] = Tkinter.Radiobutton(self.frame, text='Emissive',
108 value=3, variable = self.currentComponent,
109 command=self.RestoreColor, relief = Tkinter.SUNKEN,
110 width=width, borderwidth=3,
111 background = '#FFFFFF', foreground = '#000000')
112 self.colw[3].grid(row=1,column=1)
113
114 self.shini = Slider.Slider(self.frame, label='Shininess', immediate=0,
115 minval=0.0, maxval = 128.0, init=30.0)
116 self.shini.frame.grid(row=2,column=0,columnspan=2)
117 self.shini.AddCallback(self.Callbacks)
118
119 if not colorChooser:
120 self.colorChooser = ColorChooser.ColorChooser(self.frame)
121 self.colorChooser.frame.grid(row=3, column=0, columnspan=2)
122 else:
123 self.colorChooser = colorChooser
124 self.colorChooser.AddCallback(self.Callbacks)
125
126
128 """Class for a light source color editor"""
129
130 property = [ 'ambient', 'diffuse', 'specular' ]
131
133 """Implement callback functions"""
134
135 tkrgb = self.colorChooser.hsWheel.Get(mode='TkRGB')
136 c = self.currentComponent.get()
137 self.mat[c] = self.colorChooser.hsWheel.Get(mode='RGB')[:3]
138 self.colw[c].config( background = tkrgb )
139 for f in self.callbacks:
140 f(self.property[c], self.mat[c])
141
142
144 """Set the wheel cursor to the color of the current component"""
145 c = self.currentComponent.get()
146 self.colorChooser.Set(self.mat[c], 'RGB')
147
148
149 - def Set(self, ambi=None, diff=None, spec=None, mode = 'RGB'):
174
175
176 - def __init__(self, root=None, colorChooser=None):
177
178 CallbackFunctions.__init__(self)
179
180 self.frame = Tkinter.Frame(root, relief=Tkinter.RIDGE, borderwidth=3)
181 self.mat = Numeric.ones( (3,3), 'f')
182 self.currentComponent = Tkinter.IntVar()
183 self.currentComponent.set(0)
184 self.colw = [0,]*4
185 width = 9
186 self.colw[0] = Tkinter.Radiobutton(self.frame, text='Ambient',
187 value=0, variable = self.currentComponent,
188 command=self.RestoreColor, relief = Tkinter.SUNKEN,
189 width=width, borderwidth=3,
190 background = '#FFFFFF', foreground = '#000000', )
191 self.colw[0].grid(row=0,column=0)
192 self.colw[1] = Tkinter.Radiobutton(self.frame, text='Diffuse',
193 value=1, variable = self.currentComponent,
194 command=self.RestoreColor, borderwidth=3,
195 width=width, relief = Tkinter.SUNKEN,
196 background = '#FFFFFF', foreground = '#000000' )
197 self.colw[1].grid(row=1,column=0)
198 self.colw[2] = Tkinter.Radiobutton(self.frame, text='Specular',
199 value=2, variable = self.currentComponent,
200 command=self.RestoreColor, relief = Tkinter.SUNKEN,
201 width=width, borderwidth=3,
202 background = '#FFFFFF', foreground = '#000000' )
203 self.colw[2].grid(row=0,column=1)
204
205 if not colorChooser:
206 self.colorChooser = ColorChooser.ColorChooser(self.frame)
207 self.colorChooser.frame.grid(row=3, column=0, columnspan=2)
208 else:
209 self.colorChooser = colorChooser
210 self.colorChooser.AddCallback(self.Callbacks)
211
212
213 if __name__ == '__main__':
214 root = Tkinter.Tk()
215 root.title( 'Material Editor' )
216 me = MaterialEditor(root)
217 me.frame.pack()
218
219 lce = LightColorEditor(root)
220 lce.frame.pack()
221