diff options
author | Vilém Duha <vilda.novak@gmail.com> | 2020-01-27 20:15:34 +0300 |
---|---|---|
committer | Vilém Duha <vilda.novak@gmail.com> | 2020-01-28 15:45:44 +0300 |
commit | f78b7f9618085f35edab46c5a599bdb1c5f843e0 (patch) | |
tree | 2b7fe5c3b4777865a4fdd8f319a140b308e5c473 /blenderkit | |
parent | 4300021a7a8ec4bd092237848daa1ecb96616df7 (diff) |
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
Diffstat (limited to 'blenderkit')
-rw-r--r-- | blenderkit/__init__.py | 17 | ||||
-rw-r--r-- | blenderkit/download.py | 1 | ||||
-rw-r--r-- | blenderkit/ratings.py | 15 | ||||
-rw-r--r-- | blenderkit/search.py | 9 | ||||
-rw-r--r-- | blenderkit/ui.py | 40 | ||||
-rw-r--r-- | blenderkit/ui_panels.py | 12 | ||||
-rw-r--r-- | blenderkit/utils.py | 10 |
7 files changed, 83 insertions, 21 deletions
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 = 6 + maxlines = 8 li = 0 for l in lines: while len(l) > threshold: @@ -584,7 +584,9 @@ def draw_panel_material_search(self, context): if props.search_advanced: layout.separator() - layout.prop(props, "search_procedural", expand=True) + layout.label(text = 'texture types') + col = layout.column() + col.prop(props, "search_procedural", expand=True) if props.search_procedural == 'TEXTURE_BASED': # TEXTURE RESOLUTION @@ -1046,6 +1048,10 @@ class VIEW3D_PT_blenderkit_downloads(Panel): def header_search_draw(self, context): '''Top bar menu in 3d view''' + + if not utils.guard_from_crash(): + return; + preferences = bpy.context.preferences.addons['blenderkit'].preferences if preferences.search_in_header: layout = self.layout @@ -1071,7 +1077,6 @@ def header_search_draw(self, context): preview_collections = {} classess = ( SetCategoryOperator, - VIEW3D_PT_blenderkit_profile, VIEW3D_PT_blenderkit_login, VIEW3D_PT_blenderkit_unified, @@ -1090,5 +1095,6 @@ def register_ui_panels(): def unregister_ui_panels(): for c in classess: + print('unregister', c) bpy.utils.unregister_class(c) bpy.types.VIEW3D_MT_editor_menus.remove(header_search_draw) diff --git a/blenderkit/utils.py b/blenderkit/utils.py index b4cd34c2..706600ee 100644 --- a/blenderkit/utils.py +++ b/blenderkit/utils.py @@ -550,4 +550,12 @@ def profile_is_validator(): a = bpy.context.window_manager.get('bkit profile') if a is not None and a['user'].get('exmenu'): return True - return False
\ No newline at end of file + return False + +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: + return False; + if bpy.context.preferences.addons['blenderkit'].preferences is None: + return False; + return True
\ No newline at end of file |