[Bf-extensions-cvs] [9823579a] master: BlenderKit: refactor reporting to User. this is still not very compatible with blender's way of doing things, but we need more lines of reporting for parallel tasks reporting.

Vilem Duha noreply at git.blender.org
Thu Jun 6 14:31:02 CEST 2019


Commit: 9823579a2da0d65f8e545e7daefd18a38676e859
Author: Vilem Duha
Date:   Thu Jun 6 14:27:18 2019 +0200
Branches: master
https://developer.blender.org/rBA9823579a2da0d65f8e545e7daefd18a38676e859

BlenderKit: refactor reporting to User.
this is still not very compatible with blender's way of doing things, but we need more lines of reporting for parallel tasks reporting.

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

A	blenderkit/colors.py
M	blenderkit/download.py
M	blenderkit/search.py
M	blenderkit/ui.py
M	blenderkit/ui_panels.py

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

diff --git a/blenderkit/colors.py b/blenderkit/colors.py
new file mode 100644
index 00000000..42545941
--- /dev/null
+++ b/blenderkit/colors.py
@@ -0,0 +1,22 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# this module defines color palette for BlenderKit UI
+
+GREEN = (.9, 1, .9, .6)
+RED = (1, .5, .5, .8)
\ No newline at end of file
diff --git a/blenderkit/download.py b/blenderkit/download.py
index 7bdbc3c4..06342db6 100644
--- a/blenderkit/download.py
+++ b/blenderkit/download.py
@@ -22,8 +22,11 @@ if "bpy" in locals():
     paths = reload(paths)
     append_link = reload(append_link)
     utils = reload(utils)
+    ui = reload(ui)
+    colors = reload(colors)
+    tasks_queue = reload(tasks_queue)
 else:
-    from blenderkit import paths, append_link, utils
+    from blenderkit import paths, append_link, utils, ui, colors, tasks_queue
 
 import threading
 import time
@@ -596,7 +599,10 @@ def download(asset_data, **kwargs):
 
     if kwargs.get('retry_counter', 0) > 3:
         sprops = utils.get_search_props()
-        sprops.report = f"Maximum retries exceeded for {asset_data['name']}"
+        report = f"Maximum retries exceeded for {asset_data['name']}"
+        sprops.report = report
+        ui.add_report(report, 5, colors.RED)
+
         utils.p(sprops.report)
         return
 
@@ -729,6 +735,7 @@ def get_download_url(asset_data, scene_id, api_key, tcom=None):
         tcom.report = 'Connection Error'
         tcom.error = True
         return 'Connection Error'
+
     if r.status_code < 400:
         data = r.json()
         url = data['filePath']
@@ -737,9 +744,12 @@ def get_download_url(asset_data, scene_id, api_key, tcom=None):
         return True
 
     if r.status_code == 403:
-        tcom.report = 'Available only in higher plans.'
+        r = 'You need Standard plan to get this item.'
+        tcom.report = r
+        r1 = 'All materials and brushes are aviable for free. Only users registered to Standart plan can use all models.'
+        tasks_queue.add_task((ui.add_report, (r1, 5, colors.RED)))
         tcom.error = True
-        return 'Available only in higher plans.'
+
     if r.status_code == 401:
         tcom.report = 'Invalid API key'
         tcom.error = True
@@ -747,6 +757,7 @@ def get_download_url(asset_data, scene_id, api_key, tcom=None):
     elif r.status_code >= 500:
         tcom.report = 'Server error'
         tcom.error = True
+    return False
 
 
 def start_download(asset_data, **kwargs):
diff --git a/blenderkit/search.py b/blenderkit/search.py
index b4d3b7fe..c1adf9b0 100644
--- a/blenderkit/search.py
+++ b/blenderkit/search.py
@@ -245,7 +245,7 @@ def timer_update():  # TODO might get moved to handle all blenderkit stuff.
                 props.search_error = False
                 props.report = 'Open assetbar to see %i results. ' % len(s['search results'])
                 if len(s['search results']) == 0:
-                    props.report = 'No matching results found.'
+                    tasks_queue.add_task((ui.add_report, ('No matching results found.',)))
 
             # (rdata['next'])
             # if rdata['next'] != None:
@@ -1032,6 +1032,8 @@ def search(category='', get_next=False, author_id=''):
     #     query['keywords'] += '+is_free:true'
 
     add_search_process(query, params)
+    tasks_queue.add_task((ui.add_report, ('BlenderKit searching....',2)))
+
     props.report = 'BlenderKit searching....'
 
 
diff --git a/blenderkit/ui.py b/blenderkit/ui.py
index f35b0f73..727f0927 100644
--- a/blenderkit/ui.py
+++ b/blenderkit/ui.py
@@ -28,8 +28,9 @@ if "bpy" in locals():
     ui_bgl = importlib.reload(ui_bgl)
     download = importlib.reload(download)
     bg_blender = importlib.reload(bg_blender)
+    colors = importlib.reload(colors)
 else:
-    from blenderkit import paths, ratings, utils, search, upload, ui_bgl, download, bg_blender
+    from blenderkit import paths, ratings, utils, search, upload, ui_bgl, download, bg_blender, colors
 
 import bpy
 
@@ -48,6 +49,7 @@ import os
 
 handler_2d = None
 handler_3d = None
+reports = []
 
 mappingdict = {
     'MODEL': 'model',
@@ -95,6 +97,48 @@ def get_approximate_text_width(st):
     return size  # Convert to picas
 
 
+def add_report(text='', timeout=5, color=colors.GREEN):
+    global reports
+    updated = False
+
+    #check for same reports and just make them longer by the timeout.
+    for old_report in reports:
+        if old_report.text == text:
+            old_report.timeout = old_report.age + timeout
+            updated = True
+    if not updated:
+        report = Report(text=text, timeout=timeout, color=color)
+        reports.append(report)
+    print('added report')
+    print(report)
+
+
+class Report():
+    def __init__(self, text='', timeout=5, color=(.5, 1, .5, 1)):
+        self.text = text
+        self.timeout = timeout
+        self.start_time = time.time()
+        self.color = color
+        self.draw_color = color
+        self.age = 0
+
+    def fade(self):
+        fade_time = 1
+        self.age = time.time() - self.start_time
+        if self.age + fade_time > self.timeout:
+            alpha_multiplier = (self.timeout - self.age) / fade_time
+            self.draw_color = (self.color[0], self.color[1], self.color[2], self.color[3] * alpha_multiplier)
+            if self.age > self.timeout:
+                global reports
+                try:
+                    reports.remove(self)
+                except Exception as e:
+                    pass;
+
+    def draw(self, x, y):
+        ui_bgl.draw_text(self.text, x, y + 8, 16, self.draw_color)
+
+
 def get_asset_under_mouse(mousex, mousey):
     s = bpy.context.scene
     ui_props = bpy.context.scene.blenderkitUI
@@ -502,9 +546,9 @@ def draw_downloader(x, y, percent=0, img=None):
     ui_bgl.draw_rect(x - 3, y - 3, 6, 6, (1, 0, 0, .3))
 
 
-def draw_progress(x, y, text='', percent=None, color=(.2, 1, .2, .3)):
+def draw_progress(x, y, text='', percent=None, color=colors.GREEN):
     ui_bgl.draw_rect(x, y, percent, 5, color)
-    ui_bgl.draw_text(text, x, y + 8, 10, color)
+    ui_bgl.draw_text(text, x, y + 8, 16, color)
 
 
 def draw_callback_3d_progress(self, context):
@@ -556,6 +600,11 @@ def draw_callback_2d_progress(self, context):
         draw_progress(x, y - index * 30, '%s' % tcom.lasttext,
                       tcom.progress)
         index += 1
+    global reports
+    for report in reports:
+        report.draw(x, y - index * 30)
+        index += 1
+        report.fade()
 
 
 def draw_callback_2d_upload_preview(self, context):
@@ -685,19 +734,19 @@ def draw_callback_2d_search(self, context):
                         img = utils.get_thumbnail(v_icon)
                         ui_bgl.draw_image(x + ui_props.thumb_size - 26, y + 2, 24, 24, img, 1)
 
-            if user_preferences.api_key == '':
-                report = 'Register on BlenderKit website to upload your own assets.'
-                ui_bgl.draw_text(report, ui_props.bar_x + ui_props.margin,
-                                 ui_props.bar_y - 25 - ui_props.margin - ui_props.bar_height, 15)
-            elif len(search_results) == 0:
-                report = 'BlenderKit - No matching results found.'
-                ui_bgl.draw_text(report, ui_props.bar_x + ui_props.margin,
-                                 ui_props.bar_y - 25 - ui_props.margin, 15)
+            # if user_preferences.api_key == '':
+            #     report = 'Register on BlenderKit website to upload your own assets.'
+            #     ui_bgl.draw_text(report, ui_props.bar_x + ui_props.margin,
+            #                      ui_props.bar_y - 25 - ui_props.margin - ui_props.bar_height, 15)
+            # elif len(search_results) == 0:
+            #     report = 'BlenderKit - No matching results found.'
+            #     ui_bgl.draw_text(report, ui_props.bar_x + ui_props.margin,
+            #                      ui_props.bar_y - 25 - ui_props.margin, 15)
         s = bpy.context.scene
         props = utils.get_search_props()
-        if props.report != '' and props.is_searching or props.search_error:
-            ui_bgl.draw_text(props.report, ui_props.bar_x,
-                             ui_props.bar_y - 15 - ui_props.margin - ui_props.bar_height, 15)
+        # if props.report != '' and props.is_searching or props.search_error:
+        #     ui_bgl.draw_text(props.report, ui_props.bar_x,
+        #                      ui_props.bar_y - 15 - ui_props.margin - ui_props.bar_height, 15)
 
         props = s.blenderkitUI
         if props.draw_tooltip:
@@ -990,10 +1039,10 @@ def update_ui_size(area, region):
     ui.bar_height = (ui.thumb_size + ui.margin) * ui.hcount + ui.margin
     ui.bar_y = region.height - ui.bar_y_offset * ui_scale
     if ui.down_up == 'UPLOAD':
-        ui.reports_y = ui.bar_y + 800
+        ui.reports_y = ui.bar_y - 600
         ui.reports_x = ui.bar_x
     else:
-        ui.reports_y = ui.bar_y + ui.bar_height
+        ui.reports_y = ui.bar_y - ui.bar_height - 100
         ui.reports_x = ui.bar_x
 
     ui.rating_x = ui.bar_x
diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py
index 197f208f..37b84aeb 100644
--- a/blenderkit/ui_panels.py
+++ b/blenderkit/ui_panels.py
@@ -273,11 +273,11 @@ def draw_panel_model_search(self, context):
     layout.prop(props, "search_keywords", text="", icon='VIEWZOOM')
 
     icon = 'NONE'
-    if props.report == 'Available only in higher plans.':
+    if props.report == 'You need S

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list