[Bf-extensions-cvs] [11491c5b] blender-v2.82-release: BlenderKit: search in header option in prefs

Vilém Duha noreply at git.blender.org
Tue Jan 28 13:49:36 CET 2020


Commit: 11491c5be04d5052632265e0fba7275db2f088e4
Author: Vilém Duha
Date:   Tue Jan 21 16:09:26 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rBA11491c5be04d5052632265e0fba7275db2f088e4

BlenderKit: search in header option in prefs

tips on start option in prefs
total_megapixels autotag wip
fix bugs in queries
active area is usually the largest 3d view and only that one draws reports e.t.c.
fix registration crash when registering/unregistering several times (menu remove)
vs_rejected icon verification status

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

M	blenderkit/__init__.py
M	blenderkit/asset_inspector.py
M	blenderkit/search.py
A	blenderkit/thumbnails/vs_rejected.png
M	blenderkit/ui.py
M	blenderkit/ui_panels.py

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

diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py
index adb8e797..f8b31fec 100644
--- a/blenderkit/__init__.py
+++ b/blenderkit/__init__.py
@@ -1367,6 +1367,18 @@ class BlenderKitAddonPreferences(AddonPreferences):
         default=False
     )
 
+    tips_on_start: BoolProperty(
+        name="Show tips when starting blender",
+        description="Show tips when starting blender",
+        default=True
+    )
+
+    search_in_header: BoolProperty(
+        name="Show BlenderKit search in 3d view header",
+        description="Show BlenderKit search in 3d view header",
+        default=True
+    )
+
     global_dir: StringProperty(
         name="Global Files Directory",
         description="Global storage for your assets, will use subdirectories for the contents",
@@ -1473,6 +1485,9 @@ class BlenderKitAddonPreferences(AddonPreferences):
         # layout.prop(self, "panel_behaviour")
         layout.prop(self, "thumb_size")
         layout.prop(self, "max_assetbar_rows")
+        layout.prop(self, "tips_on_start")
+        layout.prop(self, "search_in_header")
+
 
 
 # registration
diff --git a/blenderkit/asset_inspector.py b/blenderkit/asset_inspector.py
index 74f814ca..14224b21 100644
--- a/blenderkit/asset_inspector.py
+++ b/blenderkit/asset_inspector.py
@@ -85,6 +85,7 @@ def check_render_engine(props, obs):
     mattype = None
     materials = []
     shaders = []
+    textures = []
     props.uv = False
 
     for ob in obs:  # TODO , this is duplicated here for other engines, otherwise this should be more clever.
@@ -115,19 +116,21 @@ def check_render_engine(props, obs):
                             shaders.append(n.type)
                     if n.type == 'TEX_IMAGE':
                         mattype = 'image based'
-                        if n.image is not None:
+                        props.is_procedural = False
+                        if n.image not in textures:
+                            textures.append(n.image)
+                            props.texture_count += 1
+                            props.total_megapixels += (n.image.size[0] * n.image.size[1])
 
                             maxres = max(n.image.size[0], n.image.size[1])
-
                             props.texture_resolution_max = max(props.texture_resolution_max, maxres)
-
                             minres = min(n.image.size[0], n.image.size[1])
-
                             if props.texture_resolution_min == 0:
                                 props.texture_resolution_min = minres
                             else:
                                 props.texture_resolution_min = min(props.texture_resolution_min, minres)
 
+
         # if mattype == None:
         #    mattype = 'procedural'
         # tags['material type'] = mattype
diff --git a/blenderkit/search.py b/blenderkit/search.py
index 2c2b2dea..96c1e63e 100644
--- a/blenderkit/search.py
+++ b/blenderkit/search.py
@@ -24,12 +24,13 @@ if "bpy" in locals():
     utils = reload(utils)
     categories = reload(categories)
     ui = reload(ui)
+    colors = reload(colors)
     bkit_oauth = reload(bkit_oauth)
     version_checker = reload(version_checker)
     tasks_queue = reload(tasks_queue)
     rerequests = reload(rerequests)
 else:
-    from blenderkit import paths, utils, categories, ui, bkit_oauth, version_checker, tasks_queue, rerequests
+    from blenderkit import paths, utils, categories, ui, colors,  bkit_oauth, version_checker, tasks_queue, rerequests
 
 import blenderkit
 from bpy.app.handlers import persistent
@@ -81,6 +82,15 @@ thumb_full_download_threads = {}
 reports = ''
 
 
+rtips = ['Click or drag model or material in scene to link/append ',
+             "Please rate responsively and plentifully. This helps us distribute rewards to the authors.",
+             "Click on brushes to link them into scene.",
+             "All materials and brushes are free.",
+             "Locked models are available if you subscribe to Full plan.",
+             "Login to upload your own models, materials or brushes.",
+             "Use 'A' key to search assets by same author.",
+             "Use 'W' key to open Authors webpage.", ]
+
 def refresh_token_timer():
     ''' this timer gets run every time the token needs refresh. It refreshes tokens and also categories.'''
     utils.p('refresh timer')
@@ -127,6 +137,10 @@ def timer_update():  # TODO might get moved to handle all blenderkit stuff.
         first_time = False
         if preferences.show_on_start:
             search()
+        if preferences.tips_on_start:
+            ui.get_largest_3dview()
+            ui.update_ui_size(ui.active_area, ui.active_region)
+            ui.add_report(text='BlenderKit Tip:' + random.choice(rtips), timeout=12, color=colors.GREEN)
 
     global search_threads
     # don't do anything while dragging - this could switch asset type during drag, and make results list length different,
@@ -496,14 +510,7 @@ def generate_tooltip(mdata):
 
 def get_random_tip(mdata):
     t = ''
-    rtips = ['Click or drag model or material in scene to link/append ',
-             "Click on brushes to link them into scene.",
-             "All materials are free.",
-             "All brushes are free.",
-             "Locked models are available if you subscribe to Full plan.",
-             "Login to upload your own models, materials or brushes.",
-             "Use 'A' key to search assets by same author.",
-             "Use 'W' key to open Authors webpage.", ]
+
     tip = 'Tip: ' + random.choice(rtips)
     t = writeblock(t, tip)
     return t
@@ -743,9 +750,10 @@ class Searcher(threading.Thread):
             requeststring = '?query=' + query['keywords'].lower() + '+'
             #
             for i, q in enumerate(query):
-                requeststring += q + ':' + str(query[q]).lower()
-                if i < len(query) - 1:
-                    requeststring += '+'
+                if q != 'keywords':
+                    requeststring += q + ':' + str(query[q]).lower()
+                    if i < len(query) - 1:
+                        requeststring += '+'
 
             # result ordering: _score - relevance, score - BlenderKit score
             #first condition assumes no keywords and no category, thus an empty search that is triggered on start.
@@ -794,7 +802,7 @@ class Searcher(threading.Thread):
                     if p['parameterType'] == 'mode':
                         mode = p['value']
             if query['asset_type'] != 'brush' or (
-                    query.get('brushType') != None and query['brushType']) == mode:
+                    query.get('mode') != None and query['mode']) == mode:
                 nresults.append(d)
         rdata['results'] = nresults
 
@@ -1025,7 +1033,7 @@ def build_query_brush():
     query = {
         "asset_type": 'brush',
 
-        "brushType": brush_type
+        "mode": brush_type
     }
 
     build_query_common(query, props)
diff --git a/blenderkit/thumbnails/vs_rejected.png b/blenderkit/thumbnails/vs_rejected.png
new file mode 100644
index 00000000..6ff663cf
Binary files /dev/null and b/blenderkit/thumbnails/vs_rejected.png differ
diff --git a/blenderkit/ui.py b/blenderkit/ui.py
index 5def630f..be4bd451 100644
--- a/blenderkit/ui.py
+++ b/blenderkit/ui.py
@@ -50,6 +50,11 @@ import os
 
 handler_2d = None
 handler_3d = None
+active_area = None
+active_area = None
+active_window = None
+active_region = None
+
 reports = []
 
 mappingdict = {
@@ -67,7 +72,7 @@ verification_icons = {
     'uploading': 'vs_uploading.png',
     'on_hold': 'vs_on_hold.png',
     'validated': None,
-    'rejected': 'vs_on_hold.png'
+    'rejected': 'vs_rejected.png'
 
 }
 
@@ -133,7 +138,8 @@ class Report():
                     pass;
 
     def draw(self, x, y):
-        ui_bgl.draw_text(self.text, x, y + 8, 16, self.draw_color)
+        if bpy.context.area == active_area:
+            ui_bgl.draw_text(self.text, x, y + 8, 16, self.draw_color)
 
 
 def get_asset_under_mouse(mousex, mousey):
@@ -1174,6 +1180,10 @@ def get_largest_3dview():
                     for r in a.regions:
                         if r.type == 'WINDOW':
                             region = r
+    global active_area, active_window, active_region
+    active_window = maxw
+    active_area = maxa
+    active_region = region
     return maxw, maxa, region
 
 
@@ -1419,7 +1429,7 @@ class AssetBarOperator(bpy.types.Operator):
 
                     ui_props.tooltip = asset_data['tooltip']
 
-                    #bpy.ops.wm.call_menu(name='OBJECT_MT_blenderkit_asset_menu')
+                    # bpy.ops.wm.call_menu(name='OBJECT_MT_blenderkit_asset_menu')
 
                 else:
                     ui_props.draw_tooltip = False
@@ -1700,30 +1710,38 @@ class AssetBarOperator(bpy.types.Operator):
         if sr is None:
             bpy.context.scene['search results'] = []
 
-        if context.area.type == 'VIEW_3D':
-            # the arguments we pass the the callback
-            args = (self, context)
-            self.window = context.window
-            self.area = context.area
-            self.scene = bpy.context.scene
-            self.has_quad_views = len(bpy.context.area.spaces[0].region_quadviews) > 0
+        if context.area.type != 'VIEW_3D':
+            self.report({'WARNING'}, "View3D not found, cannot run operator")
+            return {'CANCELLED'}
 
-            for r in self.area.regions:
-                if r.type == 'WINDOW':
-                    self.region = r
+        # the arguments we pass the the callback
+        args = (self, context)
 
-            update_ui_size(self.area, self.region)
+        self.window = context.window
+        self.area = context.area
+        self.scene = bpy.context.scene
 
-            self._handle_2d = bpy.types.SpaceView3D.draw_handler_add(draw_callback_2d, args, 'WINDOW', 'POST_PIXEL')
-            self._handle_3d = bpy.types.SpaceView3D.draw_handler_add(draw_callback_3d, args, 'WINDOW', 'POST_VIEW')
 
-            context.window_manager.modal_handler_add(self)
-            ui_props.assetbar_on = True
-            return {'RUNNING_MODAL'}
-        else:
 
-            self.report({'WARNING'}, "View3D not found, cannot run operator")
-            return {'

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list