diff options
author | Vilem Duha <vilem.duha@gmail.com> | 2021-10-13 12:53:58 +0300 |
---|---|---|
committer | Vilem Duha <vilem.duha@gmail.com> | 2021-10-13 12:54:07 +0300 |
commit | 7c099b03e4ff3ffffc120bbcc7f30ca466763d24 (patch) | |
tree | 3eb7872bc7496c0028b17fee251b22498bb88e3f | |
parent | 5103e930330419d6783350f79937c6176779bd61 (diff) |
BlenderKit: improvements to new assetbar
Almost ready for the switch to default.
-rw-r--r-- | blenderkit/__init__.py | 4 | ||||
-rw-r--r-- | blenderkit/asset_bar_op.py | 298 | ||||
-rw-r--r-- | blenderkit/bl_ui_widgets/bl_ui_drag_panel.py | 1 | ||||
-rw-r--r-- | blenderkit/search.py | 4 | ||||
-rw-r--r-- | blenderkit/ui.py | 60 | ||||
-rw-r--r-- | blenderkit/utils.py | 4 |
6 files changed, 208 insertions, 163 deletions
diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py index f6fcb155..bbae65f3 100644 --- a/blenderkit/__init__.py +++ b/blenderkit/__init__.py @@ -311,7 +311,7 @@ def run_drag_drop_update(self, context): # ctx = utils.get_fake_context(bpy.context) bpy.ops.view3d.close_popup_button('INVOKE_DEFAULT') - bpy.ops.view3d.asset_drag_drop('INVOKE_DEFAULT', asset_search_index=ui_props.active_index + ui_props.scrolloffset) + bpy.ops.view3d.asset_drag_drop('INVOKE_DEFAULT', asset_search_index=ui_props.active_index + ui_props.scroll_offset) self.drag_init_button = False @@ -378,7 +378,7 @@ class BlenderKitUIProps(PropertyGroup): mouse_y: IntProperty(name="Mouse Y", default=0) active_index: IntProperty(name="Active Index", default=-3) - scrolloffset: IntProperty(name="Scroll Offset", default=0) + scroll_offset: IntProperty(name="Scroll Offset", default=0) drawoffset: IntProperty(name="Draw Offset", default=0) dragging: BoolProperty(name="Dragging", default=False) diff --git a/blenderkit/asset_bar_op.py b/blenderkit/asset_bar_op.py index 8727698d..b3de3502 100644 --- a/blenderkit/asset_bar_op.py +++ b/blenderkit/asset_bar_op.py @@ -30,8 +30,11 @@ def draw_callback_tooltip(self, context): r = sr[self.active_index] ui.draw_tooltip_with_author(r, 0, 500) + def get_area_height(self): - if type(self.context)!= dict: + if type(self.context) != dict: + if self.context is None: + self.context = bpy.context self.context = self.context.copy() # print(self.context) if self.context.get('area') is not None: @@ -48,11 +51,12 @@ def get_area_height(self): # print('no area found') return 100 + BL_UI_Widget.get_area_height = get_area_height def asset_bar_modal(self, context, event): - ui_props = bpy.context.scene.blenderkitUI + ui_props = bpy.context.window_manager.blenderkitUI if ui_props.turn_off: ui_props.turn_off = False self.finish() @@ -81,13 +85,14 @@ def asset_bar_modal(self, context, event): self.scroll_update() return {'RUNNING_MODAL'} - if self.check_ui_resized(context): + if self.check_ui_resized(context) or self.check_new_search_results(context): self.update_ui_size(context) - self.update_layout(context) + self.update_layout(context, event) + return {"PASS_THROUGH"} -def asset_bar_invoke(self, context, event): +def asset_bar_invoke(self, context, event): if not self.on_invoke(context, event): return {"CANCELLED"} @@ -98,6 +103,7 @@ def asset_bar_invoke(self, context, event): context.window_manager.modal_handler_add(self) return {"RUNNING_MODAL"} + BL_UI_OT_draw_operator.modal = asset_bar_modal BL_UI_OT_draw_operator.invoke = asset_bar_invoke @@ -118,6 +124,7 @@ def mouse_down_right(self, x, y): return False + # def handle_event(self, event): # x = event.mouse_region_x # y = event.mouse_region_y @@ -162,9 +169,9 @@ def mouse_down_right(self, x, y): BL_UI_Button.mouse_down_right = mouse_down_right BL_UI_Button.set_mouse_down_right = set_mouse_down_right -# BL_UI_Button.handle_event = handle_event +# BL_UI_Button.handle_event = handle_event class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): @@ -221,7 +228,7 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): dark_panel.bg_color = (0.0, 0.0, 0.0, 0.7) self.tooltip_widgets.append(dark_panel) - name_label = self.new_text('', self.assetbar_margin*2, labels_start, text_size=16) + name_label = self.new_text('', self.assetbar_margin * 2, labels_start, text_size=16) self.asset_name = name_label self.tooltip_widgets.append(name_label) offset_y = 16 + self.margin @@ -229,9 +236,6 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): # text_size=14) # self.tooltip_widgets.append(label) - - self.hide_tooltip() - def hide_tooltip(self): self.tooltip_panel.visible = False for w in self.tooltip_widgets: @@ -242,16 +246,34 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): for w in self.tooltip_widgets: w.visible = True - def check_ui_resized(self,context): + def check_new_search_results(self, context): + sr = bpy.context.window_manager.get('search results',[]) + if not hasattr(self, 'search_results_count'): + self.search_results_count = len(sr) + if len(sr)!= self.search_results_count: + self.search_results_count = len(sr) + return True + return False + + def check_ui_resized(self, context): + #TODO this should only check if region was resized, not really care about the UI elements size. region = context.region area = context.area - ui_props = bpy.context.scene.blenderkitUI + ui_props = bpy.context.window_manager.blenderkitUI ui_scale = bpy.context.preferences.view.ui_scale - + #just check the size of region.. + if not hasattr(self,'region_width'): + self.region_width = region.width + self.region_height = region.height + if region.height != self.region_height or region.width != self.region_width: + return True + return False + # this actually calculated UI elements, which is unnecessary reg_multiplier = 1 if not bpy.context.preferences.system.use_region_overlap: reg_multiplier = 0 + for r in area.regions: if r.type == 'TOOLS': self.bar_x = r.width * reg_multiplier + self.margin + ui_props.bar_x_offset * ui_scale @@ -259,9 +281,15 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): self.bar_end = r.width * reg_multiplier + 100 * ui_scale bar_width = region.width - self.bar_x - self.bar_end + + bar_y = ui_props.bar_y_offset * ui_scale + + changed = False if bar_width != self.bar_width: - return True - return False + changed = True + if bar_y != self.bar_y: + changed = True + return changed def update_ui_size(self, context): @@ -271,12 +299,12 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): region = context.region area = context.area - ui_props = bpy.context.scene.blenderkitUI + ui_props = bpy.context.window_manager.blenderkitUI user_preferences = bpy.context.preferences.addons['blenderkit'].preferences ui_scale = bpy.context.preferences.view.ui_scale self.margin = ui_props.bl_rna.properties['margin'].default * ui_scale - self.margin = 3 + self.margin = 1 self.assetbar_margin = self.margin self.thumb_size = user_preferences.thumb_size * ui_scale @@ -299,11 +327,12 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): search_results = bpy.context.window_manager.get('search results') # we need to init all possible thumb previews in advance/ - self.hcount = user_preferences.max_assetbar_rows - # if search_results is not None and self.wcount > 0: - # self.hcount = min(user_preferences.max_assetbar_rows, math.ceil(len(search_results) / self.wcount)) - # else: - # self.hcount = 1 + # self.hcount = user_preferences.max_assetbar_rows + if search_results is not None and self.wcount > 0: + self.hcount = min(user_preferences.max_assetbar_rows, math.ceil(len(search_results) / self.wcount)) + self.hcount = max(self.hcount,1) + else: + self.hcount = 1 self.bar_height = (self.button_size) * self.hcount + 2 * self.assetbar_margin # self.bar_y = region.height - ui_props.bar_y_offset * ui_scale @@ -315,26 +344,55 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): self.reports_y = self.bar_y - self.bar_height - 100 self.reports_x = self.bar_x - def update_layout(self, context): - pass; - - def __init__(self): - super().__init__() - - self.update_ui_size(bpy.context) - - ui_props = bpy.context.scene.blenderkitUI - - # todo move all this to update UI size + def update_layout(self, context, event): + self.init_ui() + self.setup_widgets(context, event) - self.draw_tooltip = False - self.scroll_offset = 0 - - self.text_color = (0.9, 0.9, 0.9, 1.0) + def asset_button_init(self, asset_x, asset_y, button_idx): button_bg_color = (0.2, 0.2, 0.2, .1) button_hover_color = (0.8, 0.8, 0.8, .2) - self.init_tooltip() + new_button = BL_UI_Button(asset_x, asset_y, self.button_size, self.button_size) + + # asset_data = sr[asset_idx] + # iname = blenderkit.utils.previmg_name(asset_idx) + # img = bpy.data.images.get(iname) + + new_button.bg_color = button_bg_color + new_button.hover_bg_color = button_hover_color + new_button.text = "" # asset_data['name'] + # if img: + # new_button.set_image(img.filepath) + + new_button.set_image_size((self.thumb_size, self.thumb_size)) + new_button.set_image_position((self.margin, self.margin)) + new_button.button_index = button_idx + new_button.search_index = button_idx + new_button.set_mouse_down(self.drag_drop_asset) + new_button.set_mouse_down_right(self.asset_menu) + new_button.set_mouse_enter(self.enter_button) + new_button.set_mouse_exit(self.exit_button) + new_button.text_input = self.handle_key_input + self.asset_buttons.append(new_button) + # add validation icon to button + icon_size = 24 + validation_icon = BL_UI_Button(asset_x + self.button_size - icon_size - self.margin, + asset_y + self.button_size - icon_size - self.margin, 0, 0) + + # v_icon = ui.verification_icons[asset_data.get('verificationStatus', 'validated')] + # if v_icon is not None: + # img_fp = paths.get_addon_thumbnail_path(v_icon) + # validation_icon.set_image(img_fp) + validation_icon.text = '' + validation_icon.set_image_size((icon_size, icon_size)) + validation_icon.set_image_position((0, 0)) + self.validation_icons.append(validation_icon) + new_button.validation_icon = validation_icon + return new_button + + def init_ui(self): + button_bg_color = (0.2, 0.2, 0.2, .1) + button_hover_color = (0.8, 0.8, 0.8, .2) self.buttons = [] self.asset_buttons = [] @@ -344,47 +402,16 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): self.panel = BL_UI_Drag_Panel(0, 0, self.bar_width, self.bar_height) self.panel.bg_color = (0.0, 0.0, 0.0, 0.5) + sr = bpy.context.window_manager.get('search results', []) for a in range(0, self.wcount): for b in range(0, self.hcount): + asset_x = self.assetbar_margin + a * (self.button_size) asset_y = self.assetbar_margin + b * (self.button_size) - new_button = BL_UI_Button(asset_x, asset_y, self.button_size, self.button_size) - + button_idx = a + b * self.wcount asset_idx = a + b * self.wcount + self.scroll_offset - # asset_data = sr[asset_idx] - # iname = blenderkit.utils.previmg_name(asset_idx) - # img = bpy.data.images.get(iname) - - new_button.bg_color = button_bg_color - new_button.hover_bg_color = button_hover_color - new_button.text = "" # asset_data['name'] - # if img: - # new_button.set_image(img.filepath) - - new_button.set_image_size((self.thumb_size, self.thumb_size)) - new_button.set_image_position((self.margin, self.margin)) - new_button.button_index = asset_idx - new_button.search_index = asset_idx - new_button.set_mouse_down(self.drag_drop_asset) - new_button.set_mouse_down_right(self.asset_menu) - new_button.set_mouse_enter(self.enter_button) - new_button.set_mouse_exit(self.exit_button) - new_button.text_input = self.handle_key_input - self.asset_buttons.append(new_button) - # add validation icon to button - icon_size = 24 - validation_icon = BL_UI_Button(asset_x + self.button_size - icon_size - self.margin, - asset_y + self.button_size - icon_size - self.margin, 0, 0) - - # v_icon = ui.verification_icons[asset_data.get('verificationStatus', 'validated')] - # if v_icon is not None: - # img_fp = paths.get_addon_thumbnail_path(v_icon) - # validation_icon.set_image(img_fp) - validation_icon.text = '' - validation_icon.set_image_size((icon_size, icon_size)) - validation_icon.set_image_position((0, 0)) - self.validation_icons.append(validation_icon) - new_button.validation_icon = validation_icon + if asset_idx < len(sr): + new_button = self.asset_button_init(asset_x, asset_y, button_idx) other_button_size = 30 @@ -422,11 +449,49 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): self.update_images() + def __init__(self): + super().__init__() + + self.update_ui_size(bpy.context) + + # todo move all this to update UI size + ui_props = bpy.context.window_manager.blenderkitUI + + self.draw_tooltip = False + # let's take saved scroll offset and use it to keep scroll between operator runs + self.scroll_offset = ui_props.scroll_offset + + self.text_color = (0.9, 0.9, 0.9, 1.0) + + self.init_ui() + self.init_tooltip() + self.hide_tooltip() + + def setup_widgets(self, context, event): + widgets_panel = self.widgets_panel + widgets_panel.extend(self.buttons) + widgets_panel.extend(self.asset_buttons) + widgets_panel.extend(self.validation_icons) + + widgets = [self.panel] + + widgets += widgets_panel + widgets.append(self.tooltip_panel) + widgets += self.tooltip_widgets + + self.init_widgets(context, widgets) + + self.panel.add_widgets(widgets_panel) + + self.panel.set_location(self.bar_x, + self.bar_y) + def on_invoke(self, context, event): + self.context = context if self.do_search: - #TODO: move the search behaviour to separate operator, since asset bar can be already woken up from a timer. + # TODO: move the search behaviour to separate operator, since asset bar can be already woken up from a timer. # we erase search keywords for cateogry search now, since these combinations usually return nothing now. # when the db gets bigger, this can be deleted. @@ -435,12 +500,13 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): sprops.search_keywords = '' search.search(category=self.category) - ui_props = context.scene.blenderkitUI + ui_props = context.window_manager.blenderkitUI if ui_props.assetbar_on: - #TODO solve this otehrwise to enable more asset bars? + # TODO solve this otehrwise to enable more asset bars? # we don't want to run the assetbar many times, that's why it has a switch on/off behaviour, # unless being called with 'keep_running' prop. + if not self.keep_running: # this sends message to the originally running operator, so it quits, and then it ends this one too. # If it initiated a search, the search will finish in a thread. The switch off procedure is run @@ -454,36 +520,13 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): pass return False - ui_props.assetbar_on = True + ui_props.assetbar_on = True self.active_index = -1 - widgets_panel = self.widgets_panel - widgets_panel.extend(self.buttons) - widgets_panel.extend(self.asset_buttons) - widgets_panel.extend(self.validation_icons) - - widgets = [self.panel] - - widgets += widgets_panel - widgets.append(self.tooltip_panel) - widgets += self.tooltip_widgets - - self.init_widgets(context, widgets) - - self.panel.add_widgets(widgets_panel) + self.setup_widgets(context, event) self.tooltip_panel.add_widgets(self.tooltip_widgets) - # Open the panel at the mouse location - # self.panel.set_location(bpy.context.area.width - event.mouse_x, - # bpy.context.area.height - event.mouse_y + 20) - self.panel.set_location(self.bar_x, - self.bar_y) - - self.context = context - args = (self, context) - - # self._handle_2d_tooltip = bpy.types.SpaceView3D.draw_handler_add(draw_callback_tooltip, args, 'WINDOW', 'POST_PIXEL') return True def on_finish(self, context): @@ -491,58 +534,63 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): # bpy.types.SpaceView3D.draw_handler_remove(self._handle_2d_tooltip, 'WINDOW') scene = bpy.context.scene - ui_props = scene.blenderkitUI + ui_props = bpy.context.window_manager.blenderkitUI ui_props.assetbar_on = False + ui_props.scroll_offset = self.scroll_offset wm = bpy.data.window_managers[0] for w in wm.windows: for a in w.screen.areas: a.tag_redraw() - self._finished = True # handlers def enter_button(self, widget): - # context.window.cursor_warp(event.mouse_x, event.mouse_y - 20); + # print('enter button', self.active_index, widget.button_index) + # print(widget.button_index+ self.scroll_offset, self.active_index) + search_index = widget.button_index + self.scroll_offset + if search_index < self.search_results_count: + self.show_tooltip() + if self.active_index != search_index: + self.active_index = search_index - self.show_tooltip() - - if self.active_index != widget.search_index: scene = bpy.context.scene wm = bpy.context.window_manager sr = wm['search results'] - asset_data = sr[widget.search_index + self.scroll_offset] + asset_data = sr[search_index]# + self.scroll_offset] + - self.active_index = widget.search_index self.draw_tooltip = True # self.tooltip = asset_data['tooltip'] - ui_props = scene.blenderkitUI - ui_props.active_index = widget.search_index +self.scroll_offset + ui_props = bpy.context.window_manager.blenderkitUI + ui_props.active_index = search_index #+ self.scroll_offset img = ui.get_large_thumbnail_image(asset_data) if img: self.tooltip_image.set_image(img.filepath) self.asset_name.text = asset_data['name'] - + print('moving tooltip') properties_width = 0 for r in bpy.context.area.regions: if r.type == 'UI': properties_width = r.width - tooltip_x = min(widget.x_screen + widget.width, bpy.context.region.width - self.tooltip_panel.width -properties_width) - - self.tooltip_panel.update(tooltip_x, widget.y_screen + widget.height) + tooltip_x = min(widget.x_screen + widget.width, + bpy.context.region.width - self.tooltip_panel.width - properties_width) + tooltip_y = widget.y_screen + widget.height + self.tooltip_panel.update(tooltip_x, tooltip_y) self.tooltip_panel.layout_widgets() + print(tooltip_x, tooltip_y) # bpy.ops.wm.blenderkit_asset_popup('INVOKE_DEFAULT') - def exit_button(self, widget): + # print(f'exit {widget.search_index} , {self.active_index}') # this condition checks if there wasn't another button already entered, which can happen with small button gaps - if self.active_index == widget.search_index: + if self.active_index == widget.button_index + self.scroll_offset: scene = bpy.context.scene - ui_props = scene.blenderkitUI + ui_props = bpy.context.window_manager.blenderkitUI ui_props.draw_tooltip = False self.draw_tooltip = False self.hide_tooltip() @@ -602,10 +650,12 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): def scroll_update(self): sr = bpy.context.window_manager['search results'] + sro = bpy.context.window_manager['search results orig'] self.scroll_offset = min(self.scroll_offset, len(sr) - (self.wcount * self.hcount)) self.scroll_offset = max(self.scroll_offset, 0) self.update_images() - if len(sr) - self.scroll_offset < (self.wcount * self.hcount) + 15: + + if sro['count'] > len(sr) and len(sr) - self.scroll_offset < (self.wcount * self.hcount) + 15: self.search_more() def search_by_author(self, asset_index): @@ -633,14 +683,6 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator): self.scroll_offset -= self.wcount * self.hcount self.scroll_update() - def update_sizes(self): - properties_width = 0 - for r in bpy.context.area.regions: - if r.type == 'UI': - properties_width = r.width - tooltip_x = min(widget.x_screen + widget.width, - bpy.context.region.width - self.tooltip_panel.width - properties_width) - # print(widget.x_screen + widget.width, bpy.context.region.width - self.tooltip_panel.width) def register(): diff --git a/blenderkit/bl_ui_widgets/bl_ui_drag_panel.py b/blenderkit/bl_ui_widgets/bl_ui_drag_panel.py index 44a5b1b9..1c318bab 100644 --- a/blenderkit/bl_ui_widgets/bl_ui_drag_panel.py +++ b/blenderkit/bl_ui_widgets/bl_ui_drag_panel.py @@ -20,6 +20,7 @@ class BL_UI_Drag_Panel(BL_UI_Widget): self.widgets = widgets self.layout_widgets() + def layout_widgets(self): for widget in self.widgets: widget.update(self.x_screen + widget.x, self.y_screen + widget.y) diff --git a/blenderkit/search.py b/blenderkit/search.py index 4938a7b9..83729d1b 100644 --- a/blenderkit/search.py +++ b/blenderkit/search.py @@ -460,9 +460,9 @@ def search_timer(): wm[search_name + ' orig'] = rdata wm['search results orig'] = rdata - if len(result_field) < ui_props.scrolloffset or not (thread[0].params.get('get_next')): + if len(result_field) < ui_props.scroll_offset or not (thread[0].params.get('get_next')): # jump back - ui_props.scrolloffset = 0 + ui_props.scroll_offset = 0 props.search_error = False props.report = 'Found %i results. ' % (wm['search results orig']['count']) if len(wm['search results']) == 0: diff --git a/blenderkit/ui.py b/blenderkit/ui.py index ea0c36a8..d3590469 100644 --- a/blenderkit/ui.py +++ b/blenderkit/ui.py @@ -150,7 +150,7 @@ def get_asset_under_mouse(mousex, mousey): h_draw = min(ui_props.hcount, math.ceil(len(search_results) / ui_props.wcount)) for b in range(0, h_draw): - w_draw = min(ui_props.wcount, len(search_results) - b * ui_props.wcount - ui_props.scrolloffset) + w_draw = min(ui_props.wcount, len(search_results) - b * ui_props.wcount - ui_props.scroll_offset) for a in range(0, w_draw): x = ui_props.bar_x + a * (ui_props.margin + ui_props.thumb_size) + ui_props.margin + ui_props.drawoffset y = ui_props.bar_y - ui_props.margin - (ui_props.thumb_size + ui_props.margin) * (b + 1) @@ -158,7 +158,7 @@ def get_asset_under_mouse(mousex, mousey): h = ui_props.thumb_size if x < mousex < x + w and y < mousey < y + h: - return a + ui_props.wcount * b + ui_props.scrolloffset + return a + ui_props.wcount * b + ui_props.scroll_offset # return search_results[a] @@ -636,7 +636,7 @@ def draw_asset_bar(self, context): ui_props.bar_height, hc) if search_results is not None: - if ui_props.scrolloffset > 0 or ui_props.wcount * ui_props.hcount < len(search_results): + if ui_props.scroll_offset > 0 or ui_props.wcount * ui_props.hcount < len(search_results): ui_props.drawoffset = 35 else: ui_props.drawoffset = 0 @@ -644,7 +644,7 @@ def draw_asset_bar(self, context): if ui_props.wcount * ui_props.hcount < len(search_results): # arrows arrow_y = ui_props.bar_y - int((ui_props.bar_height + ui_props.thumb_size) / 2) + ui_props.margin - if ui_props.scrolloffset > 0: + if ui_props.scroll_offset > 0: if ui_props.active_index == -2: ui_bgl.draw_rect(ui_props.bar_x, ui_props.bar_y - ui_props.bar_height, 25, @@ -655,7 +655,7 @@ def draw_asset_bar(self, context): img, 1) - if search_results_orig['count'] - ui_props.scrolloffset > (ui_props.wcount * ui_props.hcount) + 1: + if search_results_orig['count'] - ui_props.scroll_offset > (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, ui_props.bar_y - ui_props.bar_height, 25, @@ -667,7 +667,7 @@ def draw_asset_bar(self, context): ui_props.thumb_size, img1, 1) ar = context.window_manager.get('asset ratings') for b in range(0, h_draw): - w_draw = min(ui_props.wcount, len(search_results) - b * ui_props.wcount - ui_props.scrolloffset) + w_draw = min(ui_props.wcount, len(search_results) - b * ui_props.wcount - ui_props.scroll_offset) y = ui_props.bar_y - (b + 1) * (row_height) for a in range(0, w_draw): @@ -675,7 +675,7 @@ def draw_asset_bar(self, context): ui_props.margin + ui_props.thumb_size) + ui_props.margin + ui_props.drawoffset # - index = a + ui_props.scrolloffset + b * ui_props.wcount + index = a + ui_props.scroll_offset + b * ui_props.wcount iname = utils.previmg_name(index) img = bpy.data.images.get(iname) if img is not None and img.size[0] > 0 and img.size[1] > 0: @@ -971,7 +971,7 @@ def mouse_in_asset_bar(mx, my): # if search_results == None: # return False # - # w_draw1 = min(ui_props.wcount + 1, len(search_results) - b * ui_props.wcount - ui_props.scrolloffset) + # w_draw1 = min(ui_props.wcount + 1, len(search_results) - b * ui_props.wcount - ui_props.scroll_offset) # end = ui_props.bar_x + (w_draw1) * ( # ui_props.margin + ui_props.thumb_size) + ui_props.margin + ui_props.drawoffset + 25 @@ -1296,7 +1296,7 @@ class AssetBarOperator(bpy.types.Operator): # If there aren't any results, we need no interaction(yet) if sr is None: return {'PASS_THROUGH'} - if len(sr) - ui_props.scrolloffset < (ui_props.wcount * user_preferences.max_assetbar_rows) + 15: + if len(sr) - ui_props.scroll_offset < (ui_props.wcount * user_preferences.max_assetbar_rows) + 15: self.search_more() if event.type == 'WHEELUPMOUSE' or event.type == 'WHEELDOWNMOUSE' or event.type == 'TRACKPADPAN': @@ -1311,22 +1311,22 @@ class AssetBarOperator(bpy.types.Operator): # if event.type == 'TRACKPADPAN' : # print(dir(event)) # print(event.value, event.oskey, event.) - if (event.type == 'WHEELDOWNMOUSE') and len(sr) - ui_props.scrolloffset > ( + if (event.type == 'WHEELDOWNMOUSE') and len(sr) - ui_props.scroll_offset > ( ui_props.wcount * ui_props.hcount): if ui_props.hcount > 1: - ui_props.scrolloffset += ui_props.wcount + ui_props.scroll_offset += ui_props.wcount else: - ui_props.scrolloffset += 1 - if len(sr) - ui_props.scrolloffset < (ui_props.wcount * ui_props.hcount): - ui_props.scrolloffset = len(sr) - (ui_props.wcount * ui_props.hcount) + ui_props.scroll_offset += 1 + if len(sr) - ui_props.scroll_offset < (ui_props.wcount * ui_props.hcount): + ui_props.scroll_offset = len(sr) - (ui_props.wcount * ui_props.hcount) - if event.type == 'WHEELUPMOUSE' and ui_props.scrolloffset > 0: + if event.type == 'WHEELUPMOUSE' and ui_props.scroll_offset > 0: if ui_props.hcount > 1: - ui_props.scrolloffset -= ui_props.wcount + ui_props.scroll_offset -= ui_props.wcount else: - ui_props.scrolloffset -= 1 - if ui_props.scrolloffset < 0: - ui_props.scrolloffset = 0 + ui_props.scroll_offset -= 1 + if ui_props.scroll_offset < 0: + ui_props.scroll_offset = 0 return {'RUNNING_MODAL'} if event.type == 'MOUSEMOVE': # Apply @@ -1351,8 +1351,8 @@ class AssetBarOperator(bpy.types.Operator): bpy.context.window.cursor_set("HAND") - if sr != None and ui_props.wcount * ui_props.hcount > len(sr) and ui_props.scrolloffset > 0: - ui_props.scrolloffset = 0 + if sr != None and ui_props.wcount * ui_props.hcount > len(sr) and ui_props.scroll_offset > 0: + ui_props.scroll_offset = 0 asset_search_index = get_asset_under_mouse(mx, my) ui_props.active_index = asset_search_index @@ -1368,11 +1368,11 @@ class AssetBarOperator(bpy.types.Operator): ui_props.draw_tooltip = False if mx > ui_props.bar_x + ui_props.bar_width - 50 and search_results_orig[ - 'count'] - ui_props.scrolloffset > ( + 'count'] - ui_props.scroll_offset > ( ui_props.wcount * ui_props.hcount) + 1: ui_props.active_index = -1 return {'RUNNING_MODAL'} - if mx < ui_props.bar_x + 50 and ui_props.scrolloffset > 0: + if mx < ui_props.bar_x + 50 and ui_props.scroll_offset > 0: ui_props.active_index = -2 return {'RUNNING_MODAL'} @@ -1413,21 +1413,21 @@ class AssetBarOperator(bpy.types.Operator): return {'PASS_THROUGH'} # this can happen by switching result asset types - length of search result changes - if ui_props.scrolloffset > 0 and (ui_props.wcount * ui_props.hcount) > len(sr) - ui_props.scrolloffset: - ui_props.scrolloffset = len(sr) - (ui_props.wcount * ui_props.hcount) + if ui_props.scroll_offset > 0 and (ui_props.wcount * ui_props.hcount) > len(sr) - ui_props.scroll_offset: + ui_props.scroll_offset = len(sr) - (ui_props.wcount * ui_props.hcount) if event.value == 'RELEASE': # Confirm # ui_props.drag_init = False # scroll with buttons by a whole page if mx > ui_props.bar_x + ui_props.bar_width - 50 and len( - sr) - ui_props.scrolloffset > ui_props.wcount * ui_props.hcount: - ui_props.scrolloffset = min( - ui_props.scrolloffset + (ui_props.wcount * ui_props.hcount), + sr) - ui_props.scroll_offset > ui_props.wcount * ui_props.hcount: + ui_props.scroll_offset = min( + ui_props.scroll_offset + (ui_props.wcount * ui_props.hcount), len(sr) - ui_props.wcount * ui_props.hcount) return {'RUNNING_MODAL'} - if mx < ui_props.bar_x + 50 and ui_props.scrolloffset > 0: - ui_props.scrolloffset = max(0, ui_props.scrolloffset - ui_props.wcount * ui_props.hcount) + if mx < ui_props.bar_x + 50 and ui_props.scroll_offset > 0: + ui_props.scroll_offset = max(0, ui_props.scroll_offset - ui_props.wcount * ui_props.hcount) return {'RUNNING_MODAL'} if ui_props.active_index == -3: diff --git a/blenderkit/utils.py b/blenderkit/utils.py index c11dc255..33f8140a 100644 --- a/blenderkit/utils.py +++ b/blenderkit/utils.py @@ -841,6 +841,7 @@ def user_is_owner(asset_data=None): def asset_from_newer_blender_version(asset_data): + '''checks if asset is from a newer blender version, to avoid incompatibility''' bver = bpy.app.version aver = asset_data['sourceAppVersion'].split('.') #print(aver,bver) @@ -848,6 +849,7 @@ def asset_from_newer_blender_version(asset_data): if len(aver)>=3: aver_f = int(aver[0]) + int(aver[1]) * .01 + int(aver[2]) * .0001 return aver_f>bver_f + return False def guard_from_crash(): ''' @@ -855,7 +857,7 @@ def guard_from_crash(): with the addon going through unregistration process. This function is used in these functions (like draw callbacks) so these don't run during unregistration. - ''' + ''' if bpy.context.preferences.addons.get('blenderkit') is None: return False; if bpy.context.preferences.addons['blenderkit'].preferences is None: |