[Bf-extensions-cvs] [054ee2f4] master: BlenderKit: fix rating interaction

Vilém Duha noreply at git.blender.org
Sun Jul 12 19:17:09 CEST 2020


Commit: 054ee2f41734049c9ba1386d9ec9eb3e85fc2e3f
Author: Vilém Duha
Date:   Sun Jul 12 18:07:45 2020 +0200
Branches: master
https://developer.blender.org/rBA054ee2f41734049c9ba1386d9ec9eb3e85fc2e3f

BlenderKit: fix rating interaction

-disabled layout didn't work(thanks to another blender layout bug that I reported)
-replaced it with an enum, and also a popup that informs the user instead.

===================================================================

M	blenderkit/__init__.py
M	blenderkit/bkit_oauth.py
M	blenderkit/ratings.py
M	blenderkit/rerequests.py
M	blenderkit/search.py
M	blenderkit/ui_panels.py
M	blenderkit/upload.py
M	blenderkit/utils.py

===================================================================

diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py
index 15dcaffb..a7e148ea 100644
--- a/blenderkit/__init__.py
+++ b/blenderkit/__init__.py
@@ -93,6 +93,7 @@ def scene_load(context):
     preferences = bpy.context.preferences.addons['blenderkit'].preferences
     preferences.login_attempt = False
 
+
 @bpy.app.handlers.persistent
 def check_timers_timer():
     ''' checks if all timers are registered regularly. Prevents possible bugs from stopping the addon.'''
@@ -249,17 +250,12 @@ def switch_search_results(self, context):
         s['search results orig'] = s.get('bkit brush search orig')
     search.load_previews()
 
-#define these static
-# asset_type_ui_items = (
-#             ('MODEL', 'Models', 'Find upload models in the BlenderKit online database', 'OBJECT_DATAMODE',0),
-#             # ('SCENE', 'SCENE', 'Browse scenes', 'SCENE_DATA', 1),
-#             ('MATERIAL', 'Materials', 'Find or upload models in the BlenderKit online database', 'MATERIAL',2),
-#             # ('TEXTURE', 'Texture', 'Browse textures', 'TEXTURE', 3),
-#             ('BRUSH', 'Brushes', 'Find or upload models in the BlenderKit online database', 'BRUSH_DATA',3)
-#         )
-
-#same as above, but dynamic.
 def asset_type_callback(self, context):
+    '''
+    Returns
+    items for Enum property, depending on the down_up property - BlenderKit is either in search or in upload mode.
+
+    '''
     if self.down_up == 'SEARCH':
         items = (
             ('MODEL', 'Models', 'Find models in the BlenderKit online database', 'OBJECT_DATAMODE', 0),
@@ -533,7 +529,7 @@ def update_free(self, context):
                   "Part of subscription is sent to artists based on usage by paying users."
 
         def draw_message(self, context):
-            ui_panels.label_multiline(self.layout, text=message, icon='NONE', width=-1)
+            utils.label_multiline(self.layout, text=message, icon='NONE', width=-1)
 
         bpy.context.window_manager.popup_menu(draw_message, title=title, icon='INFO')
 
@@ -654,6 +650,29 @@ class BlenderKitCommonUploadProps(object):
     )
 
 
+def stars_enum_callback(self, context):
+    items = []
+    for a in range(0, 10):
+        if self.rating_quality < a+1:
+            icon = 'SOLO_OFF'
+        else:
+            icon = 'SOLO_ON'
+        # has to have something before the number in the value, otherwise fails on registration.
+        items.append((f'{a+1}', f'{a+1}', '', icon, a+1))
+    return items
+
+
+def update_quality(self, context):
+    user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
+    if user_preferences.api_key == '':
+        # ui_panels.draw_not_logged_in(self, message='Please login/signup to rate assets.')
+        # bpy.ops.wm.call_menu(name='OBJECT_MT_blenderkit_login_menu')
+        # return
+        bpy.ops.wm.blenderkit_login('INVOKE_DEFAULT', message = 'Please login/signup to rate assets. Clicking OK takes you to web login.')
+        self.rating_quality_ui = '0'
+    self.rating_quality = int(self.rating_quality_ui)
+
+
 class BlenderKitRatingProps(PropertyGroup):
     rating_quality: IntProperty(name="Quality",
                                 description="quality of the material",
@@ -661,17 +680,25 @@ class BlenderKitRatingProps(PropertyGroup):
                                 min=-1, max=10,
                                 update=ratings.update_ratings_quality)
 
+    #the following enum is only to ease interaction - enums support 'drag over' and enable to draw the stars easily.
+    rating_quality_ui: EnumProperty(name='rating_quality_ui',
+                                     items=stars_enum_callback,
+                                     description='Rating stars 0 - 10',
+                                     default=None,
+                                     update=update_quality,
+                                     )
+
     rating_work_hours: FloatProperty(name="Work Hours",
                                      description="How many hours did this work take?",
                                      default=0.00,
                                      min=0.0, max=1000, update=ratings.update_ratings_work_hours
                                      )
-    rating_complexity: IntProperty(name="Complexity",
-                                   description="Complexity is a number estimating how much work was spent on the asset.aaa",
-                                   default=0, min=0, max=10)
-    rating_virtual_price: FloatProperty(name="Virtual Price",
-                                        description="How much would you pay for this object if buing it?",
-                                        default=0, min=0, max=10000)
+    # rating_complexity: IntProperty(name="Complexity",
+    #                                description="Complexity is a number estimating how much work was spent on the asset.aaa",
+    #                                default=0, min=0, max=10)
+    # rating_virtual_price: FloatProperty(name="Virtual Price",
+    #                                     description="How much would you pay for this object if buing it?",
+    #                                     default=0, min=0, max=10000)
     rating_problems: StringProperty(
         name="Problems",
         description="Problems found/ why did you take points down - this will be available for the author"
@@ -1400,14 +1427,15 @@ class BlenderKitSceneSearchProps(PropertyGroup, BlenderKitCommonSearchProps):
         update=search.search_update
     )
 
+
 def fix_subdir(self, context):
     '''Fixes project subdicrectory settings if people input invalid path.'''
 
     # pp = pathlib.PurePath(self.project_subdir)
     pp = self.project_subdir[:]
-    pp = pp.replace('\\','')
-    pp = pp.replace('/','')
-    pp = pp.replace(':','')
+    pp = pp.replace('\\', '')
+    pp = pp.replace('/', '')
+    pp = pp.replace(':', '')
     pp = '//' + pp
     if self.project_subdir != pp:
         self.project_subdir = pp
@@ -1418,10 +1446,11 @@ def fix_subdir(self, context):
                   "and uses it for storing assets."
 
         def draw_message(self, context):
-            ui_panels.label_multiline(self.layout, text=message, icon='NONE', width=400)
+            utils.label_multiline(self.layout, text=message, icon='NONE', width=400)
 
         bpy.context.window_manager.popup_menu(draw_message, title=title, icon='INFO')
 
+
 class BlenderKitAddonPreferences(AddonPreferences):
     # this must match the addon name, use '__package__'
     # when defining this in a submodule of a python package.
@@ -1501,7 +1530,7 @@ class BlenderKitAddonPreferences(AddonPreferences):
         description="where data will be stored for individual projects",
         # subtype='DIR_PATH',
         default="//assets",
-        update = fix_subdir
+        update=fix_subdir
     )
 
     directory_behaviour: EnumProperty(
@@ -1566,10 +1595,11 @@ class BlenderKitAddonPreferences(AddonPreferences):
 
     use_timers: BoolProperty(
         name="Use timers",
-        description="Use timers for bkit",
+        description="Use timers for BlenderKit. Usefull for debugging since timers seem to be unstable.",
         default=True,
         update=utils.save_prefs
     )
+
     # allow_proximity : BoolProperty(
     #     name="allow proximity data reports",
     #     description="This sends anonymized proximity data \n \
diff --git a/blenderkit/bkit_oauth.py b/blenderkit/bkit_oauth.py
index 0bf20d4a..ae90b215 100644
--- a/blenderkit/bkit_oauth.py
+++ b/blenderkit/bkit_oauth.py
@@ -26,8 +26,9 @@ if "bpy" in locals():
     categories = reload(categories)
     oauth = reload(oauth)
     ui = reload(ui)
+    ui = reload(ui_panels)
 else:
-    from blenderkit import tasks_queue, utils, paths, search, categories, oauth, ui
+    from blenderkit import tasks_queue, utils, paths, search, categories, oauth, ui, ui_panels
 
 import bpy
 
@@ -102,7 +103,7 @@ class RegisterLoginOnline(bpy.types.Operator):
     """Login online on BlenderKit webpage"""
 
     bl_idname = "wm.blenderkit_login"
-    bl_label = "BlenderKit login or signup"
+    bl_label = "BlenderKit login/signup"
     bl_options = {'REGISTER', 'UNDO'}
 
     signup: BoolProperty(
@@ -112,16 +113,32 @@ class RegisterLoginOnline(bpy.types.Operator):
         options={'SKIP_SAVE'}
     )
 
+    message: bpy.props.StringProperty(
+        name="Message",
+        description="",
+        default="You were logged out from BlenderKit. Clicking OK takes you to web login. ")
+
     @classmethod
     def poll(cls, context):
         return True
 
+    def draw(self, context):
+        layout = self.layout
+        utils.label_multiline(layout, text=self.message)
+
     def execute(self, context):
         preferences = bpy.context.preferences.addons['blenderkit'].preferences
         preferences.login_attempt = True
         login_thread(self.signup)
         return {'FINISHED'}
 
+    def invoke(self, context, event):
+        wm = bpy.context.window_manager
+        preferences = bpy.context.preferences.addons['blenderkit'].preferences
+        preferences.api_key_refresh = ''
+        preferences.api_key = ''
+        return wm.invoke_props_dialog(self)
+
 
 class Logout(bpy.types.Operator):
     """Logout from BlenderKit immediately"""
diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py
index dbe8b8eb..48c34a61 100644
--- a/blenderkit/ratings.py
+++ b/blenderkit/ratings.py
@@ -78,6 +78,7 @@ def send_rating_to_thread_quality(url, ratings, headers):
     thread = threading.Thread(target=upload_rating_thread, args=(url, ratings, headers))
     thread.start()
 
+
 def send_rating_to_thread_work_hours(url, ratings, headers):
     '''Sens rating into thread rating, main purpose is for tasks_queue.
     One function per property to avoid lost data due to stashing.'''
@@ -93,6 +94,7 @@ def upload_review_thread(url, reviews, headers):
 
 
 def get_rating(asset_id):
+    #this function isn't used anywhere,should probably get removed.
     user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
     api_key = user_preferences.api_key
     headers = utils.get_headers(api_key)
@@ -133,6 +135,7 @@ def update_ratings_work_hours(self, context):
         tasks

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list