BlenderKit: assetbar now can be open after search ends automatically.

also can start on blender startup, it's an option in preferences(by default False)
This commit is contained in:
Vilém Duha 2020-01-07 11:04:50 +01:00
parent c1cdc9cf23
commit 97e08ebb20
3 changed files with 23 additions and 8 deletions

View File

@ -1333,6 +1333,12 @@ class BlenderKitAddonPreferences(AddonPreferences):
default=False
)
show_on_start: BoolProperty(
name="Show assetbar when starting blender",
description="Show assetbar when starting blender",
default=False
)
global_dir: StringProperty(
name="Global Files Directory",
description="Global storage for your assets, will use subdirectories for the contents",
@ -1413,6 +1419,7 @@ class BlenderKitAddonPreferences(AddonPreferences):
def draw(self, context):
layout = self.layout
layout.prop(self, "show_on_start")
if self.api_key.strip() == '':
if self.enable_oauth:

View File

@ -117,8 +117,17 @@ def fetch_server_data():
categories.fetch_categories_thread(api_key)
first_time = True
@bpy.app.handlers.persistent
def timer_update(): # TODO might get moved to handle all blenderkit stuff.
#this makes a first search after opening blender. showing latest assets.
global first_time
preferences = bpy.context.preferences.addons['blenderkit'].preferences
if first_time:
first_time = False
if preferences.show_on_start:
search()
global search_threads
# don't do anything while dragging - this could switch asset type during drag, and make results list length different,
@ -163,7 +172,7 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff.
result_field = []
ok, error = check_errors(rdata)
if ok:
bpy.ops.object.run_assetbar_fix_context()
for r in rdata['results']:
# TODO remove this fix when filesSize is fixed.
# this is a temporary fix for too big numbers from the server.

View File

@ -1730,18 +1730,17 @@ class RunAssetBarWithContext(bpy.types.Operator):
# def modal(self, context, event):
# return {'RUNNING_MODAL'}
def invoke(self, context, event):
def execute(self, context):
C_dict = bpy.context.copy()
C_dict.update(region = 'WINDOW')
if context.area.type != 'VIEW_3D':
w,a,r = get_largest_3dview()
override = {'window': w, 'screen': w.screen, 'area': a, 'region' : r}
C_dict.update(region='WINDOW')
if context.area is None or context.area.type != 'VIEW_3D':
w, a, r = get_largest_3dview()
override = {'window': w, 'screen': w.screen, 'area': a, 'region': r}
C_dict.update(override)
bpy.ops.view3d.blenderkit_asset_bar(C_dict, 'INVOKE_REGION_WIN', keep_running=True, do_search=False)
return {'RUNNING_MODAL'}
classess = (
AssetBarOperator,
RunAssetBarWithContext,