BlenderKi: fix thumbnail generators

improve reports
delete forgotten prints
fix updates in asset bar
This commit is contained in:
Vilem Duha 2021-11-11 10:54:44 +01:00
parent 90668547ad
commit db77258088
8 changed files with 50 additions and 43 deletions

View File

@ -444,6 +444,7 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator):
def update_layout(self, context, event):
# restarting asset_bar completely since the widgets are too hard to get working with updates.
self.scroll_update()
self.position_and_hide_buttons()
@ -468,7 +469,7 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator):
self.tooltip_height - self.author_text_size - self.margin)
# to hide arrows accordingly
self.scroll_update()
def asset_button_init(self, asset_x, asset_y, button_idx):
ui_scale = bpy.context.preferences.view.ui_scale
@ -796,7 +797,11 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator):
self.tooltip_image.set_image(img.filepath)
get_tooltip_data(asset_data)
self.asset_name.text = asset_data['name']
an = asset_data['name']
max_name_length = 30
if len(an)>max_name_length+3:
an = an[:30]+'...'
self.asset_name.text = an
self.authors_name.text = asset_data['tooltip_data']['author_text']
self.quality_label.text = asset_data['tooltip_data']['quality']
# print(asset_data['tooltip_data']['quality'])
@ -891,36 +896,37 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator):
if not sr:
return
for asset_button in self.asset_buttons:
asset_button.asset_index = asset_button.button_index + self.scroll_offset
# print(asset_button.asset_index, len(sr))
if asset_button.asset_index < len(sr):
asset_button.visible = True
if asset_button.visible:
asset_button.asset_index = asset_button.button_index + self.scroll_offset
# print(asset_button.asset_index, len(sr))
if asset_button.asset_index < len(sr):
asset_button.visible = True
asset_data = sr[asset_button.asset_index]
asset_data = sr[asset_button.asset_index]
iname = blenderkit.utils.previmg_name(asset_button.asset_index)
# show indices for debug purposes
# asset_button.text = str(asset_button.asset_index)
img = bpy.data.images.get(iname)
if img is None or len(img.pixels) == 0:
img_filepath = paths.get_addon_thumbnail_path('thumbnail_notready.jpg')
else:
img_filepath = img.filepath
# print(asset_button.button_index, img_filepath)
asset_button.set_image(img_filepath)
self.update_validation_icon(asset_button, asset_data)
if utils.profile_is_validator() and asset_data['verificationStatus'] == 'uploaded':
over_limit = utils.is_upload_old(asset_data)
if over_limit:
redness = min(over_limit * .05, 0.7)
asset_button.red_alert.bg_color = (1, 0, 0, redness)
asset_button.red_alert.visible = True
iname = blenderkit.utils.previmg_name(asset_button.asset_index)
# show indices for debug purposes
# asset_button.text = str(asset_button.asset_index)
img = bpy.data.images.get(iname)
if img is None or len(img.pixels) == 0:
img_filepath = paths.get_addon_thumbnail_path('thumbnail_notready.jpg')
else:
img_filepath = img.filepath
# print(asset_button.button_index, img_filepath)
asset_button.set_image(img_filepath)
self.update_validation_icon(asset_button, asset_data)
if utils.profile_is_validator() and asset_data['verificationStatus'] == 'uploaded':
over_limit = utils.is_upload_old(asset_data)
if over_limit:
redness = min(over_limit * .05, 0.7)
asset_button.red_alert.bg_color = (1, 0, 0, redness)
asset_button.red_alert.visible = True
else:
asset_button.red_alert.visible = False
elif utils.profile_is_validator():
asset_button.red_alert.visible = False
elif utils.profile_is_validator():
asset_button.red_alert.visible = False
else:
asset_button.visible = False
asset_button.validation_icon.visible = False
@ -939,6 +945,7 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator):
self.scroll_offset = min(self.scroll_offset, len(sr) - (self.wcount * self.hcount))
self.scroll_offset = max(self.scroll_offset, 0)
self.update_images()
# print(sro)
if sro['count'] > len(sr) and len(sr) - self.scroll_offset < (self.wcount * self.hcount) + 15:
self.search_more()
@ -961,7 +968,7 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator):
sprops = utils.get_search_props()
sprops.search_keywords = ''
sprops.search_verification_status = 'ALL'
utils.p('author:', a)
# utils.p('author:', a)
search.search(author_id=a)
return True

View File

@ -481,13 +481,16 @@ class GenerateMaterialThumbnailOperator(bpy.types.Operator):
bpy.ops.wm.save_as_mainfile(filepath=filepath, compress=False, copy=True)
thumb_dir = os.path.dirname(bpy.data.filepath)
thumb_path = os.path.join(thumb_dir, asset.name)
rel_thumb_path = os.path.join('//', asset.name)
an_slug = paths.slugify(asset.name)
thumb_path = os.path.join(thumb_dir, an_slug)
rel_thumb_path = os.path.join('//', an_slug)
# auto increase number of the generated thumbnail.
i = 0
while os.path.isfile(thumb_path + '.png'):
thumb_path = os.path.join(thumb_dir, asset.name + '_' + str(i).zfill(4))
rel_thumb_path = os.path.join('//', asset.name + '_' + str(i).zfill(4))
thumb_path = os.path.join(thumb_dir, an_slug + '_' + str(i).zfill(4))
rel_thumb_path = os.path.join('//', an_slug + '_' + str(i).zfill(4))
i += 1
asset.blenderkit.thumbnail = rel_thumb_path + '.png'
@ -606,10 +609,11 @@ class ReGenerateMaterialThumbnailOperator(bpy.types.Operator):
# either get the data from search results
sr = bpy.context.window_manager['search results']
asset_data = sr[self.asset_index].to_dict()
an_slug = paths.slugify(asset_data['name'])
tempdir = tempfile.mkdtemp()
thumb_path = os.path.join(tempdir, asset_data['name'])
thumb_path = os.path.join(tempdir,an_slug)
args_dict = {
"type": "material",

View File

@ -187,7 +187,7 @@ def slugify(slug):
import unicodedata, re
slug = slug.lower()
characters = '<>:"/\\|?*., ()#'
characters = '<>:"/\\|?\*., ()#'
for ch in characters:
slug = slug.replace(ch, '_')
# import re

View File

@ -101,7 +101,7 @@ def get_rating(asset_id, headers):
if r.status_code == 200:
rj = r.json()
ratings = {}
print(rj)
# print(rj)
# store ratings - send them to task queue
for r in rj['results']:
ratings[r['ratingType']] = r['score']
@ -354,8 +354,6 @@ class RatingsProperties():
def prefill_ratings(self):
# pre-fill ratings
ratings = get_rating_local(self.asset_id)
print('prefill ratings')
print(ratings)
if ratings and ratings.get('quality'):
self.rating_quality = ratings['quality']
if ratings and ratings.get('working_hours'):

View File

@ -497,9 +497,11 @@ def search_timer():
# jump back
ui_props.scroll_offset = 0
props.search_error = False
props.report = 'Found %i results. ' % (wm['search results orig']['count'])
props.report = f"Found {wm['search results orig']['count']} results."
if len(wm['search results']) == 0:
tasks_queue.add_task((reports.add_report, ('No matching results found.',)))
else:
tasks_queue.add_task((reports.add_report, (f"Found {wm['search results orig']['count']} results.",)))
# undo push
# bpy.ops.wm.undo_push_context(message='Get BlenderKit search')
# show asset bar automatically, but only on first page - others are loaded also when asset bar is hidden.

View File

@ -2250,8 +2250,6 @@ class AssetPopupCard(bpy.types.Operator, ratings_utils.RatingsProperties):
def prefill_ratings(self):
# pre-fill ratings
ratings = ratings_utils.get_rating_local(self.asset_id)
print('prefill ratings')
print(ratings)
if ratings and ratings.get('quality'):
self.rating_quality = ratings['quality']
if ratings and ratings.get('working_hours'):

View File

@ -582,7 +582,6 @@ def can_edit_asset(active_index=-1, asset_data=None):
if not asset_data:
sr = bpy.context.window_manager['search results']
asset_data = dict(sr[active_index])
# print(profile, asset_data)
if int(asset_data['author']['id']) == int(profile['user']['id']):
return True
return False

View File

@ -844,7 +844,6 @@ 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)
bver_f = bver[0] + bver[1] * .01 + bver[2] * .0001
if len(aver)>=3:
aver_f = int(aver[0]) + int(aver[1]) * .01 + int(aver[2]) * .0001