Exemplo n.º 1
0
    def execute(self, context):
        print(f'do: {self.bl_idname}')

        asset = ASSETS[self.asset_id]
        CONTENT_CACHE.remove_content(asset.download_action)

        return {'FINISHED'}
Exemplo n.º 2
0
 def execute(self, context):
     print(f'do: {self.bl_idname}, {self.asset_id}')
     asset = ASSETS[self.asset_id]
     CONTENT_CACHE.async_get_content(
         asset.download_action,
         functools.partial(self.__on_fetched, context, asset))
     return {'FINISHED'}
Exemplo n.º 3
0
    def execute(self, context):
        # pylint: disable=too-many-locals

        preferences = get_preferences()

        max_search_result_count = preferences.asset_search_results_max_display_count

        query = context.scene.mmd_uuunyaa_tools_asset_search.query
        query_type = query.type
        query_text = query.text.lower()
        query_tags = query.tags
        query_is_cached = query.is_cached

        enabled_tag_names = {tag.name for tag in query_tags if tag.enabled}
        enabled_tag_count = len(enabled_tag_names)

        search_results: List[AssetDescription] = []
        search_results = [
            asset for asset in ASSETS.values()
            if (query_type in {AssetType.ALL.name, asset.type.name} and
                enabled_tag_count == len(asset.tag_names & enabled_tag_names)
                and query_text in asset.keywords and
                (Utilities.is_importable(asset) if query_is_cached else True))
        ]

        hit_count = len(search_results)
        update_time = to_int32(time.time_ns() >> 10)
        result = context.scene.mmd_uuunyaa_tools_asset_search.result
        result.count = min(max_search_result_count, hit_count)
        result.hit_count = hit_count
        result.asset_items.clear()
        result.update_time = update_time

        for asset in search_results[:max_search_result_count]:
            CONTENT_CACHE.async_get_content(
                asset.thumbnail_url,
                functools.partial(self._on_thumbnail_fetched, result,
                                  context.region, update_time, asset))

        tag_names = set()
        for asset in search_results:
            tag_names.update(asset.tag_names)

        query.is_updating = True
        try:
            query_tags.clear()
            query.tags_index = 0
            for tag_name in sorted(tag_names):
                tag = query_tags.add()
                tag.name = tag_name
                tag.enabled = tag_name in enabled_tag_names
        finally:
            query.is_updating = False

        return {'FINISHED'}
Exemplo n.º 4
0
    def execute(self, context):
        print(f'do: {self.bl_idname}')

        asset = ASSETS[self.asset_id]
        content = CONTENT_CACHE.try_get_content(asset.download_action)

        try:
            ImportActionExecutor.execute_import_action(
                asset, content.filepath if content is not None else None)
        except MessageException as ex:
            self.report(type={'ERROR'}, message=str(ex))

        return {'FINISHED'}
Exemplo n.º 5
0
    def get_asset_state(
        asset: AssetDescription
    ) -> Tuple[AssetState, Union[Content, None], Union[Task, None]]:
        if ASSETS.is_extracted(asset.id):
            return (AssetState.EXTRACTED, None, None)

        content = CONTENT_CACHE.try_get_content(asset.download_action)
        if content is not None:
            if content.state is Content.State.CACHED:
                return (AssetState.CACHED, content, None)

            if content.state is Content.State.FAILED:
                return (AssetState.FAILED, content, None)

        else:
            task = CONTENT_CACHE.try_get_task(asset.download_action)
            if task is None:
                return (AssetState.INITIALIZED, None, None)

            elif task.state in {Task.State.QUEUING, Task.State.RUNNING}:
                return (AssetState.DOWNLOADING, None, task)

        return (AssetState.UNKNOWN, None, None)
Exemplo n.º 6
0
 def is_importable(asset: AssetDescription) -> bool:
     return (ASSETS.is_extracted(asset.id) or CONTENT_CACHE.try_get_content(
         asset.download_action) is not None)
Exemplo n.º 7
0
 def execute(self, context):
     CONTENT_CACHE.delete_cache_folder()
     return {'FINISHED'}