1 try:
2 import Tkinter
3
4 from scenario.director import Director
5 from scenario.gui import DirectorGUI
6 from scenario.actor import Actor
7
8 from mglutil.util.callback import CallbackFunction
9
10 from DejaVu.Geom import Geom
11 from DejaVu.Camera import Camera
12 from DejaVu.Light import Light
13 from DejaVu.Clip import ClippingPlane
14 from DejaVu.Viewer import SetCurrentObjectEvent, SetCurrentCameraEvent, SetCurrentLightEvent, SetCurrentClipEvent
15
16 from actor import RedrawActor, getAnimatableAttributes
17
19 """Class binding a DejaVu Viewer to a Scenario Director """
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
43
44
46 if hasattr(vi, 'director'):
47 raise RuntimeError, 'Viewer already has an director'
48
49 director = Director()
50 dg = DirectorGUI(director)
51 dg.root.protocol('WM_DELETE_WINDOW', dg.root.withdraw)
52 self.setDirector(vi, director)
53
54
56 vi.director = director
57
58
59 director.needsRedraw = False
60
61
62
63
64 director.gui.setDuration(50)
65
66
67
68 self.animObjMenuB = menuB = Tkinter.Menubutton(
69 vi.GUI.inheritF, text='Animate', relief='raise' )
70 menuB.menu = Tkinter.Menu(menuB)
71 menuB['menu'] = menuB.menu
72 menuB.pack(fill='x')
73
74
75 self.animCamMenuB = menuB = Tkinter.Menubutton(
76 vi.GUI.CameraProp, text='Animate', relief='raise' )
77 menuB.menu = Tkinter.Menu(menuB)
78 menuB['menu'] = menuB.menu
79 menuB.pack(fill='x')
80
81
82 self.animLightMenuB = menuB = Tkinter.Menubutton(
83 vi.GUI.LightProp, text='Animate', relief='raise' )
84 menuB.menu = Tkinter.Menu(menuB)
85 menuB['menu'] = menuB.menu
86 menuB.pack(fill='x')
87
88
89 self.animClipMenuB = menuB = Tkinter.Menubutton(
90 vi.GUI.ClipProp, text='Animate', relief='raise' )
91 menuB.menu = Tkinter.Menu(menuB)
92 menuB['menu'] = menuB.menu
93 menuB.pack(fill='x')
94
95
96 func = self.setCurrentObjectAttrList_cb
97 vi.registerListener(SetCurrentObjectEvent, func)
98 vi.registerListener(SetCurrentCameraEvent, func)
99 vi.registerListener(SetCurrentLightEvent, func)
100 vi.registerListener(SetCurrentClipEvent, func)
101
102
103 self.setCurrentObjectAttrList(vi.currentObject)
104 self.setCurrentObjectAttrList(vi.currentCamera)
105 self.setCurrentObjectAttrList(vi.currentClip)
106 self.setCurrentObjectAttrList(vi.currentLight)
107
108
112
113
115
116 if not hasattr(object, 'animatableProps'):
117 object.animatableProps = getAnimatableAttributes(object)
118 if not hasattr(object, 'animatedProperties'):
119 object.animatedProperties = {}
120
121 self.createCheckbuttons(object)
122
123
156
157
166
167
169
170 actor = object.animatedProperties[object.name+'.'+propname]
171 self.vi.director.deleteActor(actor)
172 del object.animatedProperties[object.name+'.'+propname]
173
174 - def createActor(self, object, propname, variable = None):
175
176 descr = object.animatableProps[0][propname]
177
178
179 actorClass, args, kw = descr['actor']
180 actor = actorClass( *(propname, object)+args, **kw )
181 actor.guiVar = variable
182 object.animatedProperties[object.name+'.'+propname] = actor
183 object.viewer.director.addActor(actor)
184
185
186
187 except ImportError:
188 import traceback
189 traceback.print_exc()
190 traceback.print_stack()
191 print 'WARNING: failed to import package scenario'
192