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:
authorVilem Duha <vilem.duha@gmail.com>2021-07-27 00:08:13 +0300
committerVilem Duha <vilem.duha@gmail.com>2021-07-27 00:08:13 +0300
commit69ad4c43d004c9788ba98e75ade02097284a25f9 (patch)
treebc054237f00dc627d40aef9f03b125cce3cba464 /blenderkit/ui.py
parent0d6b2e8767fdec2cb77e1a9ae92003a496b01837 (diff)
BlenderKit: optimize search
quite a large overhaul of how search results are loaded. this saves time due to not closing the session and enabling small previews to be first. Also use the dict_param paraameter so that the results responses are a bit smaller.
Diffstat (limited to 'blenderkit/ui.py')
-rw-r--r--blenderkit/ui.py69
1 files changed, 29 insertions, 40 deletions
diff --git a/blenderkit/ui.py b/blenderkit/ui.py
index a21cff91..138f4a89 100644
--- a/blenderkit/ui.py
+++ b/blenderkit/ui.py
@@ -40,7 +40,6 @@ import os
import logging
-
draw_time = 0
eval_time = 0
@@ -361,7 +360,7 @@ def draw_tooltip(x, y, name='', author='', quality='-', img=None, gravatar=None)
# draw author's name
author_text_size = int(name_height * .7)
- ui_bgl.draw_text(author, author_x_text, gravatar_y, author_text_size, textcol, ralign=True)
+ ui_bgl.draw_text(author, author_x_text, gravatar_y, author_text_size, textcol, halign='RIGHT')
# draw quality
quality_text_size = int(name_height * 1)
@@ -385,7 +384,7 @@ def draw_tooltip_with_author(asset_data, x, y):
if a.get('gravatarImg') is not None:
gimg = utils.get_hidden_image(a['gravatarImg'], a['gravatarHash']).name
- if len(a['firstName'])>0 or len(a['lastName'])>0:
+ if len(a['firstName']) > 0 or len(a['lastName']) > 0:
author_text = f"by {a['firstName']} {a['lastName']}"
aname = asset_data['displayName']
@@ -398,13 +397,13 @@ def draw_tooltip_with_author(asset_data, x, y):
rcount = 0
quality = '-'
if rc:
- rcount = min(rc.get('quality',0), rc.get('workingHours',0))
+ rcount = min(rc.get('quality', 0), rc.get('workingHours', 0))
if rcount > show_rating_threshold:
quality = round(asset_data['ratingsAverage'].get('quality'))
- tooltip_data={
+ tooltip_data = {
'aname': aname,
'author_text': author_text,
- 'quality':quality,
+ 'quality': quality,
'gimg': gimg
}
asset_data['tooltip_data'] = tooltip_data
@@ -419,7 +418,6 @@ def draw_tooltip_with_author(asset_data, x, y):
gravatar=gimg)
-
def draw_callback_2d(self, context):
if not utils.guard_from_crash():
return
@@ -699,7 +697,9 @@ def draw_asset_bar(self, context):
# w + 2*highlight_margin, h + 2*highlight_margin , highlight)
else:
- ui_bgl.draw_rect(x, y, ui_props.thumb_size, ui_props.thumb_size, white)
+ ui_bgl.draw_rect(x, y, ui_props.thumb_size, ui_props.thumb_size, grey2)
+ ui_bgl.draw_text('loading', x + ui_props.thumb_size // 2, y + ui_props.thumb_size // 2,
+ ui_props.thumb_size // 6, white, halign='CENTER', valign='CENTER')
result = search_results[index]
# code to inform validators that the validation is waiting too long and should be done asap
@@ -744,7 +744,7 @@ def draw_asset_bar(self, context):
# report = 'BlenderKit - No matching results found.'
# ui_bgl.draw_text(report, ui_props.bar_x + ui_props.margin,
# ui_props.bar_y - 25 - ui_props.margin, 15)
- if ui_props.draw_tooltip and len(search_results)>ui_props.active_index:
+ if ui_props.draw_tooltip and len(search_results) > ui_props.active_index:
r = search_results[ui_props.active_index]
draw_tooltip_with_author(r, ui_props.mouse_x, ui_props.mouse_y)
s = bpy.context.scene
@@ -1193,7 +1193,6 @@ class AssetBarOperator(bpy.types.Operator):
ui_props.has_hit = False
ui_props.assetbar_on = False
-
def modal(self, context, event):
# This is for case of closing the area or changing type:
@@ -1256,7 +1255,6 @@ class AssetBarOperator(bpy.types.Operator):
self.area.tag_redraw()
s = context.scene
-
if ui_props.turn_off:
ui_props.turn_off = False
self.exit_modal()
@@ -1432,7 +1430,6 @@ class AssetBarOperator(bpy.types.Operator):
ui_props.scrolloffset = max(0, ui_props.scrolloffset - ui_props.wcount * ui_props.hcount)
return {'RUNNING_MODAL'}
-
if ui_props.active_index == -3:
return {'RUNNING_MODAL'}
else:
@@ -1529,7 +1526,6 @@ class AssetBarOperator(bpy.types.Operator):
update_ui_size(self.area, self.region)
-
self._handle_2d = bpy.types.SpaceView3D.draw_handler_add(draw_callback_2d, args, 'WINDOW', 'POST_PIXEL')
ui_props.assetbar_on = True
@@ -1592,10 +1588,10 @@ def draw_callback_dragging(self, context):
try:
img = bpy.data.images.get(self.iname)
except:
- # self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_dragging, args, 'WINDOW', 'POST_PIXEL')
- # self._handle_3d = bpy.types.SpaceView3D.draw_handler_add(draw_callback_3d_dragging, args, 'WINDOW',
- # bpy.types.SpaceView3D.draw_handler_remove(self._handle,
- # bpy.types.SpaceView3D.draw_handler_remove(self._handle_3d, 'WINDOW')
+ # self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_dragging, args, 'WINDOW', 'POST_PIXEL')
+ # self._handle_3d = bpy.types.SpaceView3D.draw_handler_add(draw_callback_3d_dragging, args, 'WINDOW',
+ # bpy.types.SpaceView3D.draw_handler_remove(self._handle,
+ # bpy.types.SpaceView3D.draw_handler_remove(self._handle_3d, 'WINDOW')
return
linelength = 35
@@ -1646,7 +1642,7 @@ class AssetDragOperator(bpy.types.Operator):
if ui_props.asset_type == 'MODEL':
if not self.drag:
self.snapped_location = scene.cursor.location
- self.snapped_rotation = (0,0,0)
+ self.snapped_rotation = (0, 0, 0)
target_object = ''
if self.object_name is not None:
@@ -1671,7 +1667,7 @@ class AssetDragOperator(bpy.types.Operator):
target_object = ''
target_slot = ''
if not self.drag:
- #click interaction
+ # click interaction
object = bpy.context.active_object
if object is None:
ui_panels.ui_message(title='Nothing selected',
@@ -1725,7 +1721,6 @@ class AssetDragOperator(bpy.types.Operator):
message=f"Can't assign materials to {object.type.lower()} object.")
return
-
if target_object != '':
# position is for downloader:
loc = self.snapped_location
@@ -1741,16 +1736,13 @@ class AssetDragOperator(bpy.types.Operator):
target_object=target_object,
material_target_slot=target_slot)
-
-
if ui_props.asset_type == 'HDR':
bpy.ops.scene.blenderkit_download('INVOKE_DEFAULT',
- asset_index=self.asset_search_index,
- # replace_resolution=True,
- invoke_resolution=True,
- max_resolution=self.asset_data.get('max_resolution', 0)
- )
-
+ asset_index=self.asset_search_index,
+ # replace_resolution=True,
+ invoke_resolution=True,
+ max_resolution=self.asset_data.get('max_resolution', 0)
+ )
if ui_props.asset_type == 'SCENE':
bpy.ops.scene.blenderkit_download('INVOKE_DEFAULT',
@@ -1778,18 +1770,18 @@ class AssetDragOperator(bpy.types.Operator):
self.mouse_x = event.mouse_region_x
self.mouse_y = event.mouse_region_y
- #are we dragging already?
+ # are we dragging already?
drag_threshold = 10
if not self.drag and \
(abs(self.start_mouse_x - self.mouse_x) > drag_threshold or \
- abs(self.start_mouse_y - self.mouse_y) > drag_threshold):
+ abs(self.start_mouse_y - self.mouse_y) > drag_threshold):
self.drag = True
- #turn off asset bar here, shout start again after finishing drag drop.
+ # turn off asset bar here, shout start again after finishing drag drop.
ui_props.turn_off = True
if (event.type == 'ESC' or \
- not mouse_in_region(context.region, self.mouse_x, self.mouse_y))and \
- (not self.drag or self.steps<5):
+ not mouse_in_region(context.region, self.mouse_x, self.mouse_y)) and \
+ (not self.drag or self.steps < 5):
# this case is for canceling from inside popup card when there's an escape attempt to close the window
return {'PASS_THROUGH'}
@@ -1808,8 +1800,7 @@ class AssetDragOperator(bpy.types.Operator):
sprops.offset_rotation_amount -= sprops.offset_rotation_step
return {'RUNNING_MODAL'}
-
- if event.type =='MOUSEMOVE':
+ if event.type == 'MOUSEMOVE':
#### TODO - this snapping code below is 3x in this file.... refactor it.
self.has_hit, self.snapped_location, self.snapped_normal, self.snapped_rotation, self.face_index, object, self.matrix = mouse_raycast(
@@ -1831,14 +1822,14 @@ class AssetDragOperator(bpy.types.Operator):
return {'RUNNING_MODAL'}
if event.type == 'LEFTMOUSE' and event.value == 'RELEASE':
- self.mouse_release()# does the main job with assets
+ self.mouse_release() # does the main job with assets
self.handlers_remove()
bpy.context.window.cursor_set("DEFAULT")
- bpy.ops.object.run_assetbar_fix_context(keep_running = True, do_search = False)
+ bpy.ops.object.run_assetbar_fix_context(keep_running=True, do_search=False)
ui_props.dragging = False
return {'FINISHED'}
- self.steps +=1
+ self.steps += 1
return {'RUNNING_MODAL'}
@@ -1850,8 +1841,6 @@ class AssetDragOperator(bpy.types.Operator):
# draw in view space with 'POST_VIEW' and 'PRE_VIEW'
self.iname = utils.previmg_name(self.asset_search_index)
-
-
self.mouse_x = 0
self.mouse_y = 0
self.steps = 0