[Bf-extensions-cvs] [f78b7f96] blender-v2.82-release: BlenderKit: prevent blender crashes + undo fix

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


Commit: f78b7f9618085f35edab46c5a599bdb1c5f843e0
Author: Vilém Duha
Date:   Mon Jan 27 18:15:34 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rBAf78b7f9618085f35edab46c5a599bdb1c5f843e0

BlenderKit: prevent blender crashes + undo fix

Blender tends to crash during unregistration process when some functions still run (like UI) this is a bug that should be reported, however this fixes the problem at least for BlenderKit now.
appending an asset now runs undo push operator with faked context - works surprisingly well.
improving lots of tooltips.
ratings download
license display
default sorting by uploaded last

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

M	blenderkit/__init__.py
M	blenderkit/download.py
M	blenderkit/ratings.py
M	blenderkit/search.py
M	blenderkit/ui.py
M	blenderkit/ui_panels.py
M	blenderkit/utils.py

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

diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py
index 05747d0f..3482c4f1 100644
--- a/blenderkit/__init__.py
+++ b/blenderkit/__init__.py
@@ -93,7 +93,6 @@ def scene_load(context):
     preferences = bpy.context.preferences.addons['blenderkit'].preferences
     preferences.login_attempt = False
 
-
 def check_timers_timer():
     ''' checks if all timers are registered regularly. Prevents possible bugs from stopping the addon.'''
     if not bpy.app.timers.is_registered(search.timer_update):
@@ -1258,19 +1257,19 @@ class BlenderKitModelSearchProps(PropertyGroup, BlenderKitCommonSearchProps):
 
     # DESIGN YEAR
     search_design_year: BoolProperty(name="Sesigned in Year",
-                                     description="when the object was approximately designed",
+                                     description="When the object was approximately designed",
                                      default=False,
                                      update=search.search_update,
                                      )
 
-    search_design_year_min: IntProperty(name="Min Age",
-                                        description="when the object was approximately designed",
+    search_design_year_min: IntProperty(name="Minimum Design Year",
+                                        description="Minimum design year",
                                         default=1950, min=-100000000, max=1000000000,
                                         update=search.search_update,
                                         )
 
-    search_design_year_max: IntProperty(name="Max Age",
-                                        description="when the object was approximately designed",
+    search_design_year_max: IntProperty(name="Maximum Design Year",
+                                        description="Maximum design year",
                                         default=2017,
                                         min=0,
                                         max=10000000,
@@ -1279,19 +1278,19 @@ class BlenderKitModelSearchProps(PropertyGroup, BlenderKitCommonSearchProps):
 
     # POLYCOUNT
     search_polycount: BoolProperty(name="Use Polycount",
-                                   description="use polycount of object search tag",
+                                   description="Use polycount of object search tag",
                                    default=False,
                                    update=search.search_update, )
 
     search_polycount_min: IntProperty(name="Min Polycount",
-                                      description="polycount of the asset minimum",
+                                      description="Minimum poly count of the asset",
                                       default=0,
                                       min=0,
                                       max=100000000,
                                       update=search.search_update, )
 
     search_polycount_max: IntProperty(name="Max Polycount",
-                                      description="polycount of the asset maximum",
+                                      description="Maximum poly count of the asset",
                                       default=100000000,
                                       min=0,
                                       max=100000000,
diff --git a/blenderkit/download.py b/blenderkit/download.py
index c9df6c0b..3a99f66f 100644
--- a/blenderkit/download.py
+++ b/blenderkit/download.py
@@ -441,6 +441,7 @@ def append_asset(asset_data, **kwargs):  # downloaders=[], location=None,
     scene['assets rated'][id] = scene['assets rated'].get(id, False)
 
     parent['asset_data'] = asset_data  # TODO remove this??? should write to blenderkit Props?
+    bpy.ops.wm.undo_push_context()
     # moving reporting to on save.
     # report_use_success(asset_data['id'])
 
diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py
index fd6bb2e8..96cbc01f 100644
--- a/blenderkit/ratings.py
+++ b/blenderkit/ratings.py
@@ -80,19 +80,30 @@ def uplaod_review_thread(url, reviews, headers):
     # except requests.exceptions.RequestException as e:
     #     print('reviews upload failed: %s' % str(e))
 
+def get_rating(asset_id):
+    user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
+    api_key = user_preferences.api_key
+    headers = utils.get_headers(api_key)
+    rl = paths.get_api_url() + 'assets/' + asset['asset_data']['id'] + '/rating/'
+    rtypes = ['quality', 'working_hours']
+    for rt in rtypes:
+        params = {
+            'rating_type' : rt
+        }
+        r = rerequests.get(r1, params=data, verify=True, headers=headers)
+        print(r.text)
 
 def upload_rating(asset):
     user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
     api_key = user_preferences.api_key
     headers = utils.get_headers(api_key)
 
-    asset_data = asset['asset_data']
-
     bkit_ratings = asset.bkit_ratings
     # print('rating asset', asset_data['name'], asset_data['asset_base_id'])
     url = paths.get_api_url() + 'assets/' + asset['asset_data']['id'] + '/rating/'
 
     ratings = [
+
     ]
 
     if bkit_ratings.rating_quality > 0.1:
diff --git a/blenderkit/search.py b/blenderkit/search.py
index f68306a6..c10a708c 100644
--- a/blenderkit/search.py
+++ b/blenderkit/search.py
@@ -504,7 +504,7 @@ def generate_tooltip(mdata):
 
     # t += 'uv: %s\n' % mdata['uv']
     # t += '\n'
-    # t = writeblockm(t, mdata, key='license', width = col_w)
+    t = writeblockm(t, mdata, key='license', width = col_w)
 
     # generator is for both upload preview and search, this is only after search
     # if mdata.get('versionNumber'):
@@ -748,6 +748,7 @@ class Searcher(threading.Thread):
             # assumes no keywords and no category, thus an empty search that is triggered on start.
             # orders by last core file upload
             requeststring += '+order:-last_upload'
+            # requeststring += '+order:-created'
         elif query.get('author_id') is not None and utils.profile_is_validator():
 
             requeststring += '+order:-created'
@@ -760,7 +761,7 @@ class Searcher(threading.Thread):
         requeststring += '&addon_version=%s' % params['addon_version']
         if params.get('scene_uuid') is not None:
             requeststring += '&scene_uuid=%s' % params['scene_uuid']
-        print('params', params)
+        # print('params', params)
         urlquery = url + requeststring
         return urlquery
 
@@ -801,7 +802,7 @@ class Searcher(threading.Thread):
         try:
             utils.p(urlquery)
             r = rerequests.get(urlquery, headers=headers)  # , params = rparameters)
-            print(r.url)
+            # print(r.url)
             reports = ''
             # utils.p(r.text)
         except requests.exceptions.RequestException as e:
@@ -1114,7 +1115,7 @@ def search(category='', get_next=False, author_id=''):
     user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
 
     search_start_time = time.time()
-    mt('start')
+    #mt('start')
     scene = bpy.context.scene
     uiprops = scene.blenderkitUI
 
diff --git a/blenderkit/ui.py b/blenderkit/ui.py
index f4b64a1f..3f4d0381 100644
--- a/blenderkit/ui.py
+++ b/blenderkit/ui.py
@@ -896,8 +896,12 @@ 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():
+        return;
+
     ui = context.scene.blenderkitUI
 
     if ui.dragging and ui.asset_type == 'MODEL':
@@ -1764,6 +1768,27 @@ class TransferBlenderkitData(bpy.types.Operator):
         return {'FINISHED'}
 
 
+class UndoWithContext(bpy.types.Operator):
+    """Regenerate cobweb"""
+    bl_idname = "wm.undo_push_context"
+    bl_label = "BlnenderKit undo push"
+    bl_description = "BlenderKit undo push with fixed context"
+    bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
+
+    # def modal(self, context, event):
+    #     return {'RUNNING_MODAL'}
+
+    def execute(self, context):
+        C_dict = bpy.context.copy()
+        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.ed.undo_push(C_dict, 'INVOKE_REGION_WIN')
+        return {'FINISHED'}
+
+
 class RunAssetBarWithContext(bpy.types.Operator):
     """Regenerate cobweb"""
     bl_idname = "object.run_assetbar_fix_context"
@@ -1782,18 +1807,28 @@ class RunAssetBarWithContext(bpy.types.Operator):
             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'}
+        return {'FINISHED'}
 
 
 classess = (
     AssetBarOperator,
     RunAssetBarWithContext,
-    TransferBlenderkitData
+    TransferBlenderkitData,
+    UndoWithContext
 )
 
 # store keymap items here to access after registration
 addon_keymapitems = []
 
+#@persistent
+def pre_load(context):
+    ui_props = bpy.context.scene.blenderkitUI
+    ui_props.assetbar_on = False
+    ui_props.turn_off = True
+    preferences = bpy.context.preferences.addons['blenderkit'].preferences
+    preferences.login_attempt = False
+
+
 
 def register_ui():
     global handler_2d, handler_3d
@@ -1824,6 +1859,7 @@ def register_ui():
 
 def unregister_ui():
     global handler_2d, handler_3d
+    pre_load(bpy.context)
 
     bpy.types.SpaceView3D.draw_handler_remove(handler_2d, 'WINDOW')
     bpy.types.SpaceView3D.draw_handler_remove(handler_3d, 'WINDOW')
diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py
index 00ff869e..8bd9fd58 100644
--- a/blenderkit/ui_panels.py
+++ b/blenderkit/ui_panels.py
@@ -44,7 +44,7 @@ def label_multiline(layout, text='', icon='NONE', width=-1):
         threshold = int(width / 5.5)
     else:
         threshold = 35
-    maxlines

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list