def suspend(): global observerInstance global suspend_counter if not isRunning(): return Keeper(None) if suspend_counter == 0: App.removeDocumentObserver(observerInstance) suspend_counter += 1 return Keeper(_resume)
def stop(): global observerInstance if observerInstance is None: return App.removeDocumentObserver(observerInstance) observerInstance = None global timer timer.stop() timer = None
def containerAdded(self): App.removeDocumentObserver(self) for obj in self.new_objects: if Containers.canBeActive(obj): if self.target_container is not None: raise CommandError(self.command, "More than one container was created. I have no idea what to do! --Part-o-Magic") self.target_container = obj #if multiple objects had been created, pick one that is a container if self.target_container is None: self.target_container = self.new_objects[0] #return something... so that an error message is displayed. self.is_done = True self.command.Activated()
def makeObject(doc, type_id, name): import FreeCAD obs = Observer(doc) FreeCAD.addDocumentObserver(obs) try: obj = doc.addObject(type_id, name) finally: FreeCAD.removeDocumentObserver(obs) #some objects add extra objects automatically (e.g. Part makes an Origin). Can't prevent their creation. But can delete. for n in obs.new_objects: if n != obj.Name: doc.removeObject(n) return obj
def stop(): global observerInstance if observerInstance is None: return App.removeDocumentObserver(observerInstance) observerInstance = None global timer timer.stop() timer = None global suspend_counter suspend_counter = None
def containerAdded(self): App.removeDocumentObserver(self) for obj in self.new_objects: if Containers.canBeActive(obj): if self.target_container is not None: raise CommandError( self.command, "More than one container was created. I have no idea what to do! --Part-o-Magic" ) self.target_container = obj #if multiple objects had been created, pick one that is a container if self.target_container is None: self.target_container = self.new_objects[ 0] #return something... so that an error message is displayed. self.is_done = True self.command.Activated()
def slotStartSaveDocument(self, doc, value): print('calling save document...', doc.Label, value) if _saveObserver.instance() is None: App.removeDocumentObserver(self) return #if the document is deleted, remove the observer try: self.target_doc.__doc__ except: App.removeDocumentObserver(self) return if doc == self.target_doc: self.target_doc.before_save('slotStartSaveDocument')
def Deactivated(self): from plane import Grid as gr # from plane import DocObserver try: "workbench deactivated" if hasattr(FreeCADGui, "draftToolBar"): Gui.draftToolBar.Deactivated() if hasattr(FreeCADGui, "Snapper"): Gui.Snapper.hide() import draftutils.init_draft_statusbar as dsb dsb.hide_draft_statusbar() App.Console.PrintLog("Design456/Draft workbench deactivated.\n") # gr.removeGarbage(gr) self.planeShow.removeGarbage() del self.planeShow self.planeShow = None App.removeDocumentObserver(self.myDocObserver) self.myDocObserver = None return except Exception as exc: App.Console.PrintError(exc) App.Console.PrintError("Error: Draft deactivation failed\n")
def Deactivated(self): FreeCAD.removeDocumentObserver(self.docObserver) from .gui import AsmCmdManager for cmd in AsmCmdManager.getInfo().Types: cmd.workbenchDeactivated()
def Deactivated(self): "This function is executed when the workbench is deactivated" FreeCAD.removeDocumentObserver(self.obs) return
def Deactivated(self): import a2p_observers FreeCAD.removeDocumentObserver(a2p_observers.redoUndoObserver)
oneshot = DelayedExecute( (lambda doc=feature.Document: updateAllGhosts(doc)), delay=100) else: updateAllGhosts(feature.Document) elif prop_name == 'Placement': if not Containers.isContainer(feature): return if 'Restore' in feature.State: return onContainerPlacementChanged(feature) #stop old observer, if reloading this module if 'observer' in vars(): App.removeDocumentObserver(observer) observer = None #start obsrever observer = Observer() App.addDocumentObserver(observer) def updateAllGhosts(doc): for obj in doc.Objects: if not hasattr(obj, 'Proxy'): continue if hasattr(obj.Proxy, 'updateDeps'): try: obj.Proxy.updateDeps(obj) except Exception as err: App.Console.PrintError(
def stop(self): FreeCAD.removeDocumentObserver(self)