From 7a871722abfc7968d49e2cf28dd410bd97a69095 Mon Sep 17 00:00:00 2001 From: Vilem Duha <vilem.duha@gmail.com> Date: Tue, 20 Jul 2021 15:09:44 +0200 Subject: [PATCH] BlenderKit: close popup menu when it makes sense after running an operator --- blenderkit/paths.py | 2 ++ blenderkit/search.py | 8 ++++++++ blenderkit/ui_panels.py | 2 ++ 3 files changed, 12 insertions(+) diff --git a/blenderkit/paths.py b/blenderkit/paths.py index b9847be29..e074d966f 100644 --- a/blenderkit/paths.py +++ b/blenderkit/paths.py @@ -97,6 +97,8 @@ def get_categories_filepath(): return os.path.join(tempdir, 'categories.json') dirs_exist_dict = {}#cache these results since this is used very often +# this causes the function to fail if user deletes the directory while blender is running, +# but comes back when blender is restarted. def get_temp_dir(subdir=None): user_preferences = bpy.context.preferences.addons['blenderkit'].preferences diff --git a/blenderkit/search.py b/blenderkit/search.py index d8344aca7..b58dd28db 100644 --- a/blenderkit/search.py +++ b/blenderkit/search.py @@ -1458,6 +1458,12 @@ class SearchOperator(Operator): bl_description = "Search online for assets" bl_options = {'REGISTER', 'UNDO', 'INTERNAL'} + esc: BoolProperty(name="Escape window", + description="Escape window right after start", + default=False, + options={'SKIP_SAVE'} + ) + own: BoolProperty(name="own assets only", description="Find all own assets", default=False) @@ -1506,6 +1512,8 @@ class SearchOperator(Operator): def execute(self, context): # TODO ; this should all get transferred to properties of the search operator, so sprops don't have to be fetched here at all. + if self.esc: + bpy.ops.view3d.close_popup_button('INVOKE_DEFAULT') sprops = utils.get_search_props() if self.author_id != '': sprops.search_keywords = '' diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py index 292d83590..bc20169f4 100644 --- a/blenderkit/ui_panels.py +++ b/blenderkit/ui_panels.py @@ -1206,6 +1206,7 @@ def draw_asset_context_menu(layout, context, asset_data, from_panel=False): op.author_id = author_id op = layout.operator('view3d.blenderkit_search', text='Search Similar') + op.esc = True op.tooltip = 'Search for similar assets in the library' # build search string from description and tags: op.keywords = asset_data['name'] @@ -1721,6 +1722,7 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties): op.url = url op = button_row.operator('view3d.blenderkit_search', text="Find Assets By Author") + op.esc = True op.keywords = '' op.author_id = self.asset_data['author']['id'] -- GitLab