def _onMetadataChanged(self, container: ContainerInterface, **kwargs: Any) -> None: """Triggered when any metadata changed in any container, but only handles it when the metadata of this node is changed. :param container: The container whose metadata changed. :param kwargs: Key-word arguments provided when changing the metadata. These are ignored. As far as I know they are never provided to this call. """ if container.getId() != self.container_id: return new_metadata = container.getMetaData() old_base_file = self.base_file if new_metadata["base_file"] != old_base_file: self.base_file = new_metadata["base_file"] if old_base_file in self.variant.materials: # Move in parent node. del self.variant.materials[old_base_file] self.variant.materials[self.base_file] = self old_material_type = self.material_type self.material_type = new_metadata["material"] old_guid = self.guid self.guid = new_metadata["GUID"] if self.base_file != old_base_file or self.material_type != old_material_type or self.guid != old_guid: # List of quality profiles could've changed. self.qualities = {} self._loadAll() # Re-load the quality profiles for this node. self.materialChanged.emit(self)
def _clearQueryCacheByContainer(self, container: ContainerInterface) -> None: # Remove all case-insensitive matches since we won't find those with the below "<=" subset check. # TODO: Properly check case-insensitively in the dict's values. for key in list(ContainerQuery.ContainerQuery.cache): if not key[0]: del ContainerQuery.ContainerQuery.cache[key] # Remove all cache items that this container could fall in. for key in list(ContainerQuery.ContainerQuery.cache): query_metadata = dict(zip(key[1::2], key[2::2])) if query_metadata.items() <= container.getMetaData().items(): del ContainerQuery.ContainerQuery.cache[key]
def addContainer(self, container: ContainerInterface) -> None: if container.getId() in self._containers: Logger.log("w", "Container with ID %s was already added.", container.getId()) return if hasattr(container, "metaDataChanged"): container.metaDataChanged.connect(self._onContainerMetaDataChanged) self.metadata[container.getId()] = container.getMetaData() self._containers[container.getId()] = container if container.getId() not in self.source_provider: self.source_provider[container.getId()] = None #Added during runtime. self._clearQueryCacheByContainer(container) self.containerAdded.emit(container)
def _clearQueryCacheByContainer(self, container: ContainerInterface) -> None: """Clear the query cache by using container type. This is a slightly smarter way of clearing the cache. Only queries that are of the same type (or without one) are cleared. """ # Remove all case-insensitive matches since we won't find those with the below "<=" subset check. # TODO: Properly check case-insensitively in the dict's values. for key in list(ContainerQuery.ContainerQuery.cache): if not key[0]: del ContainerQuery.ContainerQuery.cache[key] # Remove all cache items that this container could fall in. for key in list(ContainerQuery.ContainerQuery.cache): query_metadata = dict(zip(key[1::2], key[2::2])) if query_metadata.items() <= container.getMetaData().items(): del ContainerQuery.ContainerQuery.cache[key]
def addContainer(self, container: ContainerInterface) -> None: container_id = container.getId() if container_id in self._containers: return if hasattr(container, "metaDataChanged"): container.metaDataChanged.connect(self._onContainerMetaDataChanged) self.metadata[container_id] = container.getMetaData() self._containers[container_id] = container if container_id not in self.source_provider: self.source_provider[container_id] = None #Added during runtime. self._clearQueryCacheByContainer(container) # containerAdded is a custom signal and can trigger direct calls to its subscribers. This should be avoided # because with the direct calls, the subscribers need to know everything about what it tries to do to avoid # triggering this signal again, which eventually can end up exceeding the max recursion limit. # We avoid the direct calls here to make sure that the subscribers do not need to take into account any max # recursion problem. self._application.callLater(self.containerAdded.emit, container)
def _onMetadataChanged(self, container: ContainerInterface, **kwargs: Any) -> None: if container.getId() != self.container_id: return new_metadata = container.getMetaData() old_base_file = self.base_file if new_metadata["base_file"] != old_base_file: self.base_file = new_metadata["base_file"] if old_base_file in self.variant.materials: # Move in parent node. del self.variant.materials[old_base_file] self.variant.materials[self.base_file] = self old_material_type = self.material_type self.material_type = new_metadata["material"] old_guid = self.guid self.guid = new_metadata["GUID"] if self.base_file != old_base_file or self.material_type != old_material_type or self.guid != old_guid: # List of quality profiles could've changed. self.qualities = {} self._loadAll() # Re-load the quality profiles for this node. self.materialChanged.emit(self)
def addContainer(self, container: ContainerInterface) -> None: container_id = container.getId() if container_id in self._containers: Logger.log("w", "Container with ID %s was already added.", container_id) return if hasattr(container, "metaDataChanged"): container.metaDataChanged.connect(self._onContainerMetaDataChanged) self.metadata[container_id] = container.getMetaData() self._containers[container_id] = container if container_id not in self.source_provider: self.source_provider[container_id] = None #Added during runtime. self._clearQueryCacheByContainer(container) Logger.log("d", "Container [%s] added.", container_id) # containerAdded is a custom signal and can trigger direct calls to its subscribers. This should be avoided # because with the direct calls, the subscribers need to know everything about what it tries to do to avoid # triggering this signal again, which eventually can end up exceeding the max recursion limit. # We avoid the direct calls here to make sure that the subscribers do not need to take into account any max # recursion problem. self._application.callLater(self.containerAdded.emit, container)