[Bf-extensions-cvs] [6b61dff0] blender-v2.82-release: BlenderKit: fix bugs

Vilém Duha noreply at git.blender.org
Tue Feb 11 18:57:53 CET 2020


Commit: 6b61dff0841600368710710894ccc0c20867929f
Author: Vilém Duha
Date:   Tue Feb 11 18:56:48 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rBA6b61dff0841600368710710894ccc0c20867929f

BlenderKit: fix bugs

clipboard pasting not working at all, kind of a showstopper,
and an error in Rating drawing that spammed console.
several tooltips fixed

===================================================================

M	blenderkit/__init__.py
M	blenderkit/search.py
M	blenderkit/ui_panels.py

===================================================================

diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py
index 82361f6e..d64ea133 100644
--- a/blenderkit/__init__.py
+++ b/blenderkit/__init__.py
@@ -1313,7 +1313,8 @@ class BlenderKitModelSearchProps(PropertyGroup, BlenderKitCommonSearchProps):
             ('LINK_COLLECTION', 'Link', 'Link Collection'),
             ('APPEND_OBJECTS', 'Append', 'Append as Objects'),
         ),
-        description="choose if the assets will be linked or appended",
+        description="Appended objects are editable in your scene. Linked assets are saved in original files, "
+                    "aren't editable but also don't increase your file size",
         default="LINK_COLLECTION"
     )
     append_link: EnumProperty(
@@ -1453,8 +1454,8 @@ class BlenderKitAddonPreferences(AddonPreferences):
     )
 
     search_in_header: BoolProperty(
-        name="Show BlenderKit search in 3d view header",
-        description="Show BlenderKit search in 3d view header",
+        name="Show BlenderKit search in 3D view header",
+        description="Show BlenderKit search in 3D view header",
         default=True
     )
 
diff --git a/blenderkit/search.py b/blenderkit/search.py
index 426f2923..bf430d91 100644
--- a/blenderkit/search.py
+++ b/blenderkit/search.py
@@ -148,24 +148,25 @@ def timer_update():
     # clipboard monitoring to search assets from web
     global last_clipboard
     if bpy.context.window_manager.clipboard != last_clipboard:
-        last_clipboard = bpy.context.window_manager.clipboard
+        last_clipboard =  bpy.context.window_manager.clipboard
         instr = 'asset_base_id:'
+        # first check if contains asset id, then asset type
         if last_clipboard[:len(instr)] == instr:
             atstr = 'asset_type:'
             ati = last_clipboard.find(atstr)
+            #this only checks if the asset_type keyword is there but let's the keywords update function do the parsing.
             if ati > -1:
-                at = last_clipboard[ati:]
-
-            search_props = utils.get_search_props()
-            search_props.search_keywords = last_clipboard
-            search()
+                search_props = utils.get_search_props()
+                search_props.search_keywords = last_clipboard
+                # don't run search after this - assigning to keywords runs the search_update function.
 
     global search_threads
-    # don't do anything while dragging - this could switch asset type during drag, and make results list length different,
-    # causing a lot of throuble literally.
+    # don't do anything while dragging - this could switch asset during drag, and make results list length different,
+    # causing a lot of throuble.
     if len(search_threads) == 0 or bpy.context.scene.blenderkitUI.dragging:
         return 1
-    for thread in search_threads:  # TODO this doesn't check all processes when one gets removed,
+    for thread in search_threads:
+        # TODO this doesn't check all processes when one gets removed,
         # but most of the time only one is running anyway
         if not thread[0].is_alive():
             search_threads.remove(thread)  #
@@ -1189,6 +1190,32 @@ def search_update(self, context):
     if ui_props.down_up != 'SEARCH':
         ui_props.down_up = 'SEARCH'
 
+    # here we tweak the input if it comes form the clipboard. we need to get rid of asset type and set it to
+    sprops = utils.get_search_props()
+    instr = 'asset_base_id:'
+    atstr = 'asset_type:'
+    kwds = sprops.search_keywords
+    idi = kwds.find(instr)
+    ati = kwds.find(atstr)
+    # if the asset type already isn't there it means this update function
+    # was triggered by it's last iteration and needs to cancel
+    if idi>-1 and ati == -1:
+        return;
+    if ati > -1:
+        at = kwds[ati:].lower()
+        # uncertain length of the remaining string -  find as better method to check the presence of asset type
+        if at.find('model') > -1:
+            ui_props.asset_type = 'MODEL'
+        elif at.find('material') > -1:
+            ui_props.asset_type = 'MATERIAL'
+        elif at.find('brush') > -1:
+            ui_props.asset_type = 'BRUSH'
+        # now we trim the input copypaste by anything extra that is there,
+        # this is also a way for this function to recognize that it already has parsed the clipboard
+        # the search props can have changed and this needs to transfer the data to the other field
+        # this complex behaviour is here for the case where the user needs to paste manually into blender?
+        sprops = utils.get_search_props()
+        sprops.search_keywords = kwds[:ati].rstrip()
     search()
 
 
diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py
index e9727d0e..cacc1df4 100644
--- a/blenderkit/ui_panels.py
+++ b/blenderkit/ui_panels.py
@@ -69,6 +69,10 @@ def label_multiline(layout, text='', icon='NONE', width=-1):
 def draw_ratings(layout, context):
     # layout.operator("wm.url_open", text="Read rating instructions", icon='QUESTION').url = 'https://support.google.com/?hl=en'
     asset = utils.get_active_asset()
+    # the following shouldn't happen at all in an optimal case,
+    # this function should run only when asset was already checked to be existing
+    if asset == None:
+        return;
     bkit_ratings = asset.bkit_ratings
 
     ratings.draw_rating(layout, bkit_ratings, 'rating_quality', 'Quality')
@@ -406,7 +410,7 @@ class VIEW3D_PT_blenderkit_model_properties(Panel):
         o = utils.get_active_model()
         # o = bpy.context.active_object
         if o.get('asset_data') is None:
-            label_multiline(layout, text='To upload this asset to BlenderKit, go to the Find and Upload Assets pael.')
+            label_multiline(layout, text='To upload this asset to BlenderKit, go to the Find and Upload Assets panel.')
             layout.prop(o, 'name')
 
         if o.get('asset_data') is not None:



More information about the Bf-extensions-cvs mailing list