def getNewActors(self): # return a dictionary containing all available actors that are not in the # scenario's director. vi = self.application director = self._director() autotrackDict = director.autotrackDict if not vi.eventListeners.has_key(AddObjectEvent): func = self.getNewActor_cb vi.registerListener(AddObjectEvent, func) newDict = {} actornames = map(lambda x: x.name, director.actors[1:]) allobjects = [] for object in vi.rootObject.AllObjects(): ## if object.name != "root": ## v = hasattr(object, 'vertexSet') ## f = hasattr(object, 'faceSet') ## if v and f: ## numv = len(object.vertexSet) ## numf = len(object.faceSet) ## if numv == numf == 0: ## continue ## elif v: ## numv = len(object.vertexSet) ## if numv == 0: ## continue ## if not object.visible: ## continue if object.listed: # FIX THIS: we probably do not need to track all of the objects (too many actors), # currently, do not include Viewer's objects under 'root|misc' and 'selection' objects if object.fullName.find("misc") < 0 and object.fullName.find("selection") < 0: allobjects.append(object) for c in vi.cameras: allobjects.append(c) for lt in vi.lights: if lt.enabled: allobjects.append(lt) if vi.activeClippingPlanes > 0: allobjects.append(vi.currentClip) #for cp in vi.clipP: # if cp.enabled: # allobjects.append(cp) for object in allobjects: #self.setCurrentObjectAttrList(object) props = getAnimatableAttributes(object)[0] #print "object : ", object, props.keys() for propname in props.keys(): descr = props[propname] actorname = getActorName(object, propname) if not autotrackDict.has_key(actorname): if not actorname in actornames: # actor 'actorname' does not exist - create it and add to # newDict actorClass, args, kw = descr['actor'] actor = actorClass( *(propname, object)+args, **kw ) actor.scenario = self newDict[actorname] = actor return newDict
def deleteActor(self, object, propname): # delete the actor for object.name actorname = getActorName(object, propname) #actor = object.animatedProperties[actorname] actor = self.animatedProperties[actorname] if actor.object != object: return self._director().deleteActor(actor) #del object.animatedProperties[actorname] del self.animatedProperties[actorname]
def getActor(object, propname): """ create an actor from a DejaVu object instance and a property name. Actor <- getActor(object, propname) object is an instance of a DejaVu obbject (e.g. Geom, Camera, etc) propname is the name of the attribute in object that willbe animated """ animatableProps = getAnimatableAttributes(object) if not animatableProps[0].has_key(propname): print "DejaVu.scenarioInterface.getActor: cannot create %s actor for object:" % (propname,), object return None descr = animatableProps[0][propname] actorname = getActorName(object, propname) actorClass, args, kw = descr['actor'] actor = actorClass( *(propname, object)+args, **kw ) return actor
def createCheckbuttons(self, object): # get menu button if isinstance(object, Geom): menuB = self.animObjMenuB elif isinstance(object, Camera): menuB = self.animCamMenuB elif isinstance(object, Light): menuB = self.animLightMenuB elif isinstance(object, ClippingPlane): menuB = self.animClipMenuB else: print 'no menu button for object:', object, object.__class__ return # clear menu's content menuB.menu.delete(0, 'end') # get list of properties p1 = object.animatableProps[0].keys() p1.sort() propnames = p1 #p2 = object.animatableProps[1].keys() #p2.sort() #propnames = p1+p2 # get dict of currently animated properties for this object #aprop = object.animatedProperties aprop = self.animatedProperties for i, name in enumerate(propnames): var = Tkinter.IntVar() actorname = getActorName(object, name) if aprop.has_key(actorname): var.set(1) aprop[actorname].guiVar = var cb = CallbackFunction( self.toggleAnimatePropVar, name, var, object) menuB.menu.add_checkbutton( label=name, command=cb, variable = var) menuB.menu.add_separator() cb = CallbackFunction(self.actorFromFile_cb, propnames, object) menuB.menu.add_command( label="Create Actor From File", command=cb)
def getNewActor_cb(self, event): object = event.object if object.listed: if hasattr(object, "fullName"): if object.fullName.find("selection") >= 0: return vi = self.application director = self._director() autotrackDict = director.autotrackDict props = getAnimatableAttributes(object)[0] #print "object : ", object, props.keys() for propname in props.keys(): descr = props[propname] actorname = getActorName(object, propname) if not autotrackDict.has_key(actorname): actorClass, args, kw = descr['actor'] actor = actorClass( *(propname, object)+args, **kw ) actor.scenario = self autotrackDict[actorname] = actor if actor.hasGetFunction: val = actor.getValueFromObject() else: val = None
def createActor(self, object, propname, variable = None, check = True, addToDirector = True, actorData=None, redraw = True, valueGenerator = None): #if not object.hasBeenCurrent : # self.setCurrentObjectAttrList(object) #if not hasattr(object, 'animatedProperties'): # object.animatedProperties = {} if not hasattr(object, 'animatableProps'): object.animatableProps = getAnimatableAttributes(object) # create an actor for object.propname descr = object.animatableProps[0][propname] actorname = getActorName(object, propname) director = self._director() newactor = True if check: for i, a in enumerate(director.actors): if a.name == actorname: text = "Actor %s exists. Do you want to overwrite it?\n"%actorname d = SimpleDialog(director.gui.root, text=text, buttons=["Yes", "No"], default=1, title="Overwrite Actor Dialog") result = d.go() if result == 1: return None else: newactor = False # actorind = i break #create the actor actorClass, args, kw = descr['actor'] if valueGenerator is not None: kw['interp'] = valueGenerator if actorData is not None: from scenario.actor import FileActor actor = FileActor(*(propname, object, actorClass, actorData)+args, **kw) actorname = actor.name else: actor = actorClass( *(propname, object)+args, **kw ) actor.scenario = self #object.animatedProperties[actorname] = actor self.animatedProperties[actorname] = actor if not newactor: # director already has an actor with name "actorname", # and the user wishes to overwrite it # replace existing actor whith the new one oldactor = director.actors.pop(actorind) director.gui.deleteActor(oldactor) director.actors.insert(actorind, actor) actor._director = weakref.ref(director) posy = oldactor._posy director.gui.drawActor(actor, posy) if oldactor.guiVar: variable = oldactor.guiVar else: if addToDirector: # add actor to the director director.addActor(actor, redraw) if variable: actor.guiVar = variable return actor