Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'blenderkit/search.py')
-rw-r--r--blenderkit/search.py46
1 files changed, 35 insertions, 11 deletions
diff --git a/blenderkit/search.py b/blenderkit/search.py
index 00f8eda0..e362a928 100644
--- a/blenderkit/search.py
+++ b/blenderkit/search.py
@@ -144,6 +144,26 @@ def update_assets_data(): # updates assets data on scene load.
# bpy.context.scene['assets used'][ad] = ad
+def purge_search_results():
+ ''' clean up search results on save/load.'''
+
+ s = bpy.context.scene
+
+ sr_props = [
+ 'search results',
+ 'search results orig',
+ ]
+ print('purge search')
+ asset_types = ['model', 'material', 'scene', 'hdr', 'brush']
+ for at in asset_types:
+ sr_props.append('bkit {at} search')
+ sr_props.append('bkit {at} search orig')
+ for sr_prop in sr_props:
+ if s.get(sr_prop):
+ print(sr_prop)
+ del (s[sr_prop])
+
+
@persistent
def scene_load(context):
'''
@@ -151,6 +171,7 @@ def scene_load(context):
Should (probably)also update asset data from server (after user consent)
'''
wm = bpy.context.window_manager
+ purge_search_results()
fetch_server_data()
categories.load_categories()
if not bpy.app.timers.is_registered(refresh_token_timer):
@@ -323,7 +344,7 @@ def timer_update():
first_time = False
if preferences.show_on_start:
# TODO here it should check if there are some results, and only open assetbar if this is the case, not search.
- # if bpy.context.scene.get('search results') is None:
+ # if bpy.context.window_manager.get('search results') is None:
search()
# preferences.first_run = False
if preferences.tips_on_start:
@@ -353,7 +374,7 @@ def timer_update():
icons_dir = thread[1]
scene = bpy.context.scene
# these 2 lines should update the previews enum and set the first result as active.
- s = bpy.context.scene
+ wm = bpy.context.window_manager
asset_type = thread[2]
if asset_type == 'model':
props = scene.blenderkit_models
@@ -372,7 +393,7 @@ def timer_update():
# json_filepath = os.path.join(icons_dir, 'brush_searchresult.json')
search_name = f'bkit {asset_type} search'
- s[search_name] = []
+ wm[search_name] = []
global reports
if reports != '':
@@ -384,6 +405,7 @@ def timer_update():
result_field = []
ok, error = check_errors(rdata)
if ok:
+
bpy.ops.object.run_assetbar_fix_context()
for r in rdata['results']:
asset_data = parse_result(r)
@@ -391,10 +413,10 @@ def timer_update():
result_field.append(asset_data)
# results = rdata['results']
- s[search_name] = result_field
- s['search results'] = result_field
- s[search_name + ' orig'] = copy.deepcopy(rdata)
- s['search results orig'] = s[search_name + ' orig']
+ wm[search_name] = result_field
+ wm['search results'] = result_field
+ wm[search_name + ' orig'] = copy.deepcopy(rdata)
+ wm['search results orig'] = wm[search_name + ' orig']
load_previews()
ui_props = bpy.context.scene.blenderkitUI
@@ -402,8 +424,8 @@ def timer_update():
ui_props.scrolloffset = 0
props.is_searching = False
props.search_error = False
- props.report = 'Found %i results. ' % (s['search results orig']['count'])
- if len(s['search results']) == 0:
+ props.report = 'Found %i results. ' % (wm['search results orig']['count'])
+ if len(wm['search results']) == 0:
tasks_queue.add_task((ui.add_report, ('No matching results found.',)))
# undo push
bpy.ops.wm.undo_push_context(message='Get BlenderKit search')
@@ -425,7 +447,7 @@ def load_previews():
props = scene.blenderkitUI
directory = paths.get_temp_dir('%s_search' % props.asset_type.lower())
s = bpy.context.scene
- results = s.get('search results')
+ results = bpy.context.window_manager.get('search results')
#
if results is not None:
inames = []
@@ -664,6 +686,8 @@ def generate_tooltip(mdata):
t += f"Quality rating: {int(mdata['ratingsAverage']['quality']) * '*'}\n"
t += f"Hours saved rating: {int(mdata['ratingsAverage']['workingHours'])}\n"
if utils.profile_is_validator():
+ t += f"Score: {int(mdata['score'])}\n"
+
t += f"Ratings count {rc['quality']}*/{rc['workingHours']}wh value " \
f"{mdata['ratingsAverage']['quality']}*/{mdata['ratingsAverage']['workingHours']}wh\n"
if len(t.split('\n')) < 11:
@@ -1311,7 +1335,7 @@ def get_search_simple(parameters, filepath=None, page_size=100, max_results=1000
if not filepath:
return results
- with open(filepath, 'w', encoding = 'utf-8') as s:
+ with open(filepath, 'w', encoding='utf-8') as s:
json.dump(results, s, ensure_ascii=False, indent=4)
bk_logger.info(f'retrieved {len(results)} assets from elastic search')
return results