BlenderKit: UI fixes

Right clicking assetbar in a space where is no asset displayed did throw an error
several minor tooltip/layout fixes.
This commit is contained in:
Vilem Duha 2021-05-19 11:51:45 +02:00
parent df01c14fdd
commit 7867fe8bb3
4 changed files with 37 additions and 36 deletions

View File

@ -319,7 +319,7 @@ class BlenderKitUIProps(PropertyGroup):
update=udate_down_up
)
asset_type: EnumProperty(
name="BlenderKit Active Asset Type",
name=" ",
items=asset_type_callback,
description="",
default=None,
@ -445,7 +445,7 @@ class BlenderKitCommonSearchProps(object):
default=False)
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",
own_only: BoolProperty(name="My Assets Only", description="Search only for your assets",
default=False, update=search.search_update)
search_advanced: BoolProperty(name="Advanced Search Options", description="use advanced search properties",
default=False, update=search.search_update)

View File

@ -180,7 +180,7 @@ def draw_ratings_menu(self, context, layout):
profile_name = ''
profile = bpy.context.window_manager.get('bkit profile')
if profile:
if profile and len(profile['user']['firstName'])>0:
profile_name = ' ' + profile['user']['firstName']
col = layout.column()

View File

@ -1419,7 +1419,7 @@ class AssetBarOperator(bpy.types.Operator):
mx = event.mouse_x - r.x
my = event.mouse_y - r.y
if event.value == 'PRESS' and mouse_in_asset_bar(mx, my):
if event.value == 'PRESS' and mouse_in_asset_bar(mx, my) and ui_props.active_index>-1:
# context.window.cursor_warp(event.mouse_x - 300, event.mouse_y - 10);
bpy.ops.wm.blenderkit_asset_popup('INVOKE_DEFAULT')

View File

@ -1362,6 +1362,11 @@ def numeric_to_str(s):
return s
def push_op_left(layout):
for a in range(0, 5):
layout.label(text='')
def label_or_url(layout, text='', tooltip='', url='', icon_value=None, icon=None):
'''automatically switch between different layout options for linking or tooltips'''
layout.emboss = 'NONE'
@ -1374,8 +1379,7 @@ def label_or_url(layout, text='', tooltip='', url='', icon_value=None, icon=None
op = layout.operator('wm.blenderkit_url', text=text)
op.url = url
op.tooltip = tooltip
layout.label(text='')
layout.label(text='')
push_op_left(layout)
return
if tooltip != '':
@ -1387,8 +1391,7 @@ def label_or_url(layout, text='', tooltip='', url='', icon_value=None, icon=None
op = layout.operator('wm.blenderkit_tooltip', text=text)
op.tooltip = tooltip
# these are here to move the text to left, since operators can only center text by default
layout.label(text='')
layout.label(text='')
push_op_left(layout)
return
if icon:
layout.label(text=text, icon=icon)
@ -1416,14 +1419,14 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
def draw_property(self, layout, left, right, icon=None, icon_value=None, url='', tooltip=''):
right = str(right)
row = layout.row()
split = row.split(factor=0.4)
split = row.split(factor=0.35)
split.alignment = 'RIGHT'
split.label(text=left)
split = split.split()
split.alignment = 'LEFT'
# split for questionmark:
if url != '':
split = split.split(factor=0.7)
split = split.split(factor=0.6)
label_or_url(split, text=right, tooltip=tooltip, url=url, icon_value=icon_value, icon=icon)
# additional questionmark icon where it's important?
if url != '':
@ -1442,12 +1445,14 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
parameter = f"{parameter:,.1f}"
self.draw_property(layout, pretext, parameter)
def draw_description(self, layout, width = 250):
def draw_description(self, layout, width=250):
if len(self.asset_data['description']) > 0:
box = layout.box()
box.scale_y = 0.8
box.scale_y = 0.4
box.label(text='Description')
box.separator()
utils.label_multiline(box, self.asset_data['description'], width=width)
box.separator()
def draw_properties(self, layout, width=250):
@ -1460,8 +1465,9 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
box = layout.box()
box.scale_y = 0.8
box.scale_y = 0.4
box.label(text='Properties')
box.separator()
if self.asset_data.get('license') == 'cc_zero':
t = 'CC Zero '
icon = pcoll['cc0']
@ -1471,7 +1477,7 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
icon = pcoll['royalty_free']
self.draw_property(box,
'License:', t,
'License', t,
# icon_value=icon.icon_id,
url="https://www.blenderkit.com/docs/licenses/",
tooltip='All BlenderKit assets are available for commercial use. \n' \
@ -1502,7 +1508,7 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
}
self.draw_property(box,
'Verification:',
'Verification',
self.asset_data['verificationStatus'],
icon_value=icon.icon_id,
url="https://www.blenderkit.com/docs/validation-status/",
@ -1528,7 +1534,7 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
if f['fileType'].find('resolution') > -1:
resolutions += f['fileType'][11:] + ' '
resolutions = resolutions.replace('_', '.')
self.draw_property(box, 'Generated:', resolutions)
self.draw_property(box, 'Generated', resolutions)
self.draw_asset_parameter(box, key='designer', pretext='Designer')
self.draw_asset_parameter(box, key='manufacturer', pretext='Manufacturer') # TODO make them clickable!
@ -1548,15 +1554,15 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
t = '%s×%s×%s m' % (utils.fmt_length(mparams['dimensionX']),
utils.fmt_length(mparams['dimensionY']),
utils.fmt_length(mparams['dimensionZ']))
self.draw_property(box, 'Size:', t)
self.draw_property(box, 'Size', t)
if self.asset_data.get('filesSize'):
fs = self.asset_data['filesSize']
fsmb = fs // (1024 * 1024)
fskb = fs % 1024
if fsmb == 0:
self.draw_property(box, 'Original size:', f'{fskb}KB')
self.draw_property(box, 'Original size', f'{fskb} KB')
else:
self.draw_property(box, 'Original size:', f'{fsmb}MB')
self.draw_property(box, 'Original size', f'{fsmb} MB')
# Tags section
# row = box.row()
# letters_on_row = 0
@ -1595,25 +1601,26 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
plans_link = 'https://www.blenderkit.com/plans/pricing/'
if self.asset_data['isPrivate']:
t = 'Private'
self.draw_property(box, 'Access:', t, icon='LOCKED')
self.draw_property(box, 'Access', t, icon='LOCKED')
elif self.asset_data['isFree']:
t = 'Free plan'
icon = pcoll['free']
self.draw_property(box, 'Access:', t,
self.draw_property(box, 'Access', t,
icon_value=icon.icon_id,
tooltip=plans_tooltip,
url=plans_link)
else:
t = 'Full plan'
icon = pcoll['full']
self.draw_property(box, 'Access:', t,
self.draw_property(box, 'Access', t,
icon_value=icon.icon_id,
tooltip=plans_tooltip,
url=plans_link)
if utils.profile_is_validator():
date = self.asset_data['created'][:10]
date = f"{date[8:10]}. {date[5:7]}. {date[:4]}"
self.draw_property(box, 'Created:', date)
self.draw_property(box, 'Created', date)
box.separator()
def draw_author_area(self, context, layout, width=330):
self.draw_author(context, layout, width=width)
@ -1631,7 +1638,7 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
author_box.label(text='Author') # just one extra line to give spacing
if hasattr(self, 'gimg'):
author_left = author_box.split(factor=0.25)
author_left = author_box.split(factor=image_split)
author_left.template_icon(icon_value=self.gimg.preview.icon_id, scale=7)
text_area = author_left.split()
text_width = int(text_width * (1 - image_split))
@ -1673,13 +1680,13 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
op.keywords = ''
op.author_id = self.asset_data['author']['id']
def draw_thumbnail_box(self, layout, width = 250):
def draw_thumbnail_box(self, layout, width=250):
layout.emboss = 'NORMAL'
box_thumbnail = layout.box()
box_thumbnail.scale_y = .4
box_thumbnail.template_icon(icon_value=self.img.preview.icon_id, scale=width*.12)
box_thumbnail.template_icon(icon_value=self.img.preview.icon_id, scale=width * .12)
# row = box_thumbnail.row()
# row.scale_y = 3
@ -1727,7 +1734,7 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
if rcount <= show_rating_prompt_threshold:
box_thumbnail.alert = True
box_thumbnail.label(text=f"")
box_thumbnail.label(text=f"This asset has only {rcount} rating{'' if rcount == 1 else 's'} , please rate.")
box_thumbnail.label(text=f"This asset has only {rcount} rating{'' if rcount == 1 else 's'}, please rate.")
# box_thumbnail.label(text=f"Please rate this asset.")
def draw_menu_desc_author(self, context, layout, width=330):
@ -1752,7 +1759,6 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
# author
self.draw_author_area(context, box, width=width)
# self.draw_author_area(context, box, width=width)
#
# col = box.column_flow(columns=2)
@ -1762,11 +1768,6 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
# # self.draw_description(box, width=int(width))
# self.draw_properties(box, width=int(width))
def draw(self, context):
ui_props = context.scene.blenderkitUI
@ -1787,14 +1788,14 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
split_ratio = 0.45
split_left = row.split(factor=split_ratio)
left_column = split_left.column()
self.draw_thumbnail_box(left_column, width = int(self.width * split_ratio))
self.draw_thumbnail_box(left_column, width=int(self.width * split_ratio))
# self.draw_description(left_column, width = int(self.width*split_ratio))
# right split
split_right = split_left.split()
self.draw_menu_desc_author(context, split_right, width=int(self.width * (1-split_ratio)))
self.draw_menu_desc_author(context, split_right, width=int(self.width * (1 - split_ratio)))
if not utils.user_is_owner(asset_data=asset_data):
#Draw ratings, but not for owners of assets - doesn't make sense.
# Draw ratings, but not for owners of assets - doesn't make sense.
ratings_box = layout.box()
ratings.draw_ratings_menu(self, context, ratings_box)
# else: