diff options
author | Vilém Duha <vilda.novak@gmail.com> | 2020-02-13 18:17:18 +0300 |
---|---|---|
committer | Vilém Duha <vilda.novak@gmail.com> | 2020-02-13 18:17:18 +0300 |
commit | 47d56e88240dc330e9173c668f1ee9fee39fb36c (patch) | |
tree | cc8607c4127eddce1d631ac271ec45d11a88b0cc | |
parent | 9541def220aa4d81c754e46d8a701748a3245ba4 (diff) | |
parent | 6b61dff0841600368710710894ccc0c20867929f (diff) |
Merge branch 'blender-v2.82-release'
-rw-r--r-- | blenderkit/__init__.py | 13 | ||||
-rw-r--r-- | blenderkit/search.py | 47 | ||||
-rw-r--r-- | blenderkit/ui.py | 29 | ||||
-rw-r--r-- | blenderkit/ui_panels.py | 70 | ||||
-rw-r--r-- | blenderkit/utils.py | 2 |
5 files changed, 133 insertions, 28 deletions
diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py index bf0ec328..d64ea133 100644 --- a/blenderkit/__init__.py +++ b/blenderkit/__init__.py @@ -400,7 +400,7 @@ class BlenderKitCommonSearchProps(object): search_done: BoolProperty(name="Search Completed", description="at least one search did run (internal)", default=False) own_only: BoolProperty(name="My Assets", description="Search only for your assets", - default=False) + default=False, update=search.search_update) search_advanced: BoolProperty(name="Advanced Search Options", description="use advanced search properties", default=False, update=search.search_update) @@ -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 ) @@ -1651,8 +1652,9 @@ def register(): def unregister(): bpy.app.timers.unregister(check_timers_timer) - + ui_panels.unregister_ui_panels() ui.unregister_ui() + icons.unregister_icons() search.unregister_search() asset_inspector.unregister_asset_inspector() @@ -1660,7 +1662,6 @@ def unregister(): upload.unregister_upload() ratings.unregister_ratings() autothumb.unregister_thumbnailer() - ui_panels.unregister_ui_panels() bg_blender.unregister() overrides.unregister_overrides() bkit_oauth.unregister() diff --git a/blenderkit/search.py b/blenderkit/search.py index 6eeafcd1..bf430d91 100644 --- a/blenderkit/search.py +++ b/blenderkit/search.py @@ -132,7 +132,7 @@ last_clipboard = '' @bpy.app.handlers.persistent -def timer_update(): # TODO might get moved to handle all blenderkit stuff. +def timer_update(): # this makes a first search after opening blender. showing latest assets. global first_time preferences = bpy.context.preferences.addons['blenderkit'].preferences @@ -148,24 +148,25 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff. # 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.py b/blenderkit/ui.py index 2101e54b..b0753a08 100644 --- a/blenderkit/ui.py +++ b/blenderkit/ui.py @@ -602,6 +602,9 @@ def draw_tooltip_old(x, y, text='', author='', img=None): def draw_callback_2d(self, context): + if not utils.guard_from_crash(): + return; + a = context.area w = context.window try: @@ -769,6 +772,7 @@ def draw_callback_2d_search(self, context): ui_props.thumb_size, img, 1) + if search_results_orig['count'] - ui_props.scrolloffset > (ui_props.wcount * ui_props.hcount) + 1: if ui_props.active_index == -1: ui_bgl.draw_rect(ui_props.bar_x + ui_props.bar_width - 25, @@ -782,6 +786,7 @@ def draw_callback_2d_search(self, context): for b in range(0, h_draw): w_draw = min(ui_props.wcount, len(search_results) - b * ui_props.wcount - ui_props.scrolloffset) + y = ui_props.bar_y - (b + 1) * (row_height) for a in range(0, w_draw): x = ui_props.bar_x + a * ( @@ -896,7 +901,6 @@ 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(): @@ -1110,7 +1114,16 @@ def mouse_in_area(mx, my, x, y, w, h): def mouse_in_asset_bar(mx, my): + s = bpy.context.scene + ui_props = bpy.context.scene.blenderkitUI + # search_results = s.get('search results') + # if search_results == None: + # return False + # + # w_draw1 = min(ui_props.wcount + 1, len(search_results) - b * ui_props.wcount - ui_props.scrolloffset) + # end = ui_props.bar_x + (w_draw1) * ( + # ui_props.margin + ui_props.thumb_size) + ui_props.margin + ui_props.drawoffset + 25 if ui_props.bar_y - ui_props.bar_height < my < ui_props.bar_y \ and mx > ui_props.bar_x and mx < ui_props.bar_x + ui_props.bar_width: @@ -1575,8 +1588,8 @@ class AssetBarOperator(bpy.types.Operator): else: # first, test if object can have material applied. - #TODO add other types here if droppable. - if object is None or object.is_library_indirect and object.type =='MESH' : + # TODO add other types here if droppable. + if object is not None and not object.is_library_indirect and object.type == 'MESH': target_object = object.name # create final mesh to extract correct material slot depsgraph = bpy.context.evaluated_depsgraph_get() @@ -1725,8 +1738,6 @@ class AssetBarOperator(bpy.types.Operator): self.area = context.area self.scene = bpy.context.scene - - self.has_quad_views = len(bpy.context.area.spaces[0].region_quadviews) > 0 for r in self.area.regions: @@ -1779,7 +1790,7 @@ class UndoWithContext(bpy.types.Operator): # def modal(self, context, event): # return {'RUNNING_MODAL'} - message = StringProperty('Undo Message', default = 'BlenderKit operation') + message: StringProperty('Undo Message', default='BlenderKit operation') def execute(self, context): C_dict = bpy.context.copy() @@ -1788,7 +1799,7 @@ class UndoWithContext(bpy.types.Operator): 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', message = self.message) + bpy.ops.ed.undo_push(C_dict, 'INVOKE_REGION_WIN', message=self.message) return {'FINISHED'} @@ -1823,7 +1834,8 @@ classess = ( # store keymap items here to access after registration addon_keymapitems = [] -#@persistent + +# @persistent def pre_load(context): ui_props = bpy.context.scene.blenderkitUI ui_props.assetbar_on = False @@ -1832,7 +1844,6 @@ def pre_load(context): preferences.login_attempt = False - def register_ui(): global handler_2d, handler_3d diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py index 3dabbe68..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: @@ -672,6 +676,67 @@ def draw_login_buttons(layout): icon='URL') +class VIEW3D_PT_blenderkit_advanced_model_search(Panel): + bl_category = "BlenderKit" + bl_idname = "VIEW3D_PT_blenderkit_advanced_model_search" + # bl_parent_id = "VIEW3D_PT_blenderkit_unified" + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_label = "Advanced search options" + + @classmethod + def poll(cls, context): + return True + + def draw(self, context): + s = context.scene + + props = s.blenderkit_models + layout = self.layout + layout.separator() + + # layout.label(text = "common searches keywords:") + # layout.prop(props, "search_global_keywords", text = "") + # layout.prop(props, "search_modifier_keywords") + # if props.search_engine == 'OTHER': + # layout.prop(props, "search_engine_keyword") + + # AGE + layout.prop(props, "search_condition", text='Condition') # , text ='condition of object new/old e.t.c.') + + # DESIGN YEAR + layout.prop(props, "search_design_year", text='designed in ( min - max )') + if props.search_design_year: + row = layout.row(align=True) + row.prop(props, "search_design_year_min", text='min') + row.prop(props, "search_design_year_max", text='max') + + # POLYCOUNT + layout.prop(props, "search_polycount", text='Poly count in ( min - max )') + if props.search_polycount: + row = layout.row(align=True) + row.prop(props, "search_polycount_min", text='min') + row.prop(props, "search_polycount_max", text='max') + + # TEXTURE RESOLUTION + layout.prop(props, "search_texture_resolution", text='texture resolution ( min - max )') + if props.search_texture_resolution: + row = layout.row(align=True) + row.prop(props, "search_texture_resolution_min", text='min') + row.prop(props, "search_texture_resolution_max", text='max') + + # FILE SIZE + layout.prop(props, "search_file_size", text='File size ( min - max )') + if props.search_file_size: + row = layout.row(align=True) + row.prop(props, "search_file_size_min", text='min') + row.prop(props, "search_file_size_max", text='max') + + # layout.prop(props, "search_procedural", expand=True) + # ADULT + # layout.prop(props, "search_adult") # , text ='condition of object new/old e.t.c.') + + class VIEW3D_PT_blenderkit_unified(Panel): bl_category = "BlenderKit" bl_idname = "VIEW3D_PT_blenderkit_unified" @@ -1085,6 +1150,7 @@ classess = ( VIEW3D_PT_blenderkit_profile, VIEW3D_PT_blenderkit_login, VIEW3D_PT_blenderkit_unified, + # VIEW3D_PT_blenderkit_advanced_model_search, VIEW3D_PT_blenderkit_model_properties, VIEW3D_PT_blenderkit_downloads, OBJECT_MT_blenderkit_asset_menu, @@ -1099,7 +1165,7 @@ def register_ui_panels(): def unregister_ui_panels(): + bpy.types.VIEW3D_MT_editor_menus.remove(header_search_draw) 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 706600ee..fe80e1a0 100644 --- a/blenderkit/utils.py +++ b/blenderkit/utils.py @@ -554,7 +554,7 @@ def profile_is_validator(): 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: + if bpy.context.preferences.addons.get('blenderkit') is None: return False; if bpy.context.preferences.addons['blenderkit'].preferences is None: return False; |