BlenderKit: fix occasional crash during reordering.

It was caused with order of unregistration, now UI panels go first.
also separated advanced search panel
This commit is contained in:
Vilém Duha 2020-02-06 23:11:48 +01:00
parent 8b659917ba
commit 538e48dd91
5 changed files with 86 additions and 15 deletions

View File

@ -400,7 +400,7 @@ class BlenderKitCommonSearchProps(object):
search_done: BoolProperty(name="Search Completed", description="at least one search did run (internal)",
default=False)
own_only: BoolProperty(name="My Assets", description="Search only for your assets",
default=False)
default=False, update=search.search_update)
search_advanced: BoolProperty(name="Advanced Search Options", description="use advanced search properties",
default=False, update=search.search_update)
@ -1651,8 +1651,9 @@ def register():
def unregister():
bpy.app.timers.unregister(check_timers_timer)
ui_panels.unregister_ui_panels()
ui.unregister_ui()
icons.unregister_icons()
search.unregister_search()
asset_inspector.unregister_asset_inspector()
@ -1660,7 +1661,6 @@ def unregister():
upload.unregister_upload()
ratings.unregister_ratings()
autothumb.unregister_thumbnailer()
ui_panels.unregister_ui_panels()
bg_blender.unregister()
overrides.unregister_overrides()
bkit_oauth.unregister()

View File

@ -132,7 +132,7 @@ last_clipboard = ''
@bpy.app.handlers.persistent
def timer_update(): # TODO might get moved to handle all blenderkit stuff.
def timer_update():
# this makes a first search after opening blender. showing latest assets.
global first_time
preferences = bpy.context.preferences.addons['blenderkit'].preferences

View File

@ -602,6 +602,9 @@ def draw_tooltip_old(x, y, text='', author='', img=None):
def draw_callback_2d(self, context):
if not utils.guard_from_crash():
return;
a = context.area
w = context.window
try:
@ -769,6 +772,7 @@ def draw_callback_2d_search(self, context):
ui_props.thumb_size,
img,
1)
if search_results_orig['count'] - ui_props.scrolloffset > (ui_props.wcount * ui_props.hcount) + 1:
if ui_props.active_index == -1:
ui_bgl.draw_rect(ui_props.bar_x + ui_props.bar_width - 25,
@ -782,6 +786,7 @@ def draw_callback_2d_search(self, context):
for b in range(0, h_draw):
w_draw = min(ui_props.wcount, len(search_results) - b * ui_props.wcount - ui_props.scrolloffset)
y = ui_props.bar_y - (b + 1) * (row_height)
for a in range(0, w_draw):
x = ui_props.bar_x + a * (
@ -896,7 +901,6 @@ def draw_callback_2d_search(self, context):
ui_props.mouse_y - linelength, 2, white)
def draw_callback_3d(self, context):
''' Draw snapped bbox while dragging and in the future other blenderkit related stuff. '''
if not utils.guard_from_crash():
@ -1110,8 +1114,15 @@ def mouse_in_area(mx, my, x, y, w, h):
def mouse_in_asset_bar(mx, my):
s = bpy.context.scene
ui_props = bpy.context.scene.blenderkitUI
w_draw1 = min(ui_props.wcount + 1, len(search_results) - b * ui_props.wcount - ui_props.scrolloffset)
end = ui_props.bar_x + (w_draw1) * (
ui_props.margin + ui_props.thumb_size) + ui_props.margin + ui_props.drawoffset + 25
ui_bgl.draw_rect(end, ui_props.bar_y, 50, 50, highlight)
if ui_props.bar_y - ui_props.bar_height < my < ui_props.bar_y \
and mx > ui_props.bar_x and mx < ui_props.bar_x + ui_props.bar_width:
return True
@ -1575,8 +1586,8 @@ class AssetBarOperator(bpy.types.Operator):
else:
# first, test if object can have material applied.
#TODO add other types here if droppable.
if object is None or object.is_library_indirect and object.type =='MESH' :
# TODO add other types here if droppable.
if object is None or object.is_library_indirect and object.type == 'MESH':
target_object = object.name
# create final mesh to extract correct material slot
depsgraph = bpy.context.evaluated_depsgraph_get()
@ -1725,8 +1736,6 @@ class AssetBarOperator(bpy.types.Operator):
self.area = context.area
self.scene = bpy.context.scene
self.has_quad_views = len(bpy.context.area.spaces[0].region_quadviews) > 0
for r in self.area.regions:
@ -1779,7 +1788,7 @@ class UndoWithContext(bpy.types.Operator):
# def modal(self, context, event):
# return {'RUNNING_MODAL'}
message = StringProperty('Undo Message', default = 'BlenderKit operation')
message = StringProperty('Undo Message', default='BlenderKit operation')
def execute(self, context):
C_dict = bpy.context.copy()
@ -1788,7 +1797,7 @@ class UndoWithContext(bpy.types.Operator):
w, a, r = get_largest_3dview()
override = {'window': w, 'screen': w.screen, 'area': a, 'region': r}
C_dict.update(override)
bpy.ops.ed.undo_push(C_dict, 'INVOKE_REGION_WIN', message = self.message)
bpy.ops.ed.undo_push(C_dict, 'INVOKE_REGION_WIN', message=self.message)
return {'FINISHED'}
@ -1823,7 +1832,8 @@ classess = (
# store keymap items here to access after registration
addon_keymapitems = []
#@persistent
# @persistent
def pre_load(context):
ui_props = bpy.context.scene.blenderkitUI
ui_props.assetbar_on = False
@ -1832,7 +1842,6 @@ def pre_load(context):
preferences.login_attempt = False
def register_ui():
global handler_2d, handler_3d

View File

@ -672,6 +672,67 @@ def draw_login_buttons(layout):
icon='URL')
class VIEW3D_PT_blenderkit_advanced_model_search(Panel):
bl_category = "BlenderKit"
bl_idname = "VIEW3D_PT_blenderkit_advanced_model_search"
# bl_parent_id = "VIEW3D_PT_blenderkit_unified"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Advanced search options"
@classmethod
def poll(cls, context):
return True
def draw(self, context):
s = context.scene
props = s.blenderkit_models
layout = self.layout
layout.separator()
# layout.label(text = "common searches keywords:")
# layout.prop(props, "search_global_keywords", text = "")
# layout.prop(props, "search_modifier_keywords")
# if props.search_engine == 'OTHER':
# layout.prop(props, "search_engine_keyword")
# AGE
layout.prop(props, "search_condition", text='Condition') # , text ='condition of object new/old e.t.c.')
# DESIGN YEAR
layout.prop(props, "search_design_year", text='designed in ( min - max )')
if props.search_design_year:
row = layout.row(align=True)
row.prop(props, "search_design_year_min", text='min')
row.prop(props, "search_design_year_max", text='max')
# POLYCOUNT
layout.prop(props, "search_polycount", text='Poly count in ( min - max )')
if props.search_polycount:
row = layout.row(align=True)
row.prop(props, "search_polycount_min", text='min')
row.prop(props, "search_polycount_max", text='max')
# TEXTURE RESOLUTION
layout.prop(props, "search_texture_resolution", text='texture resolution ( min - max )')
if props.search_texture_resolution:
row = layout.row(align=True)
row.prop(props, "search_texture_resolution_min", text='min')
row.prop(props, "search_texture_resolution_max", text='max')
# FILE SIZE
layout.prop(props, "search_file_size", text='File size ( min - max )')
if props.search_file_size:
row = layout.row(align=True)
row.prop(props, "search_file_size_min", text='min')
row.prop(props, "search_file_size_max", text='max')
# layout.prop(props, "search_procedural", expand=True)
# ADULT
# layout.prop(props, "search_adult") # , text ='condition of object new/old e.t.c.')
class VIEW3D_PT_blenderkit_unified(Panel):
bl_category = "BlenderKit"
bl_idname = "VIEW3D_PT_blenderkit_unified"
@ -1085,6 +1146,7 @@ classess = (
VIEW3D_PT_blenderkit_profile,
VIEW3D_PT_blenderkit_login,
VIEW3D_PT_blenderkit_unified,
# VIEW3D_PT_blenderkit_advanced_model_search,
VIEW3D_PT_blenderkit_model_properties,
VIEW3D_PT_blenderkit_downloads,
OBJECT_MT_blenderkit_asset_menu,
@ -1099,7 +1161,7 @@ def register_ui_panels():
def unregister_ui_panels():
bpy.types.VIEW3D_MT_editor_menus.remove(header_search_draw)
for c in classess:
print('unregister', c)
bpy.utils.unregister_class(c)
bpy.types.VIEW3D_MT_editor_menus.remove(header_search_draw)

View File

@ -554,7 +554,7 @@ def profile_is_validator():
def guard_from_crash():
'''Blender tends to crash when trying to run some functions with the addon going through unregistration process.'''
if bpy.context.preferences.addons['blenderkit'] is None:
if bpy.context.preferences.addons.get('blenderkit') is None:
return False;
if bpy.context.preferences.addons['blenderkit'].preferences is None:
return False;