def activeContainerChanged(self, oldContainer, newContainer): n1 = "None" n2 = "None" if oldContainer: n1 = oldContainer.Name if newContainer: n2 = newContainer.Name if oldContainer is None: #happens when creating new document return chain_from, chain_to = GT.getContainerRelativePath(oldContainer, newContainer) for cnt in chain_from[::-1]: try: gc = GenericContainer(cnt) gc.ViewObject.call(gc.ViewObject.activationChanged, oldContainer, newContainer, event= -1) except Exception as err: App.Console.PrintError(u"Error deactivating container '{cnt}': {err}".format(cnt= cnt.Label, err= err.message)) self.leaveContainer(cnt) for cnt in chain_to: try: gc = GenericContainer(cnt) gc.ViewObject.call(gc.ViewObject.activationChanged, oldContainer, newContainer, event= +1) except Exception as err: App.Console.PrintError(u"Error activating container '{cnt}': {err}".format(cnt= cnt.Label, err= err.message)) self.enterContainer(cnt) self.updateVPs()
def updateDeps(self, selfobj, check_only=False): """update PlacementLinks to match with container path""" toleave, toenter = Containers.getContainerRelativePath( Containers.getContainer(selfobj.Base), Containers.getContainer(selfobj)) leave_deps = [] if selfobj.UseForwardPlacements: for cnt in toleave[::-1]: if hasattr(cnt, 'Placement'): leave_deps.append(cnt) enter_deps = [] if selfobj.UseInversePlacements: for cnt in toenter: if hasattr(cnt, 'Placement'): enter_deps.append(cnt) if selfobj.PlacementLinks != leave_deps or not hasattr( self, '_implicit_deps') or self._implicit_deps != enter_deps: if check_only: App.Console.PrintError( u"Placement dependencies of {feat} are out of sync!\n". format(feat=selfobj.Name)) else: selfobj.PlacementLinks = leave_deps self._implicit_deps = enter_deps selfobj.touch() for dep in enter_deps: for (prop, expr) in dep.ExpressionEngine: if prop.startswith('Placement'): raise GhostError( u'{dep} has expression bound to its placement. {ghost} uses it, but is inside of the container, so it can\'t be properly recomputed.' .format(dep=dep.Label, ghost=selfobj.Label))
def activeContainerChanged(self, oldContainer, newContainer): n1 = "None" n2 = "None" if oldContainer: n1 = oldContainer.Name if newContainer: n2 = newContainer.Name print(u"container changed from {c1} to {c2}".format(c1= n1, c2= n2)) if oldContainer is None: #happens when creating new document return chain_from, chain_to = GT.getContainerRelativePath(oldContainer, newContainer) for cnt in chain_from[::-1]: try: gc = GenericContainer(cnt) gc.ViewObject.call(gc.ViewObject.activationChanged, oldContainer, newContainer, event= -1) except Exception as err: App.Console.PrintError(u"Error deactivating container '{cnt}': {err}".format(cnt= cnt.Label, err= err.message)) self.leaveContainer(cnt) for cnt in chain_to: try: gc = GenericContainer(cnt) gc.ViewObject.call(gc.ViewObject.activationChanged, oldContainer, newContainer, event= +1) except Exception as err: App.Console.PrintError(u"Error activating container '{cnt}': {err}".format(cnt= cnt.Label, err= err.message)) self.enterContainer(cnt) self.updateVPs()
def getTransform(self, selfobj): self.updateDeps(selfobj, check_only=True) toleave, toenter = Containers.getContainerRelativePath( Containers.getContainer(selfobj.Base), Containers.getContainer(selfobj)) self.path = (toleave, toenter) #save for future reference... transform = App.Placement() if selfobj.UseForwardPlacements: for cnt in toleave[::-1]: if hasattr(cnt, 'Placement'): transform = cnt.Placement.multiply(transform) if selfobj.UseInversePlacements: for cnt in toenter: if hasattr(cnt, 'Placement'): transform = cnt.Placement.inverse().multiply(transform) return transform