Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVilem Duha <vilem.duha@gmail.com>2021-05-23 23:50:05 +0300
committerJeroen Bakker <jeroen@blender.org>2021-08-09 09:41:17 +0300
commit78a5ae9ba8796447b5fdc35f16375d3f5234d197 (patch)
tree1af14bd87f6aa30c80dde6e5dd3cfa7039cb059a
parent6a81558b63d579a58de4df39def083bb34defca7 (diff)
BlenderKit: improve ratings UIv2.93.4v2.93.3
OK button removed from popup rating fixed a bug in fetching user's ratings from server
-rw-r--r--blenderkit/ratings.py60
-rw-r--r--blenderkit/search.py16
-rw-r--r--blenderkit/ui.py7
3 files changed, 31 insertions, 52 deletions
diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py
index 10d815ba..f6a221c4 100644
--- a/blenderkit/ratings.py
+++ b/blenderkit/ratings.py
@@ -50,7 +50,6 @@ def pretty_print_POST(req):
))
-
def upload_review_thread(url, reviews, headers):
r = rerequests.put(url, data=reviews, verify=True, headers=headers)
@@ -58,9 +57,6 @@ def upload_review_thread(url, reviews, headers):
# print('reviews upload failed: %s' % str(e))
-
-
-
def upload_rating(asset):
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
api_key = user_preferences.api_key
@@ -76,10 +72,12 @@ def upload_rating(asset):
if bkit_ratings.rating_quality > 0.1:
ratings = (('quality', bkit_ratings.rating_quality),)
- tasks_queue.add_task((ratings_utils.send_rating_to_thread_quality, (url, ratings, headers)), wait=2.5, only_last=True)
+ tasks_queue.add_task((ratings_utils.send_rating_to_thread_quality, (url, ratings, headers)), wait=2.5,
+ only_last=True)
if bkit_ratings.rating_work_hours > 0.1:
ratings = (('working_hours', round(bkit_ratings.rating_work_hours, 1)),)
- tasks_queue.add_task((ratings_utils.send_rating_to_thread_work_hours, (url, ratings, headers)), wait=2.5, only_last=True)
+ tasks_queue.add_task((ratings_utils.send_rating_to_thread_work_hours, (url, ratings, headers)), wait=2.5,
+ only_last=True)
thread = threading.Thread(target=ratings_utils.upload_rating_thread, args=(url, ratings, headers))
thread.start()
@@ -168,22 +166,22 @@ def draw_ratings_menu(self, context, layout):
profile_name = ''
profile = bpy.context.window_manager.get('bkit profile')
- if profile and len(profile['user']['firstName'])>0:
+ if profile and len(profile['user']['firstName']) > 0:
profile_name = ' ' + profile['user']['firstName']
col = layout.column()
# layout.template_icon_view(bkit_ratings, property, show_labels=False, scale=6.0, scale_popup=5.0)
row = col.row()
- row.label(text='Quality:', icon = 'SOLO_ON')
+ row.label(text='Quality:', icon='SOLO_ON')
row = col.row()
row.label(text='Please help the community by rating quality:')
row = col.row()
row.prop(self, 'rating_quality_ui', expand=True, icon_only=True, emboss=False)
- if self.rating_quality>0:
+ if self.rating_quality > 0:
# row = col.row()
- row.label(text=f' Thanks{profile_name}!', icon = 'FUND')
+ row.label(text=f' Thanks{profile_name}!', icon='FUND')
# row.label(text=str(self.rating_quality))
col.separator()
col.separator()
@@ -220,17 +218,17 @@ def draw_ratings_menu(self, context, layout):
row = col.row()
row.prop(self, 'rating_work_hours_ui_1_5', expand=True, icon_only=False, emboss=True)
- if self.rating_work_hours>0:
+ if self.rating_work_hours > 0:
row = col.row()
row.label(text=f'Thanks{profile_name}, you are amazing!', icon='FUND')
+
class FastRateMenu(Operator, ratings_utils.RatingsProperties):
"""Rating of the assets , also directly from the asset bar - without need to download assets"""
bl_idname = "wm.blenderkit_menu_rating_upload"
- bl_label = ""
+ bl_label = "Ratings"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
-
@classmethod
def poll(cls, context):
scene = bpy.context.scene
@@ -239,39 +237,12 @@ class FastRateMenu(Operator, ratings_utils.RatingsProperties):
def draw(self, context):
layout = self.layout
- layout.label(text=self.message)
- layout.separator()
-
draw_ratings_menu(self, context, layout)
def execute(self, context):
- user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
- api_key = user_preferences.api_key
- headers = utils.get_headers(api_key)
-
- url = paths.get_api_url() + f'assets/{self.asset_id}/rating/'
-
- rtgs = [
-
- ]
-
- if self.rating_quality_ui == '':
- self.rating_quality = 0
- else:
- self.rating_quality = float(self.rating_quality_ui)
-
- if self.rating_quality > 0.1:
- rtgs = (('quality', self.rating_quality),)
- tasks_queue.add_task((ratings_utils.send_rating_to_thread_quality, (url, rtgs, headers)), wait=2.5, only_last=True)
-
- if self.rating_work_hours > 0.45:
- rtgs = (('working_hours', round(self.rating_work_hours, 1)),)
- tasks_queue.add_task((ratings_utils.send_rating_to_thread_work_hours, (url, rtgs, headers)), wait=2.5, only_last=True)
- return {'FINISHED'}
-
- def invoke(self, context, event):
scene = bpy.context.scene
ui_props = scene.blenderkitUI
+ #get asset id
if ui_props.active_index > -1:
sr = bpy.context.window_manager['search results']
asset_data = dict(sr[ui_props.active_index])
@@ -280,15 +251,16 @@ class FastRateMenu(Operator, ratings_utils.RatingsProperties):
if self.asset_id == '':
return {'CANCELLED'}
- self.message = f"{self.asset_name}"
+
wm = context.window_manager
+
self.prefill_ratings()
if self.asset_type in ('model', 'scene'):
# spawn a wider one for validators for the enum buttons
- return wm.invoke_props_dialog(self, width=500)
+ return wm.invoke_popup(self, width=500)
else:
- return wm.invoke_props_dialog(self)
+ return wm.invoke_popup(self)
def rating_menu_draw(self, context):
diff --git a/blenderkit/search.py b/blenderkit/search.py
index 0d3d73b0..76a105f1 100644
--- a/blenderkit/search.py
+++ b/blenderkit/search.py
@@ -436,18 +436,22 @@ def search_timer():
if not ui_props.assetbar_on:
bpy.ops.object.run_assetbar_fix_context()
- user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
- api_key = user_preferences.api_key
- headers = utils.get_headers(api_key)
+
for r in rdata['results']:
asset_data = parse_result(r)
if asset_data != None:
result_field.append(asset_data)
- if utils.profile_is_validator() and ratings_utils.get_rating_local(asset_data['id']) is None:
- thread = threading.Thread(target=ratings_utils.get_rating, args=([asset_data['id'], headers]), daemon=True)
- thread.start()
+ # Get ratings from BlenderKit server
+ if utils.profile_is_validator():
+ user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
+ api_key = user_preferences.api_key
+ headers = utils.get_headers(api_key)
+ for r in rdata['results']:
+ if ratings_utils.get_rating_local(asset_data['id']) is None:
+ thread = threading.Thread(target=ratings_utils.get_rating, args=([r['id'], headers]), daemon=True)
+ thread.start()
wm[search_name] = result_field
wm['search results'] = result_field
diff --git a/blenderkit/ui.py b/blenderkit/ui.py
index 73a11154..1fdc928b 100644
--- a/blenderkit/ui.py
+++ b/blenderkit/ui.py
@@ -395,8 +395,11 @@ def draw_tooltip_with_author(asset_data, x, y):
rcount = min(rc.get('quality',0), rc.get('workingHours',0))
if rcount > show_rating_threshold:
quality = round(asset_data['ratingsAverage'].get('quality'))
+ author_text = ''
+ if len(a['firstName'])>0 or len(a['lastName'])>0:
+ author_text = f"by {a['firstName']} {a['lastName']}"
- draw_tooltip(x, y, name=aname, author=f"by {a['firstName']} {a['lastName']}", quality=quality, img=img,
+ draw_tooltip(x, y, name=aname, author=author_text, quality=quality, img=img,
gravatar=gimg)
@@ -699,7 +702,7 @@ def draw_asset_bar(self, context):
v_icon = verification_icons[result.get('verificationStatus', 'validated')]
if v_icon is None and utils.profile_is_validator():
- # poke for validators to rate
+ # poke for validators to rate
if ratings_utils.get_rating_local(result['id']) in (None, {}):
v_icon = 'star_grey.png'